AME 3623: Project 2
- All components of the project are due by Thursday, February
20th at 5pm
- 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 0: Library Installation
Create a new project in your Arduino environment.
-
The PeriodicAction.zip library is in the lib
directory of your Dropbox. To install this library within the Arduino
environment, select
Sketch menu / Include Library / Add .ZIP Library. Navigate to
and select PeriodicAction.zip.
You will not need to repeat these steps in the future for this library
(although we will install others later).
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 supply 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).
- Connect the Analog GND pin on the Teensy to ground.
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 = A1;
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(115200);
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 115200 is a parameter that
tells the serial port to send/receive data at 115,200 bits per second.
- Implement the following function:
void sensor_display_step(){...};
that samples from each of your distance sensors and prints out
their values. Printing both on a single line will facilitate
testing later.
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
To print out the values, use the standard printf() function:
Serial.printf("Hello, World!\n");
See the printf() documentation for more information about
formatted printing: printf().
- Use the following for your loop function:
// A promise that this function will be implemented at some time
extern void sensor_display_step();
// Set up display function to be called once per 1000 ms
PeriodicAction sensor_display_task(1000, sensor_display_step);
// Check to see if the task is ready to be executed
void loop()
{
sensor_display_task.step();
}
-
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. You will submit these figures;
make sure to include a title and axis labels for each.
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 {
SHARP_LEFT = 0,
SHARP_RIGHT = 1
}SharpSensor;
SharpSensor is the variable type. SHARP_LEFT and SHARP_RIGHT
are the two values that SharpSensor variables can take on.
Implement the following function:
- float read_distance(SharpSensor side) will read
the analog port attached to the left distance sensor (if side
== SHARP_LEFT) or the right distance sensor (if side ==
SHARP_RIGHT) and return the calibrated distance in cm.
Component 6: Testing
Write a new version of the sensor_display_step() function that:
- Reads both the left and right sensors
- Prints both distances in cm on a single line.
Then:
Hints
- You should not have any more calls to delay() in your code!
(PeriodicAction does what we need here).
What to Hand In
Submit to your project2 folder of your dropbox tree by
Thursday, February 20th at 5:00pm:
- 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).
- Arduino pin plan: Update the teensy_3_5_pin_mapping.xlsx
file in the doc folder of your Dropbox with notes of how you
are using the pins for projects 1 and 2.
Other components:
- Demonstration/Code Review: All group
members must be present. This review must be completed by Monday,
February 24th. 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
- 25%: Demonstration of working project (to either
of the TA or the instructor)
- 40%: 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: Thu Feb 13 14:05:26 2020