my arm sags whenever the driver releases the joystick, how do I hold it up
To prevent an arm from sagging when the driver releases the joystick, gravity compensation can be implemented using feedforward control . This involves adding a kF constant to the motor output to counteract the effect of gravity on the arm .
The logic for gravity compensation involves calculating the current angle of the arm and using a cosine function multiplied by the kF constant to determine the necessary power output . An example of this logic is:
while True:
error = desire_position - current_position; # no effect on gravity compensation
current_angle = (TICKS_AT_ZERO - current_tick) * DEGREE_PER_TICK
output = PID(error) + cos(radians(current_angle)) * kF
The kF constant approximates the power needed to counteract gravity and is typically found empirically . To tune kF, the PID gains can be set to 0, and kF can be increased until the arm can hold itself up at any position . If the arm still falls, kF should be increased; if it moves upwards, kF should be decreased .
Other Considerations
Arms require a high gear ratio and must be well-supported to manage the torque provided by the motor . Poorly supported or constructed arms can shake, making precise movements difficult . Software control, such as control loops, can help reduce the load on motor gearboxes .