Data Sheet
RoboClaw Series
Brushed DC Motor Controllers
RoboClaw Series User Manual
101
Speed Controlled by Quadrature Encoders - Arduino Example
The following example was written using an Arduino UNO using packet serial wiring and
quadrature encoder wiring diagrams. The example will command a 4wheel robot to move
forward, backward, right turn and left turn slowly. You can change the speed by adjusting the
value of Speed and Speed2 variables. Additional example programs can be downloaded from
Ionmc.com.
//Set mode 7(packet serial address 0x80) and mode 4(38400)
//Includes required to use Roboclaw library
#include "BMSerial.h"
#include "RoboClaw.h"
#dene SPEED 12000
#dene SPEED2 12000
//Roboclaw Address
#dene address 0x80
//Velocity PID coefcients
#dene Kp 1.0
#dene Ki 0.5
#dene Kd 0.25
#dene qpps 44000
//Dente terminal for display. Use hardware serial pins 0 and 1
BMSerial terminal(0,1);
//Setup communcaitions with roboclaw. Use pins 10 and 11 with 10ms timeout
RoboClaw roboclaw(10,11,10000);
long speed;
long speed2;
void setup() {
//Open terminal and roboclaw serial ports
terminal.begin(57600);
roboclaw.begin(38400);
speed = SPEED;
speed2 = SPEED2;
//Set PID Coefcients
roboclaw.SetM1VelocityPID(address,Kd,Kp,Ki,qpps);
roboclaw.SetM2VelocityPID(address,Kd,Kp,Ki,qpps);
}