Ha Ha, she's one hot bot.
I thought I'd post my first project.
I don't have much to offer the forum yet, but maybe someone can benefit from this.
I built this robot out of roof flashing, designed to stay on top of fine loose sand, spike-paddles were cut into each wheel and a 'ski' was on a pivot in the rear
I wish I had a pic of it finished
here's the code I used with it:
~this has nothing to do with my hexapod idea
/* 10-5-10
Pete Dokter
SparkFun Electronics
This is an example sketch for Arduino that shows very basically how to control an Ardumoto
motor driver shield with a 5V Arduino controller board.
~~~ The variable values in this code have changed significantly from the (above) author's draft,
I also incorporated bumper sensors (whiskers) with iterations and fixed the northward navigation
*/
#include <Wire.h>
#include <LSM303.h> //compass/accelerometer
LSM303 compass;
int pwm_a = 3; //PWM control for motor outputs 1 and 2 is pin 3
int pwm_b = 11; // outputs 3 and 4 is pin 11
int dir_a = 12; //direction control for motor outputs 1 and 2 is pin 12
int dir_b = 13; // outputs 3 and 4 is pin 13
const int bumperPinR = 2; //bumper pins
const int bumperPinL = 4;
int bumperStateR = 0; //variable for reading the bumper status
int bumperStateL = 0;
int IRsensorPin = A0; //input pin for IR sensor
int IRsensorValue = 0; //variable to store value of IR sensor
int LEDPin = 13; //On when backing up
void setup()
{
Serial.begin(9600);
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs (motors)
pinMode(pwm_b, OUTPUT);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);
//initialize bumper and IR pins
pinMode(bumperPinR, INPUT);
pinMode(bumperPinL, INPUT);
pinMode(IRsensorPin, INPUT);
pinMode(LEDPin, OUTPUT);
digitalWrite(dir_a, LOW); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, LOW); //Set motor direction, 3 high, 4 low
analogWrite(pwm_a, 255); //set both motors to 100% duty cycle
analogWrite(pwm_b, 255);
Wire.begin();
compass.init();
compass.enableDefault();
//Use Calibrate example program for compass values
//(environment specific ~magnetics differ from place to place, recalibrate)
//M min X: -405 Y: -108 Z: -9 M max X: -382 Y: -86 Z:8
//values are copied from serial monitor, pause calibration to copy
compass.m_min.x = -405;
compass.m_min.y = -108;
compass.m_min.z = -9;
compass.m_max.x = -382;
compass.m_max.y = -86;
compass.m_max.z = +8;
}
void loop()
{
digitalWrite(LEDPin, LOW);
digitalWrite(dir_a, LOW); //motor direction, 1 low, 2 high (forward)
digitalWrite(dir_b, LOW); // 3 high, 4 low
analogWrite(pwm_a, 200); //motors run at 80% duty cycle (slower)
analogWrite(pwm_b, 200);
compass.read();
int heading = compass.heading((LSM303::vector) {1,0,0} ); //1,0,0 aligns North
Serial.println("");
Serial.print("Compass: ");
Serial.print(heading);
Serial.print("\t");
//IR reading
IRsensorValue = analogRead(IRsensorPin);
Serial.print("IR Reading: ");
Serial.print(IRsensorValue);
Serial.print("\t");
//read state of bumper value
bumperStateR = digitalRead(bumperPinR);
bumperStateL = digitalRead(bumperPinL);
//Check IR Sensor
if(IRsensorValue > 455)
{
Serial.println("");
Serial.println("IR rev ");
//reverse
digitalWrite(dir_a, HIGH); //motor direction, 1 low, 2 high
digitalWrite(dir_b, HIGH); // 3 high, 4 low
analogWrite(pwm_a, 225); //motors run slower than 100% duty cycle =(255)
analogWrite(pwm_b, 225);
delay(450);
//turn right
digitalWrite(dir_a, HIGH); //motor direction, 1 low, 2 high
digitalWrite(dir_b, HIGH); // 3 high, 4 low
analogWrite(pwm_a, 15); //turns left in reverse
analogWrite(pwm_b, 245); //points further right in forward direction
delay(520);
//forward
digitalWrite(dir_a, LOW); //motor dir, 1 low, 2 high
digitalWrite(dir_b, LOW); // 3 high, 4 low
analogWrite(pwm_a, 230); //motors run at ()% duty cycle
analogWrite(pwm_b, 230);
delay(850);
}
else
{
//check if bumper triggered
if (bumperStateR == LOW)
{
//back and turn L
Serial.println("");
Serial.println("bumperR rev ");
//reverse
digitalWrite(dir_a, HIGH); //motor dir, 1 low, 2 high
digitalWrite(dir_b, HIGH); // 3 high, 4 low
analogWrite(pwm_a, 225); //motors run slower than 100% duty cycle
analogWrite(pwm_b, 225);
delay(450);
//turn left
digitalWrite(dir_a, HIGH); //motor dir, 1 low, 2 high
digitalWrite(dir_b, HIGH); // 3 high, 4 low
analogWrite(pwm_a, 15); //turns left in reverse
analogWrite(pwm_b, 245); //points further right in forward direction)
delay(525);
//forward
digitalWrite(dir_a, LOW); // 1 low, 2 high
digitalWrite(dir_b, LOW); // 3 high, 4 low
analogWrite(pwm_a, 230); //motors run at ()% duty cycle
analogWrite(pwm_b, 230);
delay(880);
}
if (bumperStateL == LOW)
{
//back and turn R
Serial.println("");
Serial.println("bumper L rev ");
//reverse
digitalWrite(dir_a, HIGH); //1 low, 2 high
digitalWrite(dir_b, HIGH); //3 high, 4 low
analogWrite(pwm_a, 225); //motors slower than 100% duty cycle
analogWrite(pwm_b, 225);
delay(450);
//turn right
digitalWrite(dir_a, HIGH); //1 low, 2 high
digitalWrite(dir_b, HIGH); //3 high, 4 low
analogWrite(pwm_a, 245); //turns left in reverse
analogWrite(pwm_b, 15); //points further right in forward direction)
delay(525);
//forward
digitalWrite(dir_a, LOW); //1 low, 2 high
digitalWrite(dir_b, LOW); //3 high, 4 low
analogWrite(pwm_a, 230); //motors at ()% duty cycle
analogWrite(pwm_b, 230);
delay(880);
}
//break out of iteration, start navigation
else
{
if(heading < 255) // (270) = north
{
//turn left
Serial.print("left");
digitalWrite(dir_a, LOW); //1 low, 2 high
digitalWrite(dir_b, LOW); //3 high, 4 low
analogWrite(pwm_a, 135); //motor A (left) slower, B (right) faster
analogWrite(pwm_b, 225);
delay(40);
}
if(heading > 285)
{
//turn right
Serial.print("right");
digitalWrite(dir_a, LOW); //1 l, 2 h
digitalWrite(dir_b, LOW); //3 h, 4 l
analogWrite(pwm_a, 225); //motor A faster, B slower
analogWrite(pwm_b, 135);
delay(40);
}
}
}
}
How do I attach a normal size photo?