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"
#dene SPEED 12000
#dene SPEED2 12000
//Roboclaw Address
#dene address 0x80
//Velocity PID coefcients
#dene Kp 1.0
#dene Ki 0.5
#dene Kd 0.25
#dene qpps 44000
//Dente 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 Coefcients
roboclaw.SetM1VelocityPID(address,Kd,Kp,Ki,qpps);
roboclaw.SetM2VelocityPID(address,Kd,Kp,Ki,qpps);
}