This week, my team and I got some amount of work done and we are beginning to progress with the programming aspect of our project. I am relieved to see progress in this project and that we will meet our goals for this semester. Initially, I was stressing out over minimal progress made in our project but my team has been working on it the best they could. Understanding the code from the summer team was difficult to understand because I have not personally programmed code the way that team did. In other words, their code was lengthy and much more advanced than what I am usually accustomed to.
I was able to make some progress in modifying the code in the Arduino Micro while my partners are working on modifying the code on the Arduino UNO and on pathing. Below is the code that I was able to generate by modifying the existing sketch on the Arduino Micro. I was able to implement the LED for our purposes by indicating any of the four status indicators. If the LED is red, the podcar has stopped at a station. If the LED is green, the podcar is in motion. If the LED is blinking red, the kill switch has been pressed and the podcar has stopped. If the LED is blue, a checkpoint was successfully read. We also needed to change the safe distance from 30 cm (1 ft) to 15 cm (6 in). The reason we did this change was because the podcar stopped as it turned into the station. One of the supports was below the safe range which caused it to stop.
In the coming weeks, we will drastically work on the code for both the UNO and the Micro so that we can work with the mobile app team to get Processing to work with our design. These next remaining weeks might be stressful but I am confident that my team will meet our goals and what was expected of us this semester.
****************************************************************************
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define STOP 13 // emergency stop
#define RED 6 // STOP and error status
#define GREEN 5 // GO status
#define BLUE 3 // status of podcar
#define COMMON_CATHODE // Type of RGB LED
#define BUTTON 2 // Kill Switch
#define IS_PRESSED LOW
#define OFF LOW
#define ON HIGH
// RGB LED: green for GO status, red for STOP, blue for status, blinking red for error
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
int stop_counter = 0;
int restar_counter = 0;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(STOP, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(BUTTON,INPUT_PULLUP);
// change this to 56900 for XBEE comm
Serial.begin (9600);
Serial.print("Duration (ms)\t Distance \t Error Message");
Serial.println();
}
void loop()
{
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, OFF);
delayMicroseconds(2);
digitalWrite(trigPin, ON);
delayMicroseconds(10);
digitalWrite(trigPin, OFF);
// returns the length of the pulse in microseconds
duration = pulseIn(echoPin, ON);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
Serial.print(duration);
Serial.print("\t\t\t");
Serial.print(distance);
Serial.println();
// changed distance from 30 cm to 15 cm due to pole obstacle
if (distance <= 15)
{
setColor(255, 0, 0);
delay(100);
setColor(255, 0, 0);
delay(100);
setColor(255, 0, 0);
delay(100);
stop_counter++;
}
else if (digitalRead(BUTTON) == IS_PRESSED)
{
digitalWrite(STOP, LOW);
setColor(255, 0, 0);
}
else
{
stop_counter = 0;
setColor(0, 255, 0);
}
//Serial.println(stop_counter);
if (stop_counter == 10)
{
restar_counter = 0;
digitalWrite(STOP, HIGH);
Serial.print("Warning: Out of range!");
Serial.print("\t\t\t\t");
Serial.println();
stop_counter = 0;
delay(1000);
digitalWrite(STOP, LOW);
}
//Delay 50ms before next reading.
delay(50);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(RED, red);
analogWrite(GREEN, green);
analogWrite(BLUE, blue);
}
No comments:
Post a Comment