Skip to content

Commit c08ac2e

Browse files
authored
feat: add collision behavior and realtime parameters (#8)
* chore(deps): update panda-py * feat: add parameters for collision and realtime behavior * feat: implement collision behavior and realtime parameters * fix: use factories for mutable dataclass defaults * fix: import future annotations * chore: remove unused import * chore: formatting
1 parent 84d0c07 commit c08ac2e

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"dm-robotics-geometry>=0.6.0",
2727
"dm-robotics-transformations>=0.6.0",
2828
"dm_env",
29-
"panda-python",
29+
"panda-python>=0.7.4",
3030
]
3131
license = {file = "LICENSE"}
3232
readme = "README.md"

src/dm_robotics/panda/arm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import numpy as np
99
from dm_control import mjcf
1010
from dm_control.composer.observation import observable
11-
from dm_env import specs
1211
from dm_robotics.geometry import geometry, mujoco_physics
1312
from dm_robotics.moma import effector, robot, sensor
1413
from dm_robotics.moma.effectors import (arm_effector,
@@ -359,7 +358,7 @@ def set_control(self, physics: mjcf.Physics, command: np.ndarray) -> None:
359358

360359
class ArmEffector(arm_effector.ArmEffector):
361360
"""Robot arm effector for the Panda MoMa model.
362-
361+
363362
Takes :py:class:`dm_robotics.panda.parameters.RobotParams`
364363
and changes the joint stiffness and damping of the robot arm. Otherwise behaves
365364
like :py:class:`dm_robotics.moma.effectors.arm_effector.ArmEffector`.
@@ -467,7 +466,7 @@ def _vel_control(self, physics: mjcf.Physics) -> np.ndarray:
467466

468467
class RobotArmSensor(robot_arm_sensor.RobotArmSensor):
469468
"""Behaves like :py:class:`dm_robotics.moma.sensors.robot_arm_sensor.RobotArmSensor`.
470-
469+
471470
Except that the joint torque signal does not include passive forces.
472471
This is done so as to model the external torque signal provided by the Panda robot.
473472
"""

src/dm_robotics/panda/hardware.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,16 @@ def set_control(self, physics: mjcf.Physics, command: np.ndarray) -> None:
211211
def build_robot(robot_params: params.RobotParams,
212212
control_timestep: float = 0.1) -> robot.Robot:
213213
"""Builds a MoMa robot model of the Panda with hardware in the loop."""
214-
hardware_panda = panda_py.Panda(robot_params.robot_ip)
214+
hardware_panda = panda_py.Panda(
215+
robot_params.robot_ip,
216+
realtime_config=libfranka.RealtimeConfig.kEnforce
217+
if robot_params.enforce_realtime else libfranka.RealtimeConfig.kIgnore)
215218
hardware_panda.set_default_behavior()
216219
hardware_panda.get_robot().set_collision_behavior(
217-
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0],
218-
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0],
219-
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0],
220-
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0])
220+
robot_params.collision_behavior.lower_torque_thresholds,
221+
robot_params.collision_behavior.upper_torque_thresholds,
222+
robot_params.collision_behavior.lower_force_thresholds,
223+
robot_params.collision_behavior.upper_force_thresholds)
221224

222225
robot_sensors = []
223226
panda = arm_module.Panda(actuation=robot_params.actuation,

src/dm_robotics/panda/parameters.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Contains dataclasses holding parameter configurations."""
2+
from __future__ import annotations
3+
24
import dataclasses
35
from typing import Optional, Sequence
46

@@ -17,6 +19,19 @@ class GripperParams:
1719
sensors: Optional[Sequence[sensor.Sensor]] = None
1820

1921

22+
@dataclasses.dataclass
23+
class CollisionBehavior:
24+
"""Parameters to define the collision behavior of the real robot."""
25+
lower_torque_thresholds: list[float] = dataclasses.field(
26+
default_factory=lambda: [50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0])
27+
upper_torque_thresholds: list[float] = dataclasses.field(
28+
default_factory=lambda: [50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0])
29+
lower_force_thresholds: list[float] = dataclasses.field(
30+
default_factory=lambda: [50.0, 50.0, 50.0, 50.0, 50.0, 50.0])
31+
upper_force_thresholds: list[float] = dataclasses.field(
32+
default_factory=lambda: [50.0, 50.0, 50.0, 50.0, 50.0, 50.0])
33+
34+
2035
@dataclasses.dataclass
2136
class RobotParams:
2237
"""Parameters used for building the Panda robot model.
@@ -35,6 +50,8 @@ class RobotParams:
3550
robot_ip: Robot IP or hostname. If `None` hardware in the loop is not used.
3651
joint_stiffness: Joint stiffness of the robot used in actuation.
3752
joint_damping: Joint damping of the robot used in actuation.
53+
collision_behavior: configures the collision behavior of the real robot.
54+
enforce_realtime: enforce realtime priority of real robot control threat
3855
"""
3956
name: str = 'panda'
4057
pose: Optional[Sequence[float]] = None
@@ -47,3 +64,5 @@ class RobotParams:
4764
robot_ip: Optional[str] = None
4865
joint_stiffness: Sequence[float] = (600, 600, 600, 600, 250, 150, 50)
4966
joint_damping: Sequence[float] = (50, 50, 50, 20, 20, 20, 10)
67+
collision_behavior: CollisionBehavior = CollisionBehavior()
68+
enforce_realtime: bool = False

0 commit comments

Comments
 (0)