Repository.
You can find all of the code we wrote here: https://github.com/d1ma/me210
The final git diff --stat was a bit scary, and includes a lot of line following and debugging code that was not actually running on the Arduino during the final approach.
final_project/driver.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++
final_project/driver.h | 33 +++++++++++++
final_project/final_project.ino | 504 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
final_project/light_module.cpp | 23 +++++++--
final_project/light_module.h | 22 +++++----
final_project/light_sensor.h | 2 +-
final_project/line_follow.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++
final_project/motor.cpp | 46 ++++++++++++++++++
final_project/motor.h | 18 +++++++
final_project/state.cpp | 14 ++++++
final_project/state.h | 39 +++++++++++++++
led_reading_simple/led_reading_simple.ino | 27 +++++++++++
motor_testing/motor_testing.ino | 19 ++++++++
pin_reading/pin_reading.ino | 73 ++++++++++++++++++++++++++++
15 files changed, 1037 insertions(+), 19 deletions(-)
The final iteration of the code base was structured in the "if in state - do this" approach inside of the loop function provided by Arduino. Along the way, however, we wrote a library that interfaces with the vital components: LightModule and the Motors.
This hierarchal software approach allowed for rapid prototyping of light following and wall following approaches.
If we had more time...
Moreover, in the approach, we wrote a really nice abstraction of "State", that in the haste of debugging was not actually used in the end. Each potential state inherits from a parent class called State and implements two methods: void execute() and bool done(); These methods get called on the current state when running from the main Arduino loop -- and provides a nice encapsulation of any state the bot could be in.
Useful code samples.
Sonar
Here is a useful sonar code sample that abstracts away the interaction with Sonar sensor to produce a distance measurement in cm.
int distance(){
Serial.print("Distance: ");
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.println(distance);
return distance;
}
You can find all of the code we wrote here: https://github.com/d1ma/me210
The final git diff --stat was a bit scary, and includes a lot of line following and debugging code that was not actually running on the Arduino during the final approach.
final_project/driver.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++
final_project/driver.h | 33 +++++++++++++
final_project/final_project.ino | 504 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
final_project/light_module.cpp | 23 +++++++--
final_project/light_module.h | 22 +++++----
final_project/light_sensor.h | 2 +-
final_project/line_follow.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++
final_project/motor.cpp | 46 ++++++++++++++++++
final_project/motor.h | 18 +++++++
final_project/state.cpp | 14 ++++++
final_project/state.h | 39 +++++++++++++++
led_reading_simple/led_reading_simple.ino | 27 +++++++++++
motor_testing/motor_testing.ino | 19 ++++++++
pin_reading/pin_reading.ino | 73 ++++++++++++++++++++++++++++
15 files changed, 1037 insertions(+), 19 deletions(-)
The final iteration of the code base was structured in the "if in state - do this" approach inside of the loop function provided by Arduino. Along the way, however, we wrote a library that interfaces with the vital components: LightModule and the Motors.
- The LightModule library abstracts the tape sensor by exposing a method called measure, that returns "white" or "black" depending on what color the tape sensor is on (in other words doing what an op-amp/comparator would do in hardware).
- The Driver/Motor library abstracts the motors and interaction with them from the perspective of the algorithm. Driver exposes methods like straight(), back(), rotate(), while Motor exposes a single move(int) method that spins the motor forward if int is positive or backward if it is negative.
This hierarchal software approach allowed for rapid prototyping of light following and wall following approaches.
If we had more time...
Moreover, in the approach, we wrote a really nice abstraction of "State", that in the haste of debugging was not actually used in the end. Each potential state inherits from a parent class called State and implements two methods: void execute() and bool done(); These methods get called on the current state when running from the main Arduino loop -- and provides a nice encapsulation of any state the bot could be in.
Useful code samples.
Sonar
Here is a useful sonar code sample that abstracts away the interaction with Sonar sensor to produce a distance measurement in cm.
int distance(){
Serial.print("Distance: ");
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.println(distance);
return distance;
}
Create a free website
Start your own free website
A surprisingly easy drag & drop site creator. Learn more.