Update – 3/29/2012

I buttoned up all the wiring and added the on/off rocker switch today.

 

Update

We added 2 additional 9v batteries for more current

20120328-211938.jpg

Re-designed top

Here is the re-designed top, made to hold two 9v batteries, connected in parallel, and the on/off rocker switch.

Working Code!!!!

After many long hours debugging code, we finally have working code, that runs all the capabilities of our robot.
It is still tethered to the computer. but all the motors and sensors are working together correcetly.

Here’s what we got:

//ONU MAZE ROBOT 2012
//Andrew Moro, Emily Gedert, Eddie Day
const int STATE_FORWARD = 1;
const int STATE_TURN_RIGHT = 2;
const int STATE_BACKWARD = 3;
const int STATE_TURN_LEFT = 4;

int IRpin1 = 1;
int IRpin2 = 2;
int IRpin3 = 3;

int pwm_a = 3; //PWM control for motor outputs 1 and 2 is on digital pin 3
int pwm_b = 11; //PWM control for motor outputs 3 and 4 is on digital pin 11
int dir_a = 12; //direction control for motor outputs 1 and 2 is on digital pin 12
int dir_b = 13; //direction control for motor outputs 3 and 4 is on digital pin 13

int state; //current state
int lastState; //previous state

void setup()
{
Serial.begin(9600); // start the serial port
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
pinMode(pwm_b, OUTPUT);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);

analogWrite(pwm_a, 100); //set both motors to run at (100/255 = 39)% duty cycle (slow)
analogWrite(pwm_b, 100);
lastState = state = STATE_FORWARD;
}

void loop()
{

float volts1 = analogRead(IRpin1)*0.0048828125; // value from sensor * (5/1024) – if running 3.3.volts then change 5 to 3.3
float distance1 = 65*pow(volts1, -1.10); // worked out from graph 65 = theretical distance / (1/Volts1)S – luckylarry.co.uk
Serial.println(distance1); // print the distance
delay(400); // arbitary wait time.

float volts2 = analogRead(IRpin2)*0.0048828125; // value from sensor * (5/1024) – if running 3.3.volts then change 5 to 3.3
float distance2 = 65*pow(volts2, -1.10); // worked out from graph 65 = theretical distance / (1/Volts1)S – luckylarry.co.uk
Serial.println(distance2); // print the distance
delay(400); // arbitary wait time.

float volts3 = analogRead(IRpin3)*0.0048828125; // value from sensor * (5/1024) – if running 3.3.volts then change 5 to 3.3
float distance3 = 65*pow(volts3, -1.10); // worked out from graph 65 = theretical distance / (1/Volts1)S – luckylarry.co.uk
Serial.println(distance3); // print the distance
delay(400); // arbitary wait time.

Serial.print(‘\n’); // skips a line

if(state == 0) {
moveRobot();
return;
}

if (distance1 > 50)
{
state = STATE_FORWARD;
}
else if (distance1 < 50)
{
if (distance2 > 50)
{
state = STATE_TURN_RIGHT;
}
if(distance3 > 50)
{
state = STATE_TURN_LEFT;
}
}

Serial.println(state);
moveRobot();
}

void moveRobot()
{
switch( state ) {
case 1: {
digitalWrite(dir_a, LOW); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, LOW); //Set motor direction, 3 high, 4 low
break;
}
case 3: {
digitalWrite(dir_a, HIGH); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, HIGH); //Set motor direction, 3 high, 4 low
break;
}
case 2: {
digitalWrite(dir_a, LOW); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, HIGH); //Set motor direction, 3 high, 4 low
break;
}
case 4: {
digitalWrite(dir_a, HIGH); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, LOW); //Set motor direction, 3 high, 4 low
break;
}
}
}

//END OF LINE

Updated Assembly Drawing

Here’s the updated assembly drawing with the new arduino boards attached.

Arduino duemilanove + Ardumoto Motor Shield

The Arduino Duemilanove
This is what we’re using as our primary microcontroller

The Ardumoto Motor Shield

This is what we’re using as a motor driver since the Arduino cannot perform this function on its own.

This is what they look like when attached together.

Arduino

We decided to switch to the Arduino board since our Handyboard wasn’t reading sensors the right way (not to mention there isn’t much online about it because the chip is from 1999)

Luckily, we got a sensor to work on the Arduino! We found a tutorial online that went through setting it up and the code to program it. Arduino is programmed in C so there’s more similarities between that and what I learned in my programming class with C++. I also had the help of two engineering friends who have used the board before.

Here’s how we set it up. On the screen, we could see values being read and the numbers would increase when something was getting closer to the sensor. The only issue is when the object is out of the range of the sensor, the sensor doesn’t read numbers correctly anymore. The good thing about the Arduino is we only need one cable from the board to the computer. We cannot run motors off of it so we’re using a Motor Shield that fits right on top of the board and can run our motors off of it.

Maze: Done

The Maze is Done.

 

 

Build Portion Completed

The mechanical portion of our capstone project is now almost complete.  I assembled all of the components on the new bases together this afternoon and they fit together perfectly.  The handy-board will also fit very nicely with the adjusted holes.  The only problem I forsee is that the set-screw for the wheels is stripping the drive shaft.  Eddie and I decided that the best way to fix this is to grind a small notch in the shaft for the set screw to sit inside.

Here is the completed mechanical portion of the robot.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

We will now move our focus now more onto the bulk of programming.

Eddie and I have almost finished the maze and will complete it tonight (Wed 1/25)

Maze Progress

Andrew and I made a good bit of headway on the maze construction. It is roughly 90% complete. All 4 platforms are complete, the only tasks left to do are 1 ramp and legs for the 1 raised platform. We plan to finish up Wednesday evening.

Follow

Get every new post delivered to your Inbox.