Skip to content

Commit efc7378

Browse files
committed
Fix: use control timestep parameter in controller
Uses the control timestep of the environment to configure the Cartesian velocity controller. The latter was previously fixed to 0.1 seconds.
1 parent e9177ad commit efc7378

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/dm_robotics/panda/arm.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,21 @@ class Cartesian6dVelocityEffector(
328328
cartesian_6d_velocity_effector.Cartesian6dVelocityEffector):
329329
"""Panda Version of the MoMa Cartesian6dVelocityEffector."""
330330

331-
def __init__(self, robot_params: params.RobotParams, arm: robot_arm.RobotArm,
331+
def __init__(self,
332+
robot_params: params.RobotParams,
333+
arm: robot_arm.RobotArm,
332334
gripper: robot_hand.RobotHand,
333335
joint_velocity_effector: effector.Effector,
334-
tcp_sensor: robot_tcp_sensor.RobotTCPSensor):
336+
tcp_sensor: robot_tcp_sensor.RobotTCPSensor,
337+
control_timestep: float = 0.1):
335338
self._frame = robot_params.control_frame
336339
self._arm = arm
337340
self._get_world_pos = tcp_sensor.observables[tcp_sensor.get_obs_key(
338341
robot_tcp_sensor.Observations.POS)]
339342
model_params = cartesian_6d_velocity_effector.ModelParams(
340343
gripper.tool_center_point, arm.joints)
341344
control_params = cartesian_6d_velocity_effector.ControlParams(
342-
0.1,
345+
control_timestep,
343346
joint_position_limit_velocity_scale=.95,
344347
minimum_distance_from_joint_position_limit=.01,
345348
joint_velocity_limits=np.array(consts.VELOCITY_LIMITS['max']))
@@ -483,7 +486,8 @@ def _joint_torques(self, physics: mjcf.Physics) -> np.ndarray:
483486
self._arm.joints).qfrc_passive # pytype: disable=attribute-error
484487

485488

486-
def build_robot(robot_params: params.RobotParams) -> robot.Robot:
489+
def build_robot(robot_params: params.RobotParams,
490+
control_timestep: float = 0.1) -> robot.Robot:
487491
"""Builds a MoMa robot model of the Panda."""
488492
robot_sensors = []
489493
arm = Panda(actuation=robot_params.actuation, name=robot_params.name)
@@ -520,7 +524,7 @@ def build_robot(robot_params: params.RobotParams) -> robot.Robot:
520524
joint_velocity_effector = ArmEffector(robot_params, arm)
521525
_arm_effector = Cartesian6dVelocityEffector(robot_params, arm, gripper,
522526
joint_velocity_effector,
523-
tcp_sensor)
527+
tcp_sensor, control_timestep)
524528

525529
robot.standard_compose(arm, gripper)
526530
moma_robot = robot.StandardRobot(arm=arm,

src/dm_robotics/panda/environment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ def __init__(self,
3737
self._robots = collections.OrderedDict()
3838
for robot_params in self._robot_params:
3939
if robot_params.robot_ip is not None:
40-
robot = hardware.build_robot(robot_params)
40+
robot = hardware.build_robot(robot_params,
41+
control_timestep=self._control_timestep)
4142
else:
42-
robot = arm.build_robot(robot_params)
43+
robot = arm.build_robot(robot_params,
44+
control_timestep=self._control_timestep)
4345
self._robots[robot_params.name] = robot
4446
for robot, robot_params in zip(self._robots.values(), self._robot_params):
4547
self._arena.attach(robot.arm, robot_params.attach_site)

src/dm_robotics/panda/hardware.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def set_control(self, physics: mjcf.Physics, command: np.ndarray) -> None:
210210
self._command = 0 if command[0] < 0.5 else 0.08
211211

212212

213-
def build_robot(robot_params: params.RobotParams) -> robot.Robot:
213+
def build_robot(robot_params: params.RobotParams,
214+
control_timestep: float = 0.1) -> robot.Robot:
214215
"""Builds a MoMa robot model of the Panda with hardware in the loop."""
215216
hardware_panda = panda_py.Panda(robot_params.robot_ip)
216217
hardware_panda.set_default_behavior()
@@ -256,7 +257,8 @@ def build_robot(robot_params: params.RobotParams) -> robot.Robot:
256257
elif robot_params.actuation == arm_constants.Actuation.CARTESIAN_VELOCITY:
257258
joint_velocity_effector = ArmEffector(robot_params, panda, hardware_panda)
258259
_arm_effector = arm_module.Cartesian6dVelocityEffector(
259-
robot_params, panda, gripper, joint_velocity_effector, tcp_sensor)
260+
robot_params, panda, gripper, joint_velocity_effector, tcp_sensor,
261+
control_timestep)
260262

261263
robot.standard_compose(panda, gripper)
262264
moma_robot = robot.StandardRobot(arm=panda,

0 commit comments

Comments
 (0)