Skip to content

Commit 490c27f

Browse files
committed
Add action sensor to arm effector
The action sensor adds an effector's action to the observation. This commit also adds a non-empty action space for the haptic actuation mode as dm-robotics doesn't allow an environment with completely empty action space.
1 parent d58fb07 commit 490c27f

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

src/dm_robotics/panda/arm.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
from dm_robotics.moma.models import utils as models_utils
1818
from dm_robotics.moma.models.end_effectors.robot_hands import robot_hand
1919
from dm_robotics.moma.models.robots.robot_arms import robot_arm
20-
from dm_robotics.moma.sensors import (robot_arm_sensor, robot_tcp_sensor,
21-
site_sensor, wrench_observations)
20+
from dm_robotics.moma.sensors import (action_sensor, robot_arm_sensor,
21+
robot_tcp_sensor, site_sensor,
22+
wrench_observations)
2223
from dm_robotics.transformations import transformations as tr
2324

2425
from . import arm_constants as consts
@@ -373,10 +374,6 @@ def __init__(self, robot_params: params.RobotParams, arm: robot_arm.RobotArm):
373374
"""
374375
super().__init__(arm, None, robot_params.name)
375376
self._robot_params = robot_params
376-
self._empty_spec = specs.BoundedArray(shape=(0,),
377-
dtype=np.float32,
378-
minimum=0,
379-
maximum=0)
380377

381378
def after_compile(self, mjcf_model: mjcf.RootElement,
382379
physics: mjcf.Physics) -> None:
@@ -394,11 +391,6 @@ def set_control(self, physics: mjcf.Physics, command: np.ndarray) -> None:
394391
return
395392
super().set_control(physics, command)
396393

397-
def action_spec(self, physics: mjcf.Physics) -> specs.BoundedArray:
398-
if self._robot_params.actuation == consts.Actuation.HAPTIC:
399-
return self._empty_spec
400-
return super().action_spec(physics)
401-
402394

403395
@enum.unique
404396
class ControlObservations(enum.Enum):
@@ -519,13 +511,20 @@ def build_robot(robot_params: params.RobotParams,
519511
if robot_params.actuation in [
520512
consts.Actuation.JOINT_VELOCITY, consts.Actuation.HAPTIC
521513
]:
522-
_arm_effector = ArmEffector(robot_params, arm)
514+
joint_effector = ArmEffector(robot_params, arm)
515+
_arm_effector, spy_sensor = action_sensor.create_sensed_effector(
516+
joint_effector)
517+
robot_sensors.append(spy_sensor)
523518
elif robot_params.actuation == consts.Actuation.CARTESIAN_VELOCITY:
524519
joint_velocity_effector = ArmEffector(robot_params, arm)
525-
_arm_effector = Cartesian6dVelocityEffector(robot_params, arm, gripper,
520+
cart_effector = Cartesian6dVelocityEffector(robot_params, arm, gripper,
526521
joint_velocity_effector,
527522
tcp_sensor, control_timestep)
528523

524+
_arm_effector, spy_sensor = action_sensor.create_sensed_effector(
525+
cart_effector)
526+
robot_sensors.append(spy_sensor)
527+
529528
robot.standard_compose(arm, gripper)
530529
moma_robot = robot.StandardRobot(arm=arm,
531530
arm_base_site_name=arm.base_site.name,

src/dm_robotics/panda/arm_constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ class Actuation(enum.Enum):
5656
ACTUATION_LIMITS = {
5757
Actuation.CARTESIAN_VELOCITY: VELOCITY_LIMITS,
5858
Actuation.JOINT_VELOCITY: VELOCITY_LIMITS,
59-
Actuation.HAPTIC: JOINT_LIMITS,
59+
Actuation.HAPTIC: {
60+
'min': (-1, -1, -1, -1, -1, -1, -1),
61+
'max': (1, 1, 1, 1, 1, 1, 1),
62+
},
6063
}

src/dm_robotics/panda/hardware.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dm_robotics.moma import robot
1111
from dm_robotics.moma.models.end_effectors.robot_hands import robot_hand
1212
from dm_robotics.moma.models.robots.robot_arms import robot_arm
13-
from dm_robotics.moma.sensors import robot_arm_sensor
13+
from dm_robotics.moma.sensors import action_sensor, robot_arm_sensor
1414
from panda_py import controllers, libfranka
1515

1616
from . import arm as arm_module
@@ -253,12 +253,18 @@ def build_robot(robot_params: params.RobotParams,
253253
if robot_params.actuation in [
254254
arm_constants.Actuation.JOINT_VELOCITY, arm_constants.Actuation.HAPTIC
255255
]:
256-
_arm_effector = ArmEffector(robot_params, panda, hardware_panda)
256+
joint_effector = ArmEffector(robot_params, panda, hardware_panda)
257+
_arm_effector, spy_sensor = action_sensor.create_sensed_effector(
258+
joint_effector)
259+
robot_sensors.append(spy_sensor)
257260
elif robot_params.actuation == arm_constants.Actuation.CARTESIAN_VELOCITY:
258261
joint_velocity_effector = ArmEffector(robot_params, panda, hardware_panda)
259-
_arm_effector = arm_module.Cartesian6dVelocityEffector(
262+
cart_effector = arm_module.Cartesian6dVelocityEffector(
260263
robot_params, panda, gripper, joint_velocity_effector, tcp_sensor,
261264
control_timestep)
265+
_arm_effector, spy_sensor = action_sensor.create_sensed_effector(
266+
cart_effector)
267+
robot_sensors.append(spy_sensor)
262268

263269
robot.standard_compose(panda, gripper)
264270
moma_robot = robot.StandardRobot(arm=panda,

0 commit comments

Comments
 (0)