From ed504dc02c4553a9dd04f079287db3bca760324f Mon Sep 17 00:00:00 2001 From: Benelot Date: Mon, 11 Sep 2017 19:17:27 +0200 Subject: [PATCH 1/3] Remove all the tweaks added by me but not part of roboschool. --- .../pybullet/gym/pybullet_envs/env_bases.py | 2 +- .../gym/pybullet_envs/robot_locomotors.py | 36 ++++++++++--------- .../gym/pybullet_envs/robot_pendula.py | 11 +++--- .../gym/pybullet_envs/scene_abstract.py | 6 ---- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/examples/pybullet/gym/pybullet_envs/env_bases.py b/examples/pybullet/gym/pybullet_envs/env_bases.py index 8b16cd7be..ec12d8c65 100644 --- a/examples/pybullet/gym/pybullet_envs/env_bases.py +++ b/examples/pybullet/gym/pybullet_envs/env_bases.py @@ -44,7 +44,7 @@ class MJCFBaseBulletEnv(gym.Env): else: self.physicsClientId = p.connect(p.DIRECT) p.configureDebugVisualizer(p.COV_ENABLE_GUI,0) - + if self.scene is None: self.scene = self.create_single_player_scene() if not self.scene.multiplayer: diff --git a/examples/pybullet/gym/pybullet_envs/robot_locomotors.py b/examples/pybullet/gym/pybullet_envs/robot_locomotors.py index a17055675..98ba67780 100644 --- a/examples/pybullet/gym/pybullet_envs/robot_locomotors.py +++ b/examples/pybullet/gym/pybullet_envs/robot_locomotors.py @@ -152,23 +152,25 @@ class Humanoid(WalkerBase): self.motor_names += ["left_shoulder1", "left_shoulder2", "left_elbow"] self.motor_power += [75, 75, 75] self.motors = [self.jdict[n] for n in self.motor_names] - # if self.random_yaw: # TODO: Make leaning work as soon as the rest works - # cpose = cpp_household.Pose() - # yaw = self.np_random.uniform(low=-3.14, high=3.14) - # if self.random_lean and self.np_random.randint(2)==0: - # cpose.set_xyz(0, 0, 1.4) - # if self.np_random.randint(2)==0: - # pitch = np.pi/2 - # cpose.set_xyz(0, 0, 0.45) - # else: - # pitch = np.pi*3/2 - # cpose.set_xyz(0, 0, 0.25) - # roll = 0 - # cpose.set_rpy(roll, pitch, yaw) - # else: - # cpose.set_xyz(0, 0, 1.4) - # cpose.set_rpy(0, 0, yaw) # just face random direction, but stay straight otherwise - # self.cpp_robot.set_pose_and_speed(cpose, 0,0,0) + if self.random_yaw: + position = [0,0,0] + orientation = [0,0,0] + yaw = self.np_random.uniform(low=-3.14, high=3.14) + if self.random_lean and self.np_random.randint(2)==0: + cpose.set_xyz(0, 0, 1.4) + if self.np_random.randint(2)==0: + pitch = np.pi/2 + position = [0, 0, 0.45] + else: + pitch = np.pi*3/2 + position = [0, 0, 0.25] + roll = 0 + orientation = [roll, pitch, yaw] + else: + position = [0, 0, 1.4] + orientation = [0, 0, yaw] # just face random direction, but stay straight otherwise + self.robot_body.reset_position(position) + self.robot_body.reset_orientation(orientation) self.initial_z = 0.8 random_yaw = False diff --git a/examples/pybullet/gym/pybullet_envs/robot_pendula.py b/examples/pybullet/gym/pybullet_envs/robot_pendula.py index 1c6b14b05..0c82fea43 100644 --- a/examples/pybullet/gym/pybullet_envs/robot_pendula.py +++ b/examples/pybullet/gym/pybullet_envs/robot_pendula.py @@ -3,7 +3,6 @@ import numpy as np class InvertedPendulum(MJCFBasedRobot): swingup = False - force_gain = 12 # TODO: Try to find out why we need to scale the force def __init__(self): MJCFBasedRobot.__init__(self, 'inverted_pendulum.xml', 'cart', action_dim=1, obs_dim=5) @@ -16,16 +15,16 @@ class InvertedPendulum(MJCFBasedRobot): self.j1.set_motor_torque(0) def apply_action(self, a): - #assert( np.isfinite(a).all() ) + assert( np.isfinite(a).all() ) if not np.isfinite(a).all(): print("a is inf") a[0] = 0 - self.slider.set_motor_torque( self.force_gain * 100*float(np.clip(a[0], -1, +1)) ) + self.slider.set_motor_torque( 100*float(np.clip(a[0], -1, +1)) ) def calc_state(self): self.theta, theta_dot = self.j1.current_position() x, vx = self.slider.current_position() - #assert( np.isfinite(x) ) + assert( np.isfinite(x) ) if not np.isfinite(x): print("x is inf") @@ -50,7 +49,6 @@ class InvertedPendulum(MJCFBasedRobot): class InvertedPendulumSwingup(InvertedPendulum): swingup = True - force_gain = 2.2 # TODO: Try to find out why we need to scale the force class InvertedDoublePendulum(MJCFBasedRobot): @@ -70,8 +68,7 @@ class InvertedDoublePendulum(MJCFBasedRobot): def apply_action(self, a): assert( np.isfinite(a).all() ) - force_gain = 0.78 # TODO: Try to find out why we need to scale the force - self.slider.set_motor_torque( force_gain *200*float(np.clip(a[0], -1, +1)) ) + self.slider.set_motor_torque( 200*float(np.clip(a[0], -1, +1)) ) def calc_state(self): theta, theta_dot = self.j1.current_position() diff --git a/examples/pybullet/gym/pybullet_envs/scene_abstract.py b/examples/pybullet/gym/pybullet_envs/scene_abstract.py index 11ae8d489..51fd81f77 100644 --- a/examples/pybullet/gym/pybullet_envs/scene_abstract.py +++ b/examples/pybullet/gym/pybullet_envs/scene_abstract.py @@ -15,10 +15,6 @@ class Scene: self.dt = self.timestep * self.frame_skip self.cpp_world = World(gravity, timestep, frame_skip) - #self.cpp_world.set_glsl_path(os.path.join(os.path.dirname(__file__), "cpp-household/glsl")) - - #self.big_caption = self.cpp_world.test_window_big_caption # that's a function you can call - #self.console_print = self.cpp_world.test_window_print # this too self.test_window_still_open = True # or never opened self.human_render_detected = False # if user wants render("human"), we open test window @@ -52,8 +48,6 @@ class Scene: The idea is: apply motor torques for all robots, then call global_step(), then collect observations from robots using step() with the same action. """ - #if self.human_render_detected: - # self.test_window_still_open = self.cpp_world.test_window() self.cpp_world.step(self.frame_skip) class SingleRobotEmptyScene(Scene): From 7b219e0ea69c8c9f652b732ff0a2e6674597321c Mon Sep 17 00:00:00 2001 From: Benelot Date: Tue, 22 May 2018 16:40:10 +0200 Subject: [PATCH 2/3] Fix pendula to use the bullet-client. --- examples/pybullet/gym/pybullet_envs/gym_pendulum_envs.py | 4 ++-- examples/pybullet/gym/pybullet_envs/scene_abstract.py | 2 +- examples/pybullet/gym/pybullet_envs/scene_stadium.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/pybullet/gym/pybullet_envs/gym_pendulum_envs.py b/examples/pybullet/gym/pybullet_envs/gym_pendulum_envs.py index f71bf9283..c90e13200 100644 --- a/examples/pybullet/gym/pybullet_envs/gym_pendulum_envs.py +++ b/examples/pybullet/gym/pybullet_envs/gym_pendulum_envs.py @@ -18,7 +18,7 @@ class InvertedPendulumBulletEnv(MJCFBaseBulletEnv): def _reset(self): if (self.stateId>=0): #print("InvertedPendulumBulletEnv reset p.restoreState(",self.stateId,")") - p.restoreState(self.stateId) + self._p.restoreState(self.stateId) r = MJCFBaseBulletEnv._reset(self) if (self.stateId<0): self.stateId = self._p.saveState() @@ -59,7 +59,7 @@ class InvertedDoublePendulumBulletEnv(MJCFBaseBulletEnv): def _reset(self): if (self.stateId>=0): - p.restoreState(self.stateId) + self._p.restoreState(self.stateId) r = MJCFBaseBulletEnv._reset(self) if (self.stateId<0): self.stateId = self._p.saveState() diff --git a/examples/pybullet/gym/pybullet_envs/scene_abstract.py b/examples/pybullet/gym/pybullet_envs/scene_abstract.py index cc74839c8..b50dd524b 100644 --- a/examples/pybullet/gym/pybullet_envs/scene_abstract.py +++ b/examples/pybullet/gym/pybullet_envs/scene_abstract.py @@ -39,7 +39,7 @@ class Scene: """ return not self.multiplayer - def episode_restart(self): + def episode_restart(self, bullet_client): "This function gets overridden by specific scene, to reset specific objects into their start positions" self.cpp_world.clean_everything() #self.cpp_world.test_window_history_reset() diff --git a/examples/pybullet/gym/pybullet_envs/scene_stadium.py b/examples/pybullet/gym/pybullet_envs/scene_stadium.py index 8aef2552c..c105983db 100644 --- a/examples/pybullet/gym/pybullet_envs/scene_stadium.py +++ b/examples/pybullet/gym/pybullet_envs/scene_stadium.py @@ -17,7 +17,7 @@ class StadiumScene(Scene): def episode_restart(self, bullet_client): self._p = bullet_client - Scene.episode_restart(self) # contains cpp_world.clean_everything() + Scene.episode_restart(self, bullet_client) # contains cpp_world.clean_everything() if (self.stadiumLoaded==0): self.stadiumLoaded=1 From 4a16032820bef966ca940eb138adaa7e0e0c6f40 Mon Sep 17 00:00:00 2001 From: Benelot Date: Tue, 22 May 2018 18:12:45 +0200 Subject: [PATCH 3/3] Fix manipulators too. --- .../pybullet/gym/pybullet_envs/robot_manipulators.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/pybullet/gym/pybullet_envs/robot_manipulators.py b/examples/pybullet/gym/pybullet_envs/robot_manipulators.py index cdab943cf..f88487bb1 100644 --- a/examples/pybullet/gym/pybullet_envs/robot_manipulators.py +++ b/examples/pybullet/gym/pybullet_envs/robot_manipulators.py @@ -8,7 +8,7 @@ class Reacher(MJCFBasedRobot): def __init__(self): MJCFBasedRobot.__init__(self, 'reacher.xml', 'body0', action_dim=2, obs_dim=9) - def robot_specific_reset(self): + def robot_specific_reset(self, bullet_client): self.jdict["target_x"].reset_current_position( self.np_random.uniform(low=-self.TARG_LIMIT, high=self.TARG_LIMIT), 0) self.jdict["target_y"].reset_current_position( @@ -56,7 +56,7 @@ class Pusher(MJCFBasedRobot): def __init__(self): MJCFBasedRobot.__init__(self, 'pusher.xml', 'body0', action_dim=7, obs_dim=55) - def robot_specific_reset(self): + def robot_specific_reset(self, bullet_client): # parts self.fingertip = self.parts["fingertip"] self.target = self.parts["target"] @@ -138,9 +138,9 @@ class Striker(MJCFBasedRobot): max_object_placement_radius = 0.8 def __init__(self): - MJCFBasedRobot.__init__(self, 'lstriker.xml', 'body0', action_dim=7, obs_dim=55) + MJCFBasedRobot.__init__(self, 'striker.xml', 'body0', action_dim=7, obs_dim=55) - def robot_specific_reset(self): + def robot_specific_reset(self, bullet_client): # parts self.fingertip = self.parts["fingertip"] self.target = self.parts["target"] @@ -230,7 +230,7 @@ class Thrower(MJCFBasedRobot): def __init__(self): MJCFBasedRobot.__init__(self, 'thrower.xml', 'body0', action_dim=7, obs_dim=48) - def robot_specific_reset(self): + def robot_specific_reset(self, bullet_client): # parts self.fingertip = self.parts["fingertip"] self.target = self.parts["target"] @@ -307,4 +307,4 @@ class Thrower(MJCFBasedRobot): self.fingertip.pose().xyz(), self.object.pose().xyz(), self.target.pose().xyz(), - ]) \ No newline at end of file + ])