nicrusso7 / rex-gym

OpenAI Gym environments for an open-source quadruped robot (SpotMicro)
Apache License 2.0
973 stars 130 forks source link

Robot walking backwards in headless mode #21

Closed Dzhange closed 3 years ago

Dzhange commented 3 years ago

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).

https://user-images.githubusercontent.com/35654021/118835855-f1504500-b8f5-11eb-9c61-a6f37d0bc16f.mp4

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

https://user-images.githubusercontent.com/35654021/118837850-c6ff8700-b8f7-11eb-87f3-0b868ec910f4.mp4

I tried enabling the sleep control in https://github.com/nicrusso7/rex-gym/blob/26663048bd3c3da307714da4458b1a2a9dc81824/rex_gym/envs/rex_gym_env.py#L387-L398

but the problem still exists. Any ideas?

Thanks!

nicrusso7 commented 3 years ago

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 commented 3 years ago

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? https://github.com/nicrusso7/rex-gym/blob/26663048bd3c3da307714da4458b1a2a9dc81824/rex_gym/envs/gym/walk_env.py#L262-L275

nicrusso7 commented 3 years ago

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

https://github.com/nicrusso7/rex-gym/blob/26663048bd3c3da307714da4458b1a2a9dc81824/rex_gym/envs/gym/walk_env.py#L156

https://github.com/nicrusso7/rex-gym/blob/26663048bd3c3da307714da4458b1a2a9dc81824/rex_gym/envs/rex_gym_env.py#L260

nicrusso7 commented 3 years ago

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

Dzhange commented 3 years ago

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

https://user-images.githubusercontent.com/35654021/118866533-adb90380-b914-11eb-8a7b-ce9f06b10af9.mp4

2) render only --> normal

https://user-images.githubusercontent.com/35654021/118866837-fd97ca80-b914-11eb-8a84-58e07b3c2e2d.mp4

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

https://user-images.githubusercontent.com/35654021/118866463-9843d980-b914-11eb-9519-61e344044e1a.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 commented 3 years ago

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 commented 3 years ago

Each env has its own metadata:

https://github.com/nicrusso7/rex-gym/blob/26663048bd3c3da307714da4458b1a2a9dc81824/rex_gym/envs/gym/walk_env.py#L27

Have you tried editing video.frames_per_second?

Dzhange commented 3 years ago

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