RSS Feed

Final Video of Robotic Art

The final video of the Robot art is on our group blog.  At: http://g5robot.wordpress.com/

Advertisements

Code for Final Run

The Source Code

#include “URMSerial.h”

// The measurement we’re taking #define DISTANCE 1 #define TEMPERATURE 2 #define ERROR 3 #define NOTREADY 4 #define TIMEOUT 5

URMSerial urm;

const int enablePinL = 3; //H-Bridge Left Side const int motorLeftPinA = 4; const int motorLeftPinB = 5;

const int enablePinR = 9; //H-Bridge Right Side const int motorRightPinA = 6; const int motorRightPinB = 7;

const int encoderPinL = 2; const int encoderPinR = 13;

volatile int ticks = 0; volatile boolean spinState = false;

void encInterrupt() { ticks++; }

void Stop() { detachInterrupt(0);

analogWrite(enablePinL, 0); analogWrite(enablePinR, 0); digitalWrite(motorLeftPinA, LOW); digitalWrite(motorLeftPinB, LOW); digitalWrite(motorRightPinA, LOW); digitalWrite(motorRightPinB, LOW); }

void Forward(int speed) { analogWrite(enablePinL, speed); analogWrite(enablePinR, speed); digitalWrite(motorLeftPinA, LOW); digitalWrite(motorLeftPinB, HIGH); digitalWrite(motorRightPinA, LOW); digitalWrite(motorRightPinB, HIGH); }

void Reverse(int speed) { analogWrite(enablePinL, speed); analogWrite(enablePinR, speed); digitalWrite(motorLeftPinA, HIGH); digitalWrite(motorLeftPinB, LOW); digitalWrite(motorRightPinA, HIGH); digitalWrite(motorRightPinB, LOW); }

void TurnRight(int speed) { analogWrite(enablePinL, speed); analogWrite(enablePinR, speed); digitalWrite(motorLeftPinA, LOW); digitalWrite(motorLeftPinB, HIGH); digitalWrite(motorRightPinA, HIGH); digitalWrite(motorRightPinB, LOW); }

void TurnLeft(int speed) { analogWrite(enablePinL, speed); analogWrite(enablePinR, speed); digitalWrite(motorLeftPinA, HIGH); digitalWrite(motorLeftPinB, LOW); digitalWrite(motorRightPinA, LOW); digitalWrite(motorRightPinB, HIGH); }

void setup() { Serial.begin(9600);                  // Sets the baud rate to 9600 urm.begin(11,12,9600); // RX Pin, TX Pin, Baud Rate Serial.println(“URM37 Library by Miles Burton – Distance. Version 2.0″);   // Shameless plug

pinMode(encoderPinL, INPUT); pinMode(enablePinL, OUTPUT); pinMode(enablePinR, OUTPUT); pinMode(motorLeftPinA, OUTPUT); pinMode(motorLeftPinB, OUTPUT); pinMode(motorRightPinA, OUTPUT); pinMode(motorRightPinB, OUTPUT);

delay(2500); }

void loop() { Serial.print(“Measurement: “); Serial.println(getMeasurement(DISTANCE));  // Output measurement

Serial.print(“Ticks: “); Serial.println(ticks);

if(!spinState) { Forward(200);

if(getMeasurement(DISTANCE) < 20) { Stop(); spinState = true; attachInterrupt(0, encInterrupt, CHANGE); }

} else if(spinState) { //if(ticks < 20) //{ TurnRight(255); //} if(ticks >= 33) { ticks = 0; spinState = false; detachInterrupt(0); }

}

delay(100);

}

int value; // This value will be populated int getMeasurement(int mode) { // Request a distance reading from the URM37 switch(urm.requestMeasurementOrTimeout(mode, value)) // Find out the type of request { case DISTANCE: // Double check the reading we recieve is of DISTANCE type //    Serial.println(value); // Fetch the distance in centimeters from the URM37 return value; break; case TEMPERATURE: return value; break; case ERROR: Serial.println(“Error”); break; case NOTREADY: Serial.println(“Not Ready”); break; case TIMEOUT: Serial.println(“Timeout”); break;

}

return -1;

}

Finally got Our Robot to Run

After, a very tedious but fun-filled semester working on our robot we finally get it to run to do our desire robotic art. This course has actually widen my parameters in electronics and C programming. Working with my other two group members: Ashuani Collins and Eric Cho has truly impacted my engineering life. This course has allow me to grasp esssential knowledge that would certainlty be beneficial to me in my engineering carrer.

Robot Going Forward and Turning

 

Robot drives at reduced power, then switches to full power, rotates, then drives again. Source code is below video

Source Code:

//Ashani TEst program

const int motorRightaPin = 7;    // H-bridge motor+ 1 (pin 2, 1A) const int motorRightbPin = 6;    // H-bridge motor- 1 (pin 7, 2A) const int motorLeftaPin = 5;    // H-bridge motor+ 2 (pin 15, 1A) const int motorLeftbPin = 4;    // H-bridge motor- 2 (pin 10, 2A) const int enablePin = 3;  // H-bridge enable pin Left side of robot

