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

Fix mutable default robot object #61

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pybulletgym/envs/mujoco/envs/locomotion/humanoid_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


class HumanoidMuJoCoEnv(WalkerBaseMuJoCoEnv):
def __init__(self, robot=Humanoid()):
self.robot = robot
def __init__(self, robot=None):
self.robot = robot if robot is not None else Humanoid()
WalkerBaseMuJoCoEnv.__init__(self, self.robot)
self.electricity_cost = 4.25 * WalkerBaseMuJoCoEnv.electricity_cost
self.stall_torque_cost = 4.25 * WalkerBaseMuJoCoEnv.stall_torque_cost
2 changes: 1 addition & 1 deletion pybulletgym/envs/mujoco/robots/locomotors/humanoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Humanoid(WalkerBase, MJCFBasedRobot):
self_collision = True
foot_list = ["right_foot", "left_foot"] # "left_hand", "right_hand"

def __init__(self, random_yaw = False, random_lean=False):
def __init__(self, random_yaw=False, random_lean=False):
WalkerBase.__init__(self, power=0.41)
MJCFBasedRobot.__init__(self, 'humanoid_symmetric.xml', 'torso', action_dim=17, obs_dim=376)
# 17 joints, 4 of them important for walking (hip, knee), others may as well be turned off, 17/4 = 4.25
Expand Down
19 changes: 14 additions & 5 deletions pybulletgym/envs/mujoco/robots/robot_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ class URDFBasedRobot(XmlBasedRobot):
Base class for URDF .xml based robots.
"""

def __init__(self, model_urdf, robot_name, action_dim, obs_dim, basePosition=[0, 0, 0], baseOrientation=[0, 0, 0, 1], fixed_base=False, self_collision=False):
def __init__(self, model_urdf, robot_name, action_dim, obs_dim, basePosition=None, baseOrientation=None, fixed_base=False, self_collision=False):
XmlBasedRobot.__init__(self, robot_name, action_dim, obs_dim, self_collision)

self.model_urdf = model_urdf
self.basePosition = basePosition
self.baseOrientation = baseOrientation
self.basePosition = basePosition if basePosition is not None else [0, 0, 0]
self.baseOrientation = baseOrientation if baseOrientation is not None else [0, 0, 0, 1]
self.fixed_base = fixed_base

def reset(self, bullet_client):
Expand Down Expand Up @@ -185,9 +185,14 @@ class SDFBasedRobot(XmlBasedRobot):
Base class for SDF robots in a Scene.
"""

def __init__(self, model_sdf, robot_name, action_dim, obs_dim, basePosition=[0, 0, 0], baseOrientation=[0, 0, 0, 1], fixed_base=False, self_collision=False):
def __init__(self, model_sdf, robot_name, action_dim, obs_dim, basePosition=None, baseOrientation=None, fixed_base=False, self_collision=False):
XmlBasedRobot.__init__(self, robot_name, action_dim, obs_dim, self_collision)

if basePosition is None:
basePosition = [0, 0, 0]
if baseOrientation is None:
baseOrientation = [0, 0, 0, 1]

self.model_sdf = model_sdf
self.fixed_base = fixed_base

Expand Down Expand Up @@ -275,7 +280,11 @@ def reset_position(self, position):
def reset_orientation(self, orientation):
self._p.resetBasePositionAndOrientation(self.bodies[self.bodyIndex], self.get_position(), orientation)

def reset_velocity(self, linearVelocity=[0,0,0], angularVelocity =[0,0,0]):
def reset_velocity(self, linearVelocity=None, angularVelocity=None):
if linearVelocity is None:
linearVelocity = [0, 0, 0]
if angularVelocity is None:
angularVelocity = [0, 0, 0]
self._p.resetBaseVelocity(self.bodies[self.bodyIndex], linearVelocity, angularVelocity)

def reset_pose(self, position, orientation):
Expand Down
4 changes: 2 additions & 2 deletions pybulletgym/envs/roboschool/envs/locomotion/humanoid_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


class HumanoidBulletEnv(WalkerBaseBulletEnv):
def __init__(self, robot=Humanoid()):
self.robot = robot
def __init__(self, robot=None):
self.robot = robot if robot is not None else Humanoid()
WalkerBaseBulletEnv.__init__(self, self.robot)
self.electricity_cost = 4.25 * WalkerBaseBulletEnv.electricity_cost
self.stall_torque_cost = 4.25 * WalkerBaseBulletEnv.stall_torque_cost
Expand Down
2 changes: 1 addition & 1 deletion pybulletgym/envs/roboschool/robots/locomotors/humanoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Humanoid(WalkerBase, MJCFBasedRobot):
self_collision = True
foot_list = ["right_foot", "left_foot"] # "left_hand", "right_hand"

def __init__(self, random_yaw = False, random_lean=False):
def __init__(self, random_yaw=False, random_lean=False):
WalkerBase.__init__(self, power=0.41)
MJCFBasedRobot.__init__(self, 'humanoid_symmetric.xml', 'torso', action_dim=17, obs_dim=44)
# 17 joints, 4 of them important for walking (hip, knee), others may as well be turned off, 17/4 = 4.25
Expand Down
19 changes: 14 additions & 5 deletions pybulletgym/envs/roboschool/robots/robot_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ class URDFBasedRobot(XmlBasedRobot):
Base class for URDF .xml based robots.
"""

def __init__(self, model_urdf, robot_name, action_dim, obs_dim, basePosition=[0, 0, 0], baseOrientation=[0, 0, 0, 1], fixed_base=False, self_collision=False):
def __init__(self, model_urdf, robot_name, action_dim, obs_dim, basePosition=None, baseOrientation=None, fixed_base=False, self_collision=False):
XmlBasedRobot.__init__(self, robot_name, action_dim, obs_dim, self_collision)

self.model_urdf = model_urdf
self.basePosition = basePosition
self.baseOrientation = baseOrientation
self.basePosition = basePosition if basePosition is not None else [0, 0, 0]
self.baseOrientation = baseOrientation if baseOrientation is not None else [0, 0, 0, 1]
self.fixed_base = fixed_base

def reset(self, bullet_client):
Expand Down Expand Up @@ -183,9 +183,14 @@ class SDFBasedRobot(XmlBasedRobot):
Base class for SDF robots in a Scene.
"""

def __init__(self, model_sdf, robot_name, action_dim, obs_dim, basePosition=[0, 0, 0], baseOrientation=[0, 0, 0, 1], fixed_base=False, self_collision=False):
def __init__(self, model_sdf, robot_name, action_dim, obs_dim, basePosition=None, baseOrientation=None, fixed_base=False, self_collision=False):
XmlBasedRobot.__init__(self, robot_name, action_dim, obs_dim, self_collision)

if basePosition is None:
basePosition = [0, 0, 0]
if baseOrientation is None:
baseOrientation = [0, 0, 0, 1]

self.model_sdf = model_sdf
self.fixed_base = fixed_base

Expand Down Expand Up @@ -271,7 +276,11 @@ def reset_position(self, position):
def reset_orientation(self, orientation):
self._p.resetBasePositionAndOrientation(self.bodies[self.bodyIndex], self.get_position(), orientation)

def reset_velocity(self, linearVelocity=[0,0,0], angularVelocity =[0,0,0]):
def reset_velocity(self, linearVelocity=None, angularVelocity=None):
if linearVelocity is None:
linearVelocity = [0, 0, 0]
if angularVelocity is None:
angularVelocity = [0, 0, 0]
self._p.resetBaseVelocity(self.bodies[self.bodyIndex], linearVelocity, angularVelocity)

def reset_pose(self, position, orientation):
Expand Down