roverRobot.jpg (64991Bytes)
First post and second robot build (first was the Build your first robot from the Popular Mechanics magazine). I am having an issue and seeing if I can get some assistance.
When not plugged in, the robot sometimes moves, jerks or just sits there. I noted that times the battery connection to the Motor Shield fell out, but I have re-inserted for testing - I will be giving it a bigger wire to fit in the shield. There are other times, when it has power, it jerks as it if is doing something then nothing, or jerk - stop, jerk-stop. I dont know if it may be code or the power or both.
My robot is built using the following (using the Clusterbot as a influence: letsmakerobots.com/node/30832):
- Erector set for chassis.
- Arduino Uno
- Arduino Motor Shield r3
- HC-SR04 Distance Sensor - using the NewPing library
- Tamiya Twin Motor gearbox
- Radio Shack 9V connector (270-0324) & Plug (274-1569) to power the Uno
- Radio Shack 4-AA battery compartment (270-0391)
Code is below - you can note I am also checking for ping that is not 0. In the serial monitor, it would show as 0 when there was nothing in front of the sensor - I am attributing it to a software bug or dust/hair.
#include#define SENSOR_TRIG_PIN 7
#define SENSOR_ECHO_PIN 6
#define SENSOR_MIN_DIST 10
#define SENSOR_MAX_DIST 200#define MOTOR_CH_A 12
#define BRAKE_CH_A 9
#define SPEED_CH_A 3#define MOTOR_CH_B 13
#define BRAKE_CH_B 8
#define SPEED_CH_B 11#define HI_SPEED 175
#define LO_SPEED 75NewPing sonar(SENSOR_TRIG_PIN, SENSOR_ECHO_PIN, SENSOR_MAX_DIST);
void setup() {
Serial.begin(115200);pinMode(MOTOR_CH_A, OUTPUT); pinMode(BRAKE_CH_A, OUTPUT); pinMode(SPEED_CH_A, OUTPUT); pinMode(MOTOR_CH_B, OUTPUT); pinMode(BRAKE_CH_B, OUTPUT); pinMode(SPEED_CH_B, OUTPUT);
}
void loop() {
delay(50);
int ping = sonar.ping_cm();
Serial.println(ping);go_forward(); if ( ping <= SENSOR_MIN_DIST ) { if ( ping != 0 ) { brake(); delay(20); go_backwards(); delay(150); brake(); delay(20); turn_right(); delay(20); } }
}
void go_forward() {
Serial.println(“Going forward…”);digitalWrite(MOTOR_CH_A, HIGH); digitalWrite(BRAKE_CH_A, LOW); analogWrite(SPEED_CH_A, LO_SPEED); digitalWrite(MOTOR_CH_B, HIGH); digitalWrite(BRAKE_CH_B, LOW); analogWrite(SPEED_CH_B, LO_SPEED);
}
void go_backwards() {
Serial.println(“Going back…”);digitalWrite(MOTOR_CH_A, LOW); digitalWrite(BRAKE_CH_A, LOW); analogWrite(SPEED_CH_A, LO_SPEED); digitalWrite(MOTOR_CH_B, LOW); digitalWrite(BRAKE_CH_B, LOW); analogWrite(SPEED_CH_B, LO_SPEED);
}
void turn_left() {
Serial.println(“Going left…”);digitalWrite(MOTOR_CH_A, LOW); digitalWrite(BRAKE_CH_A, HIGH); analogWrite(SPEED_CH_A, LO_SPEED); digitalWrite(MOTOR_CH_B, HIGH); digitalWrite(BRAKE_CH_B, LOW); analogWrite(SPEED_CH_B, HI_SPEED);
}
void turn_right() {
Serial.println(“Going right…”);digitalWrite(MOTOR_CH_A, HIGH); digitalWrite(BRAKE_CH_A, LOW); analogWrite(SPEED_CH_A, HI_SPEED); digitalWrite(MOTOR_CH_B, LOW); digitalWrite(BRAKE_CH_B, HIGH); analogWrite(SPEED_CH_B, LO_SPEED);
}
void brake() {
Serial.println(“Braking…”);digitalWrite(BRAKE_CH_A, HIGH); digitalWrite(BRAKE_CH_B, HIGH);
}
Any help is greatly appreciated. A picture of the robot is included in the attachment.