fix pybullet gym environments: InvertedDoublePendulumBulletEnv-v0,
InvertedPendulumBulletEnv-v0, InvertedPendulumSwingupBulletEnv-v0 motors were not disabled, extra gains applied etc.
This commit is contained in:
@@ -53,6 +53,7 @@ class MJCFBasedRobot:
|
|||||||
part_name = part_name.decode("utf8")
|
part_name = part_name.decode("utf8")
|
||||||
parts[part_name] = BodyPart(part_name, bodies, i, -1)
|
parts[part_name] = BodyPart(part_name, bodies, i, -1)
|
||||||
for j in range(p.getNumJoints(bodies[i])):
|
for j in range(p.getNumJoints(bodies[i])):
|
||||||
|
p.setJointMotorControl2(bodies[i],j,p.POSITION_CONTROL,positionGain=0.1,velocityGain=0.1,force=0)
|
||||||
_,joint_name,_,_,_,_,_,_,_,_,_,_,part_name = p.getJointInfo(bodies[i], j)
|
_,joint_name,_,_,_,_,_,_,_,_,_,_,part_name = p.getJointInfo(bodies[i], j)
|
||||||
|
|
||||||
joint_name = joint_name.decode("utf8")
|
joint_name = joint_name.decode("utf8")
|
||||||
@@ -209,4 +210,4 @@ class Joint:
|
|||||||
self.disable_motor()
|
self.disable_motor()
|
||||||
|
|
||||||
def disable_motor(self):
|
def disable_motor(self):
|
||||||
p.setJointMotorControl2(self.bodies[self.bodyIndex],self.jointIndex,controlMode=p.VELOCITY_CONTROL, force=0)
|
p.setJointMotorControl2(self.bodies[self.bodyIndex],self.jointIndex,controlMode=p.POSITION_CONTROL, targetPosition=0, targetVelocity=0, positionGain=0.1, velocityGain=0.1, force=0)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ class InvertedPendulum(MJCFBasedRobot):
|
|||||||
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()
|
||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user