Roboclaw Motor Controller - olinrobotics/gravl GitHub Wiki
- Overview
- Documentation
- Wiring
- Configuring
-
Programming
a. Arduino Library
b. Encoders
c. Buffer - Example
The Roboclaw is a motor controller intended for varied and scaled control of motors at varied scales. GRAVL uses Roboclaws because they are available in numerous sizes and current load ratings, allowing a standardized motor controller for both small and large vehicles. These motor controllers have a number of useful features, including tune-able internal PID loops and an Arduino API library.
- RoboClaw User Manual: (link)
- Instructions for wiring, configuring, and programming RoboClaws
- RoboClaw Downloads Page: (link)
- Links to datasheets, API libraries, CAD, Drivers, etc.
- Kubo 1.0 Roboclaw Tuning Documentation: (link)
To check your wiring setup and tune the PID values for the actuators, you first need to be in Windows. Get the BasicMicro Motion Studio here. For reference, the use the RoboClaw 2x30A.
Although the full documentation can be found in the document linked above, here are some notable things to keep in mind when configuring the RoboClaw
- Under general settings, make sure the Control Mode is set to Packet Serial, the Packet Serial address is set to 128, and the baud rate is set to 38400. If you are tuning the hitch actuator, make sure the Encoder 2 Mode is set to Absolute.
- Under PWM Settings, move the sliding bar and verify the actuator moves. Move the sliding bar from one end to the other and take note of what the maximum encoder speed value is.
- Under velocity settings, put the maximum encoder value you noted into the qqps box. You could use the autotune, but we've found that it's not too great and sometimes crashes the program. I'd suggest manually tuning the PID constants. A good site for this can be found here
- Move the actuator from one endpoint to the other, taking note of the min and max encoder values. Put these values in the PID position controller under the min and max pos boxes. Tune the PID constants for position following a similar procedure to the constants for velocity.
- When you are finished tuning, make sure you click Device > Write Settings before exiting
To obtain the RoboClaw API for Arduino, follow these steps:
-
Navigate to the BasicMicro Downloads page here and download the
Arduino Library and Examples
from underneath the heading "RoboClaw General Downloads". -
Move the resulting
.zip
file from Downloads into the/libraries
directory in your arduino folder.
cd /opt/<arduino-version-here>/libraries
sudo mv ~/Downloads/arduino.zip .
unzip arduino.zip
In the past, RoboClaws used by GRAVL have experienced difficulty with the ReadEncM1 and ReadEncM2 functions. While the functions throw no errors and return values, they have been shown to be unreliable. It is better to use the ReadEncoders function, as shown below:
uint32_t reading1, reading2;
bool valid;
valid = roboclaw.ReadEncoders(ADDRESS, reading1, reading2);
The RoboClaw has a buffer for each motor channel that stores commands to execute sequentially. This buffer can cause large lag issues if your controller sends commands faster than the RoboClaw can execute them. Particularly with linear actuators, which move very slowly, sending messages that move the motor through the extent of it's actuation range repeatedly quickly bog down the system.
To set highest priority to the most recent command received, pass a '1' for the Buffer argument in a given motor command:
roboclaw.SpeedAccelDeccelPositionM1(ADDRESS, ACCEL, SPEED, DECCEL, POSITION, 1);
If you do keep the buffer, you will want to monitor it to prevent possible runaway states that induce too much lag for your system to handle. Use the ReadBuffers function as shown:
uint32_t buffer1, buffer2;
roboclaw.ReadBuffers(RC1_ADDRESS, buffer1, buffer2);