machinekoder / ar_gripper

ROS drivers for the AR Gripper - Open Hardware Parallel Adaptive Electric Gripper
0 stars 1 forks source link

gripper speed 10x too slow #3

Open mrjogo opened 3 months ago

mrjogo commented 3 months ago

The servo torque_limit getter and setter are missing a 10 conversion factor:

https://github.com/machinekoder/ar_gripper/blob/59ad095111884504eefb97f22cae3c282b8f8bb1/src/ar_gripper/feetech.py#L706-L717

Should be:

    @property
    def torque_limit(self):
        data = self._read_address(self._TORQUE_LIMIT_ADDR, 2)
        return int(data[0] | data[1] << 8) * 0.1

    @torque_limit.setter
    def torque_limit(self, value):
        if not 0.0 <= value <= 100.0:
            raise ValueError("Torque limit must be between 0 and 100%")
        value = int(value * 10)
        data = [value & 0xFF, value >> 8 & 0xFF]
        self._write_address(self._TORQUE_LIMIT_ADDR, data)

When combined with https://github.com/machinekoder/ar_gripper/blob/59ad095111884504eefb97f22cae3c282b8f8bb1/src/ar_gripper/gripper.py#L174 this means the gripper runs an order of magnitude slower than its maximum speed.

If setting the torque to 1/10th its maximum value is intentional (ie, due to the mechanism or something), please let me know, because I'm now running mine full speed 😄

mrjogo commented 3 months ago

Cranking up the torque immediately broke the calibration, which sent me down the rabbit hole of reading the SM85CL datasheets and experimentation. In doing so, I discovered a related bug: the driver is using servo.max_torque to change the torque while running, however that is the EPROM address for saving default torque, which is read into servo.torque_limit on powerup and subsequently ignored. Changes to servo.torque_limit will dynamically change the max torque of the motor.

Anyway, I did a big refactor to be able to move at full speed (full torque), but then immediately drop down to a lower torque once stall is detected (to avoid crushing things / tearing apart the gripper): https://github.com/mrjogo/ar_gripper/commit/76dc230a2340d5287468dd1d12baaf5663bd84bd