Skip to content

[SENSOR] Fix actuator torque sensor naming for MuJoCo compatibility #19

@ShravanTata

Description

@ShravanTata

Description

The current logging code uses actuatorfrc_torque_{joint_name} when reading torque sensors from MuJoCo, while the mjcf.py follows the pattern f'actuatorfrc_{actuator.tag}_{actuator.joint}' to set the sensor names. However, this creates a mismatch with MuJoCo's naming conventions as actuator.tag returns motor for torque actuators.

Problem

  • Current behavior: Code generates sensor names like actuatorfrc_torque for torque actuators
  • Issue: MuJoCo doesn't have "torque" actuators - they are called "motor" actuators
  • Working cases: Position and velocity elements work correctly with this naming pattern

Expected Behavior

The sensor naming should align with MuJoCo's actuator terminology:

  • Option 1: Torque actuator sensors should be referenced as actuatorfrc_motor instead of actuatorfrc_torque
  • Option 2: Torque actuators sensors should be initialized as actuatorfrc_torque instead of actuatorfrc_motor

Impact

This naming mismatch likely causes:

  • Failed sensor readings for torque/motor actuators
  • Potential runtime errors or silent failures in logging
  • Inconsistency with MuJoCo's internal naming conventions

Proposed Solution 1

Update actuator sensor naming in mjcf.py

if actuator.tag == "motor":
    actuator_type = "torque"
else:
   actuator_type = actuator.tag
mjcf_model.sensor.add(
                    'actuatorfrc',
                    # Adapted for muscles
                    name=f'actuatorfrc_{actuator_type}_{actuator.joint}',
                    actuator=actuator_name,
                )

Proposed Solution 2

Update the actuator naming logic to map "torque" to "motor" when generating MuJoCo sensor names, or adjust the naming pattern to match MuJoCo's conventions.

diff@@ -44,7 +44,7 @@ def joints_data(physics, sensor_maps):
                 ['jointvel', 1],
                 ['actuatorfrc_position', 1],
                 ['actuatorfrc_velocity', 1],
-                ['actuatorfrc_torque', 1],
+                ['actuatorfrc_motor', 1],
         ]
     ]
 
@@ -74,7 +74,7 @@ def get_sensor_maps(physics, verbose=True):
         'jointpos', 'jointvel', 'jointlimitfrc',
         'force', 'torque',
         # Joints control
-        'actuatorfrc_position', 'actuatorfrc_velocity', 'actuatorfrc_torque',
+        'actuatorfrc_position', 'actuatorfrc_velocity', 'actuatorfrc_motor',
         # Muscles
         'musclefrc', 'tendonpos', 'tendonvel',
         'musclefiberlen', 'musclefibervel',
@@ -139,7 +139,7 @@ def get_sensor_maps(physics, verbose=True):
                     ['velocities', 'jointvel'],
                     ['torques (position)', 'actuatorfrc_position'],
                     ['torques (velocity)', 'actuatorfrc_velocity'],
-                    ['torques (torque)', 'actuatorfrc_torque'],
+                    ['torques (torque)', 'actuatorfrc_motor'],
                     ['limits', 'jointlimitfrc'],
                     ['forces (total)', 'force'],
                     ['torques (total)', 'torque'],
@@ -250,7 +250,7 @@ def get_physics2data_maps(physics, sensor_data, sensor_maps):
             'jointpos', 'jointvel', 'jointlimitfrc',
             'actuatorfrc_position',
             'actuatorfrc_velocity',
-            'actuatorfrc_torque',
+            'actuatorfrc_motor',
     ]:
         sensor_maps[f'{identifier}2data'] = np.array([
             sensor_maps[identifier]['indices'][
@@ -518,9 +518,9 @@ def physicsactuators2data(physics, iteration, data, sensor_maps, units):
         data.sensors.joints.array[iteration, :, sc.joint_torque] += (
             physics.data.sensordata[sensor_maps['actuatorfrc_velocity2data']]
         )*itorques
-    if len(sensor_maps['actuatorfrc_torque2data']) > 0:
+    if len(sensor_maps['actuatorfrc_motor2data']) > 0:
         data.sensors.joints.array[iteration, :, sc.joint_torque] += (
-            physics.data.sensordata[sensor_maps['actuatorfrc_torque2data']]
+            physics.data.sensordata[sensor_maps['actuatorfrc_motor2data']]
         )*itorques

Notes
Solution 2 is technically a breaking change for any code that explicitly references actuatorfrc_torque, the current implementation is broken because it doesn't actually log the motor torques from MuJoCo. This fix restores the intended functionality. Anyone relying on actuatorfrc_torque will need to update their code to use actuatorfrc_motor instead, but they'll also benefit from having access to the actual motor torque values that were previously missing.

Metadata

Metadata

Labels

bugSomething isn't workingenhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions