Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robot walking backwards in headless mode #21

Closed
Dzhange opened this issue May 19, 2021 · 8 comments
Closed

Robot walking backwards in headless mode #21

Dzhange opened this issue May 19, 2021 · 8 comments

Comments

@Dzhange
Copy link

Dzhange commented May 19, 2021

Hi

After I fixed the headless rendering issue I had another problem.

While running the policy_player in headless mode, I turned render option to False when initializing the environment, and used a gym.wrappers.monitoring.video_recorder to record the scene.
Here you can see the robot is walking smoothly backwards(walking environment, in mounts terrain).

2021-05-19.10.56.13.996819.mp4

Another case(gallop, plane), but this time is turning around

2021-05-19.11.09.19.051276.mp4

I tried enabling the sleep control in

if self._is_render:
# Sleep, otherwise the computation takes less time than real time,
# which will make the visualization like a fast-forward video.
time_spent = time.time() - self._last_frame_time
self._last_frame_time = time.time()
time_to_sleep = self.control_time_step - time_spent
if time_to_sleep > 0:
time.sleep(time_to_sleep)
base_pos = self.rex.GetBasePosition()
# Keep the previous orientation of the camera set by the user.
[yaw, pitch, dist] = self._pybullet_client.getDebugVisualizerCamera()[8:11]
self._pybullet_client.resetDebugVisualizerCamera(dist, yaw, pitch, base_pos)

but the problem still exists. Any ideas?

Thanks!

@nicrusso7
Copy link
Owner

this looks like a timing issue, and I see you had my same impression (as you tried to edit the simulation timestep timing. However that block won't be executed if render = False, did you tried removing that if statement as well?

@Dzhange
Copy link
Author

Dzhange commented May 19, 2021

Yeah I tried to remove that if statement, actually the videos are recorded with this block executed.

I'm wondering if this problem is related to the parameters updated here?

if self._is_render and self._is_debug:
position, orientation, step_length, step_rotation, step_angle, step_period = \
self._read_inputs(base_pos_coeff, gait_stage_coeff)
else:
position = np.array([base_x,
self._base_y * base_pos_coeff,
self._base_z * base_pos_coeff])
orientation = np.array([self._base_roll * base_pos_coeff,
self._base_pitch * base_pos_coeff,
self._base_yaw * base_pos_coeff])
step_length = (self.step_length if self.step_length is not None else step) * gait_stage_coeff
step_rotation = (self.step_rotation if self.step_rotation is not None else 0.0)
step_angle = self.step_angle if self.step_angle is not None else 0.0
step_period = (self.step_period if self.step_period is not None else period)

@nicrusso7
Copy link
Owner

nicrusso7 commented May 19, 2021

I may be wrong but, nope, don't think so.. in both cases, the values we set are actually the same

def setup_ui(self, base_x, step, period):

self._ranges = {

@nicrusso7
Copy link
Owner

Do you have the same behavior running the policy_player in render mode? just wondering if the pybullet update made some changes

@Dzhange
Copy link
Author

Dzhange commented May 19, 2021

HIii, just checked several things:

  1. I found that walking backwards or forwards is randomly chosen, so I think the main problem is the gait/frequency etc
  2. sometimes the step_length parameter varies a bit(i.e. from -0.1 to -0.3), not sure if this is normal?
  3. I tried the newest pybullet with a monitor, and the robot walked well. I also tested the session with 3 settings:
  1. render and record video at same time --> moving slowly
out.mp4
  1. render only --> normal
out1.mp4

3)record video only --> rapid frequency, yet slow

cap_only.mp4

I guess the problem is mainly about timing, let me take a deeper look at that.
Here is my implementation of recording if you are interested:
https://github.com/Dzhange/rex-gym/blob/779470994e74259f5b29db62beb4f4aa05f8ddeb/rex_gym/playground/policy_player.py#L45-L84

@Dzhange
Copy link
Author

Dzhange commented May 20, 2021

I think I found the problem:

In render mode, fps is around 50
but when using capture_frame to visualize, the fps drops to ~3

I'm wondering if there is any method to fix the time for each step in the pybullet world?
or do you have any suggestions?
Thanks!

@nicrusso7
Copy link
Owner

Each env has its own metadata:

metadata = {"render.modes": ["human", "rgb_array"], "video.frames_per_second": 66}

Have you tried editing video.frames_per_second?

@Dzhange
Copy link
Author

Dzhange commented May 26, 2021

Hi,

thanks for your advice, this did make the video more nature!
After some struglling I raised the fps to ~20 by adding this block

https://github.com/Dzhange/rex-gym/blob/3ffb674ade13ceac3352c3329f1804eb21a08403/rex_gym/envs/rex_gym_env.py#L234-L242

not sure if this would support batchified training but I think that has little to do with this issue, I'll close itHi,

thanks for your advice, this did make the video more nature!
After some struglling I raised the fps to ~20 by adding this block

            self._pybullet_client = bullet_client.BulletClient(connection_mode=pybullet.DIRECT)
            import pkgutil
            egl = pkgutil.get_loader('eglRenderer')
            if egl:
                pluginId = pybullet.loadPlugin(egl.get_filename(), "_eglRendererPlugin")
            else:
                pluginId = pybullet.loadPlugin("eglRendererPlugin")
            print("pluginId=",pluginId)

not sure if this fps would support batchified training, but I think that has little to do with this issue, I'll close it

@Dzhange Dzhange closed this as completed May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants