How is managed the compliant parameter in the pypot controller?

Continuing the discussion from Artist residency: Êtres et Numérique:

I have some trouble with my SmartCompliance primitive behaviour. I wondering if it is not due to the fact that the compliance is not set as fast as I think.

I saw in the controller module the compliance was not added by default as a read/write loop:


self.add_sync_loop(50, self._get_pos_speed_load, 'Thread-get_pos_speed_load')
self.add_sync_loop(50, self._set_pos_speed_load, 'Thread-set_pos_speed_load')

self.add_write_loop(10, 'pid_gain', 'pid')
self.add_write_loop(10, 'compliance_margin')
self.add_write_loop(10, 'compliance_slope')

self.add_read_loop(1, 'angle_limit')
self.add_read_loop(1, 'present_voltage')
self.add_read_loop(1, 'present_temperature')

So:

  1. What happens when I set the compliance of a motors at 50 Hz ?
  2. Is it possible to add a custom read/write loop when we create a robot ? For example:
poppy = pypot.robot.from_config(...)
poppy.something.add_write_loop(50, 'compliant')

So, as you can see by directly looking inside the code of the controller, the compliance is actually synced inside the pos/speed/load loop.

def _set_pos_speed_load(self):
    change_torque = {}
    torques = [not m.compliant for m in self._motors]
    for m, t, old_t in zip(self._motors, torques, self._old_torques):
        if t != old_t:
            change_torque[m.id] = t
    self._old_torques = torques
    if change_torque:
        self._dxl_io._set_torque_enable(change_torque)

    rigid_motors = [m for m in self._motors if not m.compliant]
    ids = tuple(m.id for m in rigid_motors)

    if not ids:
        return

    values = ((m._values['goal_position'],
               m._values['moving_speed'],
               m._values['torque_limit']) for m in rigid_motors)
    self._dxl_io.set_goal_position_speed_load(dict(zip(ids, values)))

We implemented the synchronisation of the compliance this way to “bypass” the standard dynamixel motor behavior which re-enables the torque when setting a goal position. This should be explained in the doc (added to my todo list ;)).

To answer your two questions:

  1. It will indeed be synced at 50Hz. Yet, I don’t really know what happened if you keep changing the compliance and the goal_position at 50Hz. I don’t have a setup to test this right now, but I’m definitely interested in knowing what would happened. If you test it, let me know!
  2. It is possible yes, but as the compliance is already synced it is a bad idea :slight_smile:
1 Like

It’s true, I had forgotten that point …my bad.

Thanks