Down select design we used
Robot Drawing
Robot Multi-View
Battery Box Drawing
Motor Bracket Drawing
Sensor Bracket Drawing
Exploded View
Line Follower, Edge Detection and Bumper Code
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#define senseDark 500
#define senselite 100
#define motorSpeed 100
//The following 3 lines of code create the motorshield and tells what the motors
//objects are and tells what ports the motors will be attached to in the motorshield
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
int vlinl;
int vlinc;
int vlinr;
void setup(){
//begin the serial to be able to read values and debug
Serial.begin(9600);
AFMS.begin(1.6);
//"starting up" the motors
motor1->setSpeed(motorSpeed);
motor1->run(FORWARD);
motor2->setSpeed(motorSpeed);
motor2->run(FORWARD);
motor1->run(RELEASE);
motor2->run(RELEASE);
delay(1000);
}
void loop(){
readSensors();
//if both sensors are light, go straight
if (vlinl < senselite && vlinr < senselite){
stopSet();
motor1->run(BACKWARD);
motor2->run(BACKWARD);
}
//if right sensor goes dark, turn right
if (vlinl < senselite && vlinr > senseDark){
stopSet();
motor1->run(BACKWARD);
motor2->run(FORWARD);
delay(250);
}
//if left sensor goes dark, turn left
if (vlinl > senseDark && vlinr < senselite){
stopSet();
motor1->run(FORWARD);
motor2->run(BACKWARD);
delay(250);
}
}
void readSensors(){
//writing the values of the analog sensors into variables to determine cases for turning and going straight
vlinl = analogRead(A0);
vlinc = analogRead(A1);
vlinr = analogRead(A2);
}
void stopSet(){
//code to stop the motor and reset its speed in case it encounters a change in conditions
motor1->run(RELEASE);
motor2->run(RELEASE);
motor1->setSpeed(motorSpeed);
motor2->setSpeed(motorSpeed);
}
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
//more convenient and accurate to change a value once and have it propagate than to have to change it
//many times
#define senseDark 500
#define motorSpeed 100
//creating the motor "objects"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
//initializing the pins for the bumpers and the led (led for debugging purposes)
int buml = 6;
int bumr = 10;
int led = 13;
//declaring variables to store values of sensors
int vlinl;
int vlinc;
int vlinr;
int vbuml;
int vbumr;
void setup(){
//setting up for debugging (by reading sensor values through the serial)
Serial.begin(9600);
AFMS.begin(1.6);
//"starting up" the motors
motor1->setSpeed(motorSpeed);
motor1->run(FORWARD);
motor2->setSpeed(motorSpeed);
motor2->run(FORWARD);
motor1->run(RELEASE);
motor2->run(RELEASE);
//setting the pin mode for the bumpers
pinMode(buml, INPUT);
pinMode(bumr, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
delay(1000);
}
void loop(){
readSensors();
//running the motors if if cases fail
motor1->setSpeed(motorSpeed);
motor2->setSpeed(motorSpeed);
//if any of the sensors lose feedback, stop and turn around
if (vlinc > senseDark){
rotate();
}
//if either bumper is triggered, stop and turn
if (vbuml == HIGH){
Serial.println(vbuml);
rotate();
}
if (vbumr == HIGH){
Serial.println(vbumr);
rotate();
}
else{
motor1->run(BACKWARD);
motor2->run(BACKWARD);
}
}
//function to add sensor values to working variables
void readSensors(){
vbuml = digitalRead(buml);
vbumr = digitalRead(bumr);
vlinl = analogRead(A0);
vlinc = analogRead(A1);
vlinr = analogRead(A2);
//In case something is wrong with the robot, we can see what values the sensors have
//if we connect the bot to a monitor or if we read the serial output through the ide
//Serial.println(vlinl);
//Serial.println(vlinc);
//Serial.println(vlinr);
}
//function for stopping both motors, backing up and turning right
void rotate(){
motor1->run(RELEASE);
motor2->run(RELEASE);
motor1->setSpeed(motorSpeed);
motor2->setSpeed(motorSpeed);
motor1->run(FORWARD);
motor2->run(FORWARD);
delay(2000);
motor1->run(RELEASE);
motor2->run(RELEASE);
motor1->setSpeed(motorSpeed);
motor2->setSpeed(motorSpeed);
motor1->run(BACKWARD);
motor2->run(FORWARD);
delay (3000);
}
No comments:
Post a Comment