jeremiedecock / pyax12

Python library to control Dynamixel AX-12 actuators.
MIT License
18 stars 10 forks source link

Setting Acceleration with MX28 servo #5

Closed jimruxton closed 7 years ago

jimruxton commented 7 years ago

I am experimenting with pyax12 on an MX28 motor. It works quite well. Thanks for sharing your code. I want to add a command that will control acceleration so I tried just copying your set-speed function and creating a set_goal_acceleration function as below:

def set_goal_acceleration(self, dynamixel_id, acceleration):
    """Set the *acceleration* for the specified Dynamixel unit.

    :param int dynamixel_id: the unique ID of a Dynamixel unit. It must be
            in range (0, 0xFE).
    :param int acceleration: the new acceleration. It must be in range (0, 1023)
            i.e. (0, 0x3FF) in hexadecimal notation.
    """

    params = utils.int_to_little_endian_bytes(acceleration)

    self.write_data(dynamixel_id, pk.GOAL_ACCELERATION, params)
    # I set GOAL_ACCELERATION to 0x49 in the register

When I call this function I get a range error , just wondering if you have experimented with setting acceleration and if so what I could be doing wrong. I assume I only need to send the 1 parameter. I can set the "Goal Acceleration" using Dynamixel Wizard but when the motor power is recycled it reverts back to 0 "maximum acceleration" I'd also like to modify the PID values but that's another issue.

jeremiedecock commented 7 years ago

Hi Jim,

thanks for your feedback, I'm glad to know that pyax12 works on MX actuators too. Pyax12 has been written for AX-12 actuators and these actuators don't have the "goal acceleration" data in their control table ; Sadly I don't have any MX actuator so I can give you some clues but I cannot test them.

You use utils.int_to_little_endian_bytes function to make the acceleration value params. This function return a 2 bytes value. According to Robotis documentation, the goal acceleration data is coded with only 1 byte (it takes values in range [0,254]) contrary to the moving speed data (which takes 2 bytes). That's certainly why you have this range error.

For one byte values, one should not use the params = utils.int_to_little_endian_bytes(acceleration) line and simply write this (like the set_id function):

def set_goal_acceleration(self, dynamixel_id, acceleration):
        self.write_data(dynamixel_id, pk.GOAL_ACCELERATION, acceleration)

Also, don't forget that pyax12 has been written for AX-12 actuators, there may be deeper causes for issues observed on others Dynamixel series.