Merge pull request #1308 from benelot/fix-gyms
Fix gyms to make them work just like robotschool
This commit is contained in:
@@ -152,23 +152,25 @@ class Humanoid(WalkerBase):
|
|||||||
self.motor_names += ["left_shoulder1", "left_shoulder2", "left_elbow"]
|
self.motor_names += ["left_shoulder1", "left_shoulder2", "left_elbow"]
|
||||||
self.motor_power += [75, 75, 75]
|
self.motor_power += [75, 75, 75]
|
||||||
self.motors = [self.jdict[n] for n in self.motor_names]
|
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
|
if self.random_yaw:
|
||||||
# cpose = cpp_household.Pose()
|
position = [0,0,0]
|
||||||
# yaw = self.np_random.uniform(low=-3.14, high=3.14)
|
orientation = [0,0,0]
|
||||||
# if self.random_lean and self.np_random.randint(2)==0:
|
yaw = self.np_random.uniform(low=-3.14, high=3.14)
|
||||||
# cpose.set_xyz(0, 0, 1.4)
|
if self.random_lean and self.np_random.randint(2)==0:
|
||||||
# if self.np_random.randint(2)==0:
|
cpose.set_xyz(0, 0, 1.4)
|
||||||
# pitch = np.pi/2
|
if self.np_random.randint(2)==0:
|
||||||
# cpose.set_xyz(0, 0, 0.45)
|
pitch = np.pi/2
|
||||||
# else:
|
position = [0, 0, 0.45]
|
||||||
# pitch = np.pi*3/2
|
else:
|
||||||
# cpose.set_xyz(0, 0, 0.25)
|
pitch = np.pi*3/2
|
||||||
# roll = 0
|
position = [0, 0, 0.25]
|
||||||
# cpose.set_rpy(roll, pitch, yaw)
|
roll = 0
|
||||||
# else:
|
orientation = [roll, pitch, yaw]
|
||||||
# cpose.set_xyz(0, 0, 1.4)
|
else:
|
||||||
# cpose.set_rpy(0, 0, yaw) # just face random direction, but stay straight otherwise
|
position = [0, 0, 1.4]
|
||||||
# self.cpp_robot.set_pose_and_speed(cpose, 0,0,0)
|
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
|
self.initial_z = 0.8
|
||||||
|
|
||||||
random_yaw = False
|
random_yaw = False
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import numpy as np
|
|||||||
|
|
||||||
class InvertedPendulum(MJCFBasedRobot):
|
class InvertedPendulum(MJCFBasedRobot):
|
||||||
swingup = False
|
swingup = False
|
||||||
force_gain = 12 # TODO: Try to find out why we need to scale the force
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
MJCFBasedRobot.__init__(self, 'inverted_pendulum.xml', 'cart', action_dim=1, obs_dim=5)
|
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)
|
self.j1.set_motor_torque(0)
|
||||||
|
|
||||||
def apply_action(self, a):
|
def apply_action(self, a):
|
||||||
#assert( np.isfinite(a).all() )
|
assert( np.isfinite(a).all() )
|
||||||
if not np.isfinite(a).all():
|
if not np.isfinite(a).all():
|
||||||
print("a is inf")
|
print("a is inf")
|
||||||
a[0] = 0
|
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):
|
def calc_state(self):
|
||||||
self.theta, theta_dot = self.j1.current_position()
|
self.theta, theta_dot = self.j1.current_position()
|
||||||
x, vx = self.slider.current_position()
|
x, vx = self.slider.current_position()
|
||||||
#assert( np.isfinite(x) )
|
assert( np.isfinite(x) )
|
||||||
|
|
||||||
if not np.isfinite(x):
|
if not np.isfinite(x):
|
||||||
print("x is inf")
|
print("x is inf")
|
||||||
@@ -50,7 +49,6 @@ class InvertedPendulum(MJCFBasedRobot):
|
|||||||
|
|
||||||
class InvertedPendulumSwingup(InvertedPendulum):
|
class InvertedPendulumSwingup(InvertedPendulum):
|
||||||
swingup = True
|
swingup = True
|
||||||
force_gain = 2.2 # TODO: Try to find out why we need to scale the force
|
|
||||||
|
|
||||||
|
|
||||||
class InvertedDoublePendulum(MJCFBasedRobot):
|
class InvertedDoublePendulum(MJCFBasedRobot):
|
||||||
@@ -70,8 +68,7 @@ class InvertedDoublePendulum(MJCFBasedRobot):
|
|||||||
|
|
||||||
def apply_action(self, a):
|
def apply_action(self, a):
|
||||||
assert( np.isfinite(a).all() )
|
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( 200*float(np.clip(a[0], -1, +1)) )
|
||||||
self.slider.set_motor_torque( force_gain *200*float(np.clip(a[0], -1, +1)) )
|
|
||||||
|
|
||||||
def calc_state(self):
|
def calc_state(self):
|
||||||
theta, theta_dot = self.j1.current_position()
|
theta, theta_dot = self.j1.current_position()
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ class Scene:
|
|||||||
|
|
||||||
self.dt = self.timestep * self.frame_skip
|
self.dt = self.timestep * self.frame_skip
|
||||||
self.cpp_world = World(gravity, timestep, 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.test_window_still_open = True # or never opened
|
||||||
self.human_render_detected = False # if user wants render("human"), we open test window
|
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
|
The idea is: apply motor torques for all robots, then call global_step(), then collect
|
||||||
observations from robots using step() with the same action.
|
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)
|
self.cpp_world.step(self.frame_skip)
|
||||||
|
|
||||||
class SingleRobotEmptyScene(Scene):
|
class SingleRobotEmptyScene(Scene):
|
||||||
|
|||||||
Reference in New Issue
Block a user