Latest Entries »

Final Robot Demo

Advertisements

FINAL CODE

int motor1a=6; //control pins for Motor1

int motor1b=7;

int motor2a=9; //control pins for Motor2

int motor2b=8;

 

int enableMotor1=10; //PWM Motor 1 Speed pin

int enableMotor2=11;

 

int pingPin = 12;

long duration, cm;

 

//float IR1;

//float IR2;

 

 

 

void forward(int speed) //function to move forward at a defined speed (0-255)

{

digitalWrite(motor1a, HIGH); //set motor 1 direction

digitalWrite(motor1b, LOW);

digitalWrite(motor2a, HIGH); //set motor 2 direction

digitalWrite(motor2b, LOW);

analogWrite(enableMotor1, speed); //set motor 1 speed (0-255)

analogWrite(enableMotor2, speed);

}

 

void reverse(int speed)

{

digitalWrite(motor1a, LOW); //set motor 1 direction

digitalWrite(motor1b, HIGH);

digitalWrite(motor2a, LOW); //set motor 2 direction

digitalWrite(motor2b, HIGH);

analogWrite(enableMotor1, speed);

analogWrite(enableMotor2, speed);

}

 

void left(int speed)

{

digitalWrite(motor1a, HIGH); //set motor 1 direction

digitalWrite(motor1b, HIGH);

digitalWrite(motor2a, HIGH); //set motor 2 direction

digitalWrite(motor2b, LOW);

analogWrite(enableMotor1, speed);

analogWrite(enableMotor2, speed);

}

 

void right(int speed)

{

digitalWrite(motor1a, HIGH); //set motor 1 direction

digitalWrite(motor1b, LOW);

digitalWrite(motor2a, HIGH); //set motor 2 direction

digitalWrite(motor2b, HIGH);

analogWrite(enableMotor1, speed);

analogWrite(enableMotor2, speed);

}

void tankturnleft(int speed)

{

digitalWrite(motor1a, LOW); //set motor 1 direction

digitalWrite(motor1b, HIGH);

digitalWrite(motor2a, HIGH); //set motor 2 direction

digitalWrite(motor2b, LOW);

analogWrite(enableMotor1, speed); //set motor 1 speed (0-255)

analogWrite(enableMotor2, speed);

}

 

void tankturnright(int speed)

{

digitalWrite(motor1a, HIGH); //set motor 1 direction

digitalWrite(motor1b, LOW);

digitalWrite(motor2a, LOW); //set motor 2 direction

digitalWrite(motor2b, HIGH);

analogWrite(enableMotor1, speed); //set motor 1 speed (0-255)

analogWrite(enableMotor2, speed);

}

 

void stop()

{

digitalWrite(motor1a, HIGH); //set motor 1 direction

digitalWrite(motor1b, HIGH);

digitalWrite(motor2a, HIGH); //set motor 2 direction

digitalWrite(motor2b, HIGH);

}

void ping()

{

pinMode(pingPin, OUTPUT);

digitalWrite(pingPin, LOW);

delayMicroseconds(2);

digitalWrite(pingPin, HIGH);

delayMicroseconds(5);

digitalWrite(pingPin, LOW);

 

pinMode(pingPin, INPUT);

duration = pulseIn(pingPin, HIGH);

 

cm = duration / 29 / 2;

}

 

void angleL(int degree)

{

tankturnright(120);

delay(degree*(5217/360));

stop();

delay(1000);

}

 

void angleR(int degree)

{

tankturnleft(120);

delay(degree*(5217/360));

stop();

delay(1000);

}

 

void triangle()

{

forward(120);

delay(1500);

stop();

delay(1500);

angleR(146);

forward(120);

delay(1500);

stop();

delay(1500);

angleR(146);

forward(120);

delay(1500);

}

void square()
{

angleL(125);

forward(120);

delay(750);

stop();

delay(1500);

angleR(105);

forward(120);

delay(750);

stop();

delay(1500);

angleR(115);

stop();

delay(1500);

forward(120);

delay(750);

}

void setup()

{

pinMode(motor1a, OUTPUT);

pinMode(motor1b, OUTPUT);

pinMode(motor2a, OUTPUT);

pinMode(motor2b, OUTPUT);

pinMode(enableMotor1, OUTPUT);

pinMode(enableMotor2, OUTPUT);

//Serial.begin(9600);

//pinMode(A0,INPUT);

//pinMode(A1, INPUT);

// IR1 = analogRead(A0);

}

 

 

 

void loop()

{

angleL(135);

triangle();

square();

stop();

delay(5000);
}

5/3/2012

Final touches on the robot and recalibrating the wheels so the lines and angles are more percise. The code is already done too.

5/1/12

We are today working on writing code for our final design. We have been having trouble with turning the robot, because it just keeps spinning in circles, but we will soon have it fixed.

20120501-142206.jpg

Troubles with robot

Unfortunately, our robot chip is short circuited in a certain area. Today we are attempting to find that area in order to fix it. After we switch a few wires, we should get it working and getting the sensors running in order to complete our next task.

Jobs today…
Eric- Working on project 4
Joepy- Changing algorithm into code
Nigel- Fixing the robot

4/10/12

Today’s jobs…
Eric-preparing an algorithm
Joepy-coding the robot
Nigel-troubleshooting

4/3/12

Today, we are inputting our code into the robot after finishing wiring. By the end. Of the day, our robot should be fully prepared for new and more complex codes and movements to be put in. We can’t get ahead do ourselves, though; for now, we are sticking to a line and taking baby steps towards our ultimate goal of the butterfly shape.

Today is the deadline to draw a line for showcasing tomorrow. We have finished robot construction and we now need to input the code and make sure everything is running smoothly.

Tweaks to the Design

After showing our design to Dr. Shankar, he decided to add a rectangle to the middle of the design, making a butterfly-like drawing. This is the new version of how it looks…

20120329-145608.jpg