Lucas (alright I as well) have had grand ideas of cool robots. This one, is cool, so far, but in the end will be too small for what we’re going to do. However, that hasn’t stopped this from becoming the beginning of a cool little rover.
If you go to the RobotShop and search for the V2 the chassis kit does not show up. You need to search for chassis or just visit this link. http://www.robotshop.com/en/dfrobotshop-rover-chassis-kit.html
I had ordered the treads and gearbox then found the chassis and ordered it. Once you have all of that you need the Arduino and a motorshield. I have a mega laying around from a 3D printer I’m never going to build (I mean I have a Printrbot so why would I want to build one). I also have two motorshields laying around, one was to build a 3D printer the other was for a robot…no really.
The first thing we did was go to a V2 page (http://www.robotshop.com/en/dfrobotshop-rover-tracked-robot-basic-kit.html). There is a nice video link on youtube that shows how to assemble the chassis and gearbox. I swapped the motors out for two that already had the wires attached and ready to go.
I did download the sample code (also on the page) that has a simple WASDX control system (where X is stop). I also have an Arduino Motor Shield so I went to (http://arduino.cc/en/Main/ArduinoMotorShieldR3) to look up the pins…and I rewrote some of the code (what? I couldn’t help myself).
The original code provided everything you need to move in all directions for the type of motor shield it was written for. Below you’ll find my modified code for the Arduino Motor Shield.
The next steps are to add all of the awesome gadgets that we have in mind (including a bluetooth controlled from iOS device).
#define MOTOR_A 12
#define SPEED_A 3
#define BRAKE_A 9
#define MOTOR_B 13
#define SPEED_B 11
#define BRAKE_B 8
// from http://arduino.cc/en/Main/ArduinoMotorShieldR3
//Function Channel A Channel B
//Direction Digital 12 Digital 13
//Speed (PWM) Digital 3 Digital 11
//Brake Digital 9 Digital 8
//Current Sensing Analog 0 Analog 1
void setup() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
pinMode(3, OUTPUT); //Initiates Speed Channel A pin
//setup Channel B
pinMode(13, OUTPUT); //Initiates Motor Channel B pin
pinMode(8, OUTPUT); //Initiates Speed Channel B pin
pinMode(11, OUTPUT); //Initiates Brake Channel B pin
Serial.begin(9600);
Serial.println("setup");
}
void loop() {
// Wait until a character is received
while (Serial.available() < 1) {}
char val = Serial.read();
//255 is maximum speed
int leftspeed = 255;
int rightspeed = 255;
// Perform an action depending on the command
switch(val) {
case 'w'://Move Forward
case 'W':
forward (leftspeed,rightspeed);
break;
case 's'://Move Backwards
case 'S':
reverse (leftspeed,rightspeed);
break;
case 'a'://Turn Left
case 'A':
left (leftspeed,rightspeed);
break;
case 'd'://Turn Right
case 'D':
right (leftspeed,rightspeed);
break;
default:
stop();
break;
}
}
void stop(void) {
digitalWrite(MOTOR_A, LOW);
analogWrite(SPEED_A, 0);
digitalWrite(MOTOR_B, LOW);
analogWrite(SPEED_B, 0);
Serial.println("stop");
}
void forward(char a, char b) {
analogWrite (SPEED_A,a);
digitalWrite(MOTOR_A,LOW);
analogWrite (SPEED_B,b);
digitalWrite(MOTOR_B,LOW);
Serial.println("forward");
}
void reverse (char a, char b) {
analogWrite (SPEED_A,a);
digitalWrite(MOTOR_A,HIGH);
analogWrite (SPEED_B,b);
digitalWrite(MOTOR_B,HIGH);
Serial.println("reverse");
}
void left (char a, char b) {
analogWrite (SPEED_A, a);
digitalWrite(MOTOR_A, LOW);
analogWrite (SPEED_B, b);
digitalWrite(MOTOR_B, HIGH);
Serial.println("left");
}
void right (char a, char b) {
analogWrite (SPEED_A, a);
digitalWrite(MOTOR_A, HIGH);
analogWrite (SPEED_B, b);
digitalWrite(MOTOR_B, LOW);
Serial.println("right");
}