The Rover 5 from HobbyKing.com
This is for entertainment only but it worked perfectly for me.
This is what you get in the kit plus a 6 Cell Battery Holder
My version has Two Motors and No Encoders
You can dismantle the motor and drive wheels front and rear and adjust the ground clearance as well as tension the rubber track if required. I left mine as it came in the box. I had to consider what style of control I was going to use and whether I wanted to add to its operational capabilities later or not. I chose a simple set up first and decided to use Infrared sensor for obstacle avoidance, a servo to point the IR sensor across the front of the robot and I had a few Arduino Adafruit Motor Shields made by DK Electronics as well as a DCcduino Arduino Uno in my parts bin so that dictated how it was to be controlled.
This is the Infrared Sensor I used
I put some Heat Shrink on it for Protection
I had some IR sensors that I purchased a few months ago and I got then for $1.00AUD. I protected it with some heat shrink and glued a servo horn on the underside and left the adjustment trim pot uncovered so I could adjust the sensitivity of the sensor later on in the build. I will use four more later on when I design and build a robot arm for the robot, that will give it finer control over it's position.
The Servo Arm or Horn glued to the underside
I used a standard size Servo, one with plastic gears because it isn't doing heavy work and they were very cheap, $13.00AUD from Micro Engines in Australia, supporting the Local Bloke.
The Servo that I used
IR Sensor mounted on the servo
The Adafruit Motor Control Shield is one of the simplest motor control shields to use, it has a huge number of sketches already written by the Arduino Family and as always I Stand on the Shoulders of the great Women and Men that went before me and use the sketches that are out there for most of my builds and this one is no different. It was George Frick that did the original work on the sketch that I am using.
The Adafruit Motor Controller
The Arduino Uno Clone that I used
The Arduino Uno Clone that I used can be purchased from China for about $5.50AUD at the moment, it doesn't use the DIP chip so if it fails you have to replace the unit as a whole but they are very cheap anyway. I do have a genuine Arduino Uno that I use for programing the chips that I use in homemade builds and prototyping work.
The Beauty of the Adafruit shield and Arduino Uno
As you can see from the above image the beauty of the Adafruit Shield and the Arduino Uno is they clip together and occupy the same footprint in the build as well as having two servo outputs and the six A0 to A5 inputs, six 5V+ and 0V- pins all close together for easy wiring. I think that this is V2 but it is still available in clone forms for about $5.00AUD from China so they are very cheap as well.
As I mentioned you get a six cell battery holder in the Kit and I wired a switch to the earth or 0V line as well as a 2.1mm plug for the arduino power socket and two power wires to connect the 9V to the Motor Control Shield for maximum power for the motors. The combination or parts that I used makes it very easy to power and wire up the robot and lends itself beautifully to modifications and upgrades later on which is what I want to do in time with this robot base.
The Six Cell Battery Holder in the Kit
The Switch, 2.1mm Plug and Power Wires for the Motor shield
I have cut out a bit of 3mm MDF for the Rover 5 chassis that fits over the opening on the top of the robot so I can mount the components on the robot. I have cut out an opening for the servo motor to mount in and some holes for screws and wiring to go through so it is all safe and secure for operation. I mounted the components onto the MDF and had to put some spacers or standoffs under the mounting brackets for the servo as well as long screws, nuts and washers to get the clearance required for the batteries and wiring etc in the chassis. As it happens it worked out fine and stage one works well given how simple it really is.
Rover 5 Looking at the Front
Rover 5 Side View
The wiring is simple, the motor shield does most of the connections required for the Arduino Uno and then all you need to connect is the servo to the Servo 1 connection on the shield and the 5V+, 0V- and the output from the IR Sensor to power supply terminals on the shield and to A5 on the analog pins on the shield as well as the motor connections. You can have as many as four DC Motors controlled via this shield and in this case M1 and M2 are used and if the motors are going the wrong way just swap the motor wires around, M1 is the right hand motor and M2 is the left so it really is very simple.
The ON/OFF Switch is mounted between the servo and arduino
The Servo has just enough clearance
You will need to adjust the IR sensor to get the best result but other than that the Sketch works perfectly on my Arduino Clone and adafruit motor shield, This is the code that I used, enjoy.
/*
* George Frick (george.frick@gmail.com)
* Jan/Feb 2010.
* Arduino Robot 2 - Wandering Tank
* This robot will wander around, scanning with a very short range forward IR.
* When an object is detected, the robot will turn based on the position of the IR sensor
* during the detection. The robot will move backwards, then turn away from the detected object
* and continue. The robot runs continuously.
*/
#include <AFMotor.h>
#include <Servo.h>
// Two motors, a servo, and an IR sensor.
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
Servo sensorServo;
const int irPin = 19; // pin 5 as digital is pin 19
// Timing. I don't like using delay.
unsigned long tCnt = 0;
unsigned long tStart = 0;
unsigned long tDelta = 0;
unsigned long tTurn = 0;
int state; // Current Robot State
int lastState; // Previous Robot State
int servoPos; // Position to send servo
int servoDirection; // Direction servo is turning
int lastDetectionAngle; // Position of servo at last IR detect.
// Constants for state of tank tracks.
const int STATE_FORWARD = 1;
const int STATE_TURN_RIGHT = 2;
const int STATE_BACKWARD = 3;
const int STATE_TURN_LEFT = 4;
// Constants for Servo.
const int DIR_LEFT = 0;
const int DIR_RIGHT = 1;
const int MIN_DEGREE = 40;
const int MAX_DEGREE = 140;
/*
* Initializes everything. Is run once.
*/
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
sensorServo.attach(10); // attaches the servo on pin 10
pinMode(irPin, INPUT);
motor1.setSpeed(255); // set the speed to 200/255
motor2.setSpeed(255); // set the speed to 200/255
tStart = millis();
lastState = state = STATE_FORWARD;
servoPos = 90;
servoDirection = DIR_RIGHT;
sensorServo.write(servoPos);
//state = 0; // Uncomment to have robot not move tank tracks.
}
/*
* Runs continuously.
* 1. Update Servo.
* 2. Check IR sensor.
* 3. Move Robot
*/
void loop() {
tDelta = millis() - tStart;
tCnt += tDelta;
tStart += tDelta;
// Tell the servo to move 2 degrees every 25 ticks.
if( tCnt > 25 ) {
tCnt = 0;
if( servoDirection == DIR_LEFT ) {
servoPos -= 2;
} else if( servoDirection == DIR_RIGHT) {
servoPos += 2;
}
// Servo position will be beyond desired angles, turn around.
if( servoPos >= MAX_DEGREE ) {
servoDirection = DIR_LEFT;
} else if( servoPos <= MIN_DEGREE ) {
servoDirection = DIR_RIGHT;
}
sensorServo.write(servoPos);
}
// Allows disabling of tracks by setting state to 0.
if(state == 0) {
moveRobot();
return;
}
// Double read the pin, @see forums.adafruit.com
digitalRead(irPin);
delay(5);
if( digitalRead(irPin) == 0 ) {
lastDetectionAngle = servoPos;
state = STATE_BACKWARD;
} else {
if( state == STATE_BACKWARD ) {
if( lastDetectionAngle > 105 ) { // right
state = STATE_TURN_LEFT;
tTurn = 1000; // turn for ~1 seconds
} else if( lastDetectionAngle < 75 ) { // left
state = STATE_TURN_RIGHT;
tTurn = 1000; // turn for ~1 seconds
} else { // center
state = STATE_TURN_RIGHT; // for now, turn right by default.
tTurn = 1500; // turn for ~1 seconds
}
} else if ( state == STATE_TURN_RIGHT || state == STATE_TURN_LEFT ) {
tTurn -= tDelta;
if( tTurn <= 10 ) {
state = STATE_FORWARD;
}
} else {
state = STATE_FORWARD;
}
}
moveRobot();
}
/*
* Uses the state of the robot to move tank treads accordingly
*/
void moveRobot() {
// The motors seemed to respond better if they receive a stop before a switch in direction.
if( state != lastState ) {
motor1.run(RELEASE); // stopped
motor2.run(RELEASE); // stopped
}
switch( state ) {
default:
return; // helps test, state 0 = dont move.
case STATE_FORWARD: {
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD); // turn it on going forward
break;
}
case STATE_BACKWARD: {
motor1.run(BACKWARD); // turn it on going forward
motor2.run(BACKWARD); // turn it on going forward
break;
}
case STATE_TURN_RIGHT: {
motor1.run(FORWARD); // turn it on going forward
motor2.run(BACKWARD); // turn it on going forward
break;
}
case STATE_TURN_LEFT: {
motor1.run(BACKWARD); // turn it on going forward
motor2.run(FORWARD); // turn it on going forward
break;
}
}
lastState = state;
}
/* EOF */
My thoughts on the product or if I had to give it a score out of 10 I would give it an eight, 8/10, it lost two points because the battery holder had an opencircuit on the 0V- line at the soldered joint in the holder itself. Other than that it has huge amounts of power and remember I have the two motor version so four motors must be twice as powerful and ease of mating your build to the chassis is excellent with four screw mounting points that you can tap out for 3mm machine thread screws, that is what I did on mine and it worked perfectly. If you are looking for a tank style chassis motor setup this is one that I would highly recommend.
If you copy and paste the above code into your Arduino IDE it should work perfectly when used with the components that I used so have fun.
This is a very short video of it in operation;
No comments:
Post a Comment