Position control of servos motors

Hello All,
I am using a Dynamixel MX-28AT(2.0) servos.
I wish to control the servos using some mathematical equations. The position for the motors are generated by these kinematic equations. My question is how to write the code so that I can command the servo to finish the motion in specified time.
Eg : alpha = alpha_0 /(2tanh(2.7)) * tanh(2.7sin(2pif*t)) ;
here alpha_0 is a constant , f - frequency of the cycle and t is the time step at which the positions are being updated.
How do I calculate the time step size so that the motors will follow same frequency of motion as that of the equations.

Thank you for your time,

Regards,
Raj Kiran.

For a linear motion I'd take the distance divided by servo (PWM) step size evenly distributed over the specified time.

1 Like

Using servo.writeMicroseconds() instead of servo.write() will give you finer control over the servo position assuming that the servo is up to it mechanically

I hope that it goes without saying that if you are intending to move more than one servo at a time then delay() must not be used

This library may be of interest GitHub - kousheekc/Kinematics: Generalised kinematics library for Arduino based microcontrollers. Features matrix manipulation, Jacobian computation and forward and inverse kinematics using Newton Raphson method.

1 Like

Thanks for the reply, by servo step size do you mean the resolution of the servo or the corresponding PWM value?

Thanks for replying , but servo.write() is a command. I am asking regarding the positions or points that need to be given to servo.write() so that I can achieve the given motion in a specific time period.
And ya I am using 3 motors connected in series.

The suggestion to use writeMicroseconds() is applicable when you calculate the steps to take due to the finer control that it allows

The PWM signal resolution is determined by the timer settings. The servo reaction in time is subject to torque, acceleration and possibly more parameters.

what is the interface? i see 4.5 Mbps. is it digital?

doesn't seems like a PWM or servo.write() would work with this device

Ya I got you. But like I said earlier I am not giving the final position directly instead am giving the position values from the equations.
So if I want to make the servos follow the same frequency (time period) as that of the equations how can I achieve that ? And how can I code that way. Please direct me in this path.

I am using MATLAB.
And ya the servos can work at baudrate of 4.5Mbps.
I kind of confused when you say is it digital?

because the description says 4.5 M bits-per-second and 4,096 PRECISE RESOLUTION by 0.088 degrees

I am just a beginner level but working on this specific problem. So I will be lost if you throw so many parameters at me.
Is there any standard scaling rule to achieve required motion in position control mode
depending on the output motion of servos. As I need to vary the frequencies in the equation and also make servos to follow the same motion along with the same time period.

For synchronized moves you have to choose a common time increment. Not too short so that calculations and transmission can be performed in time.

Ya that is correct. Resolution of servos is 4096 for 360degree revolution. It is digital may be.

you're using an advanced high-end and expensive ($289) device

a typical RC servo used in a robotics application is driven by a 1-2 msec pulse. using servo.write() which proportionally positions the angle of the servo arm

The equipment may be high end but am just a beginner with basic level skills. And am stuck with this issue of position control.
Can you direct me to some sources where position control is being done using such kinematic equations?

Ya. So how do I choose the time increment.
Is there is standard rule for such scaling?

Start e.g. with 1 ms and reduce it as long as the movement is not smooth enough. The combined signal transmission time will give the lower limit.

presumably kinematics is determining the outputs to drive a device thru a desired path.

in this case, you simply tell the single device what position you want, some value between 0 - 4095, and it rotates to that position

Physical Connection:
RS485 / TTL Multidrop Bus
TTL Half Duplex Asynchronous Serial Communication with 8bit, 1stop, No Parity
RS485 Asynchronous Serial Communication with 8bit, 1stop, No Parity