AME 3623: Project 2
- All components of the project are due by Friday, February 22nd
at 10:00 am (note time change)
- Groups are the same as for project 1.
- Discussion within groups is fine.
- Discussion across groups may not be about the specifics of the
solution (general programming/circuit issues are fine to
discuss).
For this project, you will be reading analog data from an infrared
distance sensor (made by Sharp) and modeling the relationship between
the analog values and the distances.
Each group has been issued two Sharp sensors. In most cases, these
are already attached to your hovercraft frame. You may remove them
from the frame if it facilitates testing.
At the end of this project, you should be able to:
- connect an analog sensor to your microcontroller,
- read analog voltage data,
- display information through a USB serial interface,
- design mathematical models for transforming raw sensor data
into calibrated information,
- implement these models in code, and
- test the models.
Component 1: Microcontroller Circuit
Connect two Sharp infrared distance sensors to your circuit
board. Mark the sensors as "left" and "right so you know which
sensor is which. The coloring of the wires varies from connector to
connector. In general:
- Black/brown is ground
- Redish is +5V power
- Green/yellow is signal
Wiring:
- Connect power and ground from your breadboard. Power for the
Sharp sensors must come from Vin of the Teensy (this is the +5V
power supplies from the lower deck of your hovercraft).
- Note: do not connect +5V to +3.3V.
- Connect the signal line of each sensor to its own analog input pin
on the Teensy (analog pins are labeled with "A??", where ?? are
digits).
Component 2: Analog Interface Software for Data Collection
Write a data collection program:
- Define your analog pin mapping at the top of your INO file:
const int leftSharpPin = 1;
This example corresponds to Arduino analog pin A1.
Note that you will need two such definitions (one for each
distance sensor).
- In setup(), initialize the serial port connected to the
USB port (which is connected to your computer):
Serial.begin(57600);
This C++ notation is new for many of you. Here, there is a
software object that is related to a specific piece of
hardware. The global variable name for this object (provided
by the Arduino environment) is Serial.
begin()
is a function (also called a method) that is executed with
respect to this object. The 57600 is a parameter that
tells the serial port to send/receive data at 57,600 bits per second.
- Within your loop(), sample from both of the analog sensors
every 500ms. To read from the analog port that we defined
above, use the following:
int val = analogRead(leftSharpPin);
This will give you a value in the range 0 ... 1023,
corresponding to voltages 0 to 3.3V
- Print out the raw value:
Serial.println("Foo");
Will print the string "Foo" followed by a new line. You can
also use:
Serial.print("Foo");
to print without the new line.
These functions can take as input strings, ints or floats.
More examples may be found in the Arduino
documentation for print().
-
You can view the output from the Teensy on your computer by
clicking on the serial monitor button in the upper-right
corner of your Arduino window.
Component 3: Data Collection
- One at a time, set up each of your sensors so that they are
pointed in a direction that does not have any obstacles. Also,
make sure that the two sensors do not point at each other or at
the same obstacle.
- Place a flat obstacle at a known distance and record 5 samples
from of the raw analog value. The obstacle should be
orthogonal to the IR beam emitted from the sensor. Record
samples at least from the following distances: 8, 9, 10,
14, 20, 30, 40, 60, 80 cm. A calibrated set of marks has been
set up in FH 300 for this calibration step.
- Using a tool such as Excel or Matlab, graph the raw value as a
function of distance. Also graph the raw value as a
function of inverse distance.
Component 4: Sensor Model
Given the data that you collected, derive a
mathematical equation for distance as a function of sensor value.
Keep in mind:
- The output of the function must be in cm
- Using a simple mathematical function, you will be able
estimate
the distance quite well over a reasonable range. For the
purposes of navigation with these distance sensors (and nearby
obstacles), distance estimates need to be most accurate at
8 cm.
Performing a least-mean-squared fit of your function to your
data (i.e., using regression) will treat
all points equally in the fitting process. Instead, you must
favor 8cm. To do this, use a representative point
to define one point that your
function must capture well and then select any other parameters
to best capture the rest of your data.
- You will need a separate model for each of your sensors. Make
sure you keep careful records of which sensor is which (you
don't want to mix the distance sensors and models on future projects).
Component 5: Analog Interface Software
Define a new variable type in "project.h":
typedef enum {
DISTANCE_LEFT = 0,
DISTANCE_RIGHT = 1
}DistanceSensor;
DistanceSensor is the variable type. DISTANCE_LEFT and DISTANCE_RIGHT are the
two values that DistanceSensor variables can take on.
Implement the following function:
- float read_sharp(DistanceSensor side) will read
the analog port attached to the left distance sensor (if side
== DISTANCE_LEFT) or the right distance sensor (if side ==
DISTANCE_RIGHT) and return the calibrated distance in cm.
Component 6: Testing
Write a new test loop() function that repeatedly:
- Reads both the left and right sensors
- Prints both distances in cm on a single line.
Then:
What to Hand In
Submit to your project2 folder of your dropbox tree by
Friday, February 22nd at 10:00am:
- Documented code. Include both your "ino" and "h" files
in the dropbox. The documentation requirements are
the same as in project 1.
- Figures: a copy of the raw and calibrated graphs that
you generated (JPG, PNG, PDF or EPS format).
Other components:
- Demonstration/Code Review: All group
members must be present. This review must be completed by Tuesday,
February 26th. However, it is better to complete these reviews
as early as possible.
- Personal report: there is no personal report for this project.
Grading
-
Personal programming credit: this project offers one programming credit.
-
Group grade distribution:
- 35%: Project implementation
- 30%: Demonstration of working project (to either
of the TA or the instructor)
- 35%: Code documentation
-
Group Grading Rubric
-
Grades for individuals will be based on the group grade, but weighted
by the assessed contributions of the group members to the non-personal programming items.
andrewhfagg -- gmail.com
Last modified: Wed Feb 13 21:26:08 2019