//const int motor3aPin = 10;    // H-bridge motor+ 2 (pin 15, 1A) //const int motor3bPin = 11;    // H-bridge motor- 2 (pin 10, 2A)

//const int motor4aPin = 13;    // H-bridge motor+ 2 (pin 15, 1A) //const int motor4bPin = 12;    // H-bridge motor- 2 (pin 10, 2A)

const int enable2Pin = 9;    // H-bridge enable pin for right side of robot

const int ultraSoundPin = 8;

int time = 0;

void goForward(int speed) {

analogWrite(enablePin, speed); //enable motors 50%duty cycle analogWrite(enable2Pin, speed); //enable motors 50%duty cycle

digitalWrite(motorRightaPin, HIGH); digitalWrite(motorRightbPin, LOW);

digitalWrite(motorLeftaPin, HIGH); digitalWrite(motorLeftbPin, LOW); }

void goTurnLeft() { analogWrite(enablePin, 255); //enable motors 50%duty cycle analogWrite(enable2Pin, 255); //enable motors 50%duty cycle

digitalWrite(motorRightaPin, HIGH); digitalWrite(motorRightbPin, LOW);

digitalWrite(motorLeftaPin, LOW); digitalWrite(motorLeftbPin, HIGH); }

void goTurnRight() { analogWrite(enablePin, 255); //enable motors 50%duty cycle analogWrite(enable2Pin, 255); //enable motors 50%duty cycle

digitalWrite(motorRightaPin, LOW); digitalWrite(motorRightbPin, HIGH);

digitalWrite(motorLeftaPin, HIGH); digitalWrite(motorLeftbPin, LOW); }

void goBackWard(int speed) {

analogWrite(enablePin, speed); //enable motors 50%duty cycle analogWrite(enable2Pin, speed); //enable motors 50%duty cycle

analogWrite(enablePin, 255); //enable motors 50%duty cycle analogWrite(enable2Pin, 255); //enable motors 50%duty cycle digitalWrite(motorRightaPin, LOW); digitalWrite(motorRightbPin, HIGH);

digitalWrite(motorLeftaPin, LOW); digitalWrite(motorLeftbPin, HIGH); }

void setup() {

// beginSerial(9600);

// set all the other pins you’re using as outputs: pinMode(motorRightaPin, OUTPUT); pinMode(motorRightbPin, OUTPUT); pinMode(motorLeftaPin, OUTPUT); pinMode(motorLeftbPin, OUTPUT);

pinMode(enablePin, OUTPUT); pinMode(enable2Pin, OUTPUT);

}

void loop() { time = millis();

if ( time < 10000) { goForward(127); } else if(time > 10000 && time < 20000) { goForward (255); }

else if (time >20000 & time < 30000) { goTurnRight(); }

else if (time > 30000) { goBackWard(255); }

delay(5000);

}

H-Bridge

Code

Souce Code: //Test Program written for Arduino Robot v1.0 //Marcorel

const int motor1aPin = 7;    // H-bridge motor+ 1 (pin 2, 1A) const int motor1bPin = 6;    // H-bridge motor- 1 (pin 7, 2A) const int motor2aPin = 5; // H-bridge motor+ 2 (pin 15, 1A) const int motor2bPin = 4;    // H-bridge motor- 2 (pin 10, 2A) const int enablePin = 3;  // H-bridge enable pin

const int motor3aPin = 10; // H-bridge motor+ 2 (pin 15, 1A) const int motor3bPin = 11;    // H-bridge motor- 2 (pin 10, 2A)

const int motor4aPin = 13;    // H-bridge motor+ 2 (pin 15, 1A) const int motor4bPin = 12;    // H-bridge motor- 2 (pin 10, 2A)

const int enable2Pin = 9;    // H-bridge enable pin

void setup() {

// set all the other pins you’re using as outputs: pinMode(motor1aPin, OUTPUT); pinMode(motor1bPin, OUTPUT); pinMode(motor2aPin, OUTPUT); pinMode(motor2bPin, OUTPUT);

pinMode(motor3aPin, OUTPUT); pinMode(motor3bPin, OUTPUT);

pinMode(motor4aPin, OUTPUT); pinMode(motor4bPin, OUTPUT);

pinMode(enablePin, OUTPUT); pinMode(enable2Pin, OUTPUT);

}

void loop() {

analogWrite(enablePin, 150); //enable motors 50%duty cycle analogWrite(enable2Pin, 150); //enable motors 50%duty cycle //Back engines digitalWrite(motor1aPin, HIGH); digitalWrite(motor1bPin, LOW);

digitalWrite(motor2aPin, HIGH); digitalWrite(motor2bPin, LOW);

// Front Engines digitalWrite(motor3aPin, HIGH); digitalWrite(motor3bPin, LOW);

digitalWrite(motor4aPin, HIGH); digitalWrite(motor4bPin, LOW); delay(300);

}

H-Bridges Implementation

SN7544 10NE H-Bridge Schematic

These are the H-bridges wired to the protoshield and connected to the arduino board using the above schematic. 

Charging cicuit schematic and picture

Schematic of Charging Circuit

 

Picture of Charging-Circuit