The final video of the Robot art is on our group blog. At: http://g5robot.wordpress.com/
Author Archives: drogba15
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);
}
Processing image of Jamaican flag and code
This image of the Jamaican flag was used created using processing. The goal of the project is to get the robot to draw this image autonomously.
size(900,480);
fill(0,0,0);
rect(0, 0, 900, 480);
noStroke();
fill(0, 255, 0);
triangle(0,0, 450, 240, 900, 0); // Top Triangle
triangle(0,480, 450, 240, 900, 480); // Bottom Triangle
stroke(255, 215, 0);
strokeWeight(10);
line(0, 0, 900, 480);
line(900, 0, 0, 480);
AVR Microcontroller
It said that the AVR enhanced RISC microcontrollers are based on a new RISC architecture that has been developed to take advantage of semiconductor integration and software capabilities of the 1990’s. In the AVR architecture is Central which has the fast-access RISC register file, that consists of 32 x 8-bit general purpose working registers. Within one single clock cycle, AVR can feed two arbitrary registers from the register file to the ALU, do a requested operation, and write back the result to an arbitrary register. ALU supports arithmetic and logic functions between registers or between a register and a constant. Single register operations are also executed in the ALU.
AVR uses a Harvard architecture, where the program memory space is separated from the data memory space. Program memory is accessed with a single level pipelining. While one instruction is being executed, the next instruction is being pre-fetched from the program memory. Due to the true single cycle execution of arithmetic and logic operations, the AVR microcontrollers achieve performance approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.