# AME 3623: Project 5: Sensor Models

• All components of the project are due by Thursday, March 31st at 9:00 am
• 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).

At the end of this project, you should be able to:

• design mathematical models for transforming raw sensor data into calibrated information,
• implement these models in code, and
• test the models.

## Component 1: Circuit

• Connect a second Sharp infrared distance sensor to your circuit board. Use the same approach as with the previous project.

## Component 2: Sensor Model

Given the data that you collected on the previous project, derive a mathematical equation for distance as a function of sensor value. Keep in mind:
• The output of the function must be in mm
• 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 around 5 cm (and slightly above). 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
• The plots of your data from the previous project will help you to solve this problem for your first sensor. You will need to collect a second data set for the new sensor.

Define a new variable type in "project.h":
```typedef enum {
DISTANCE_LEFT = 0,
DISTANCE_RIGHT = 1
}Sensor;

```

Sensor is the variable type. DISTANCE_LEFT and DISTANCE_RIGHT are the two values that Sensor variables can take on.

Implement the following function:

• uint16_t read_distance(Sensor 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 mm. Computing the distance from the sensor value must be done using integer math (i.e., no floating point variables).

## Component 4: Testing

Write a test main() function that repeatedly:

• Reads both the left and right sensors
• Prints both distances in mm on a single line.

Then:

• Set up your sensor so that it is pointed in a direction that does not have any obstacles.

• For each sensor, place a flat obstacle at a known distance and record 5 samples from of the sensed value (your calibrated value). The obstacle should be orthogonal to the IR beam emitted from the sensor. Record samples at least from the following distances: 5, 6, 8, 10, 14, 20, 30, 40, 60, 80 cm.

Note: go through this process once for each sensor separately (using both sensors pointed in the same direction at the same time may result in interference)

• Using a tool such as Excel or Matlab, graph the reported value as a function of distance (mm). Generate curves for both sensors (could be the same graph or different ones)

Do the curves behave as you expect? (if not, then you need to review your implementation)

### What to Hand In

All components of the project are due by Thursday, March 31st at 9:00 am.
• Demonstration/Code Review: All group members must be present. Given time, this can be done during class. The demonstration must be completed by Monday, April 4th.

• Check in the following to the project 5 section of your subversion tree:
• Documented code: See the project 1 specification for detailed documentation requirements.
• Figures: a copy of the graph(s) that you generated (JPG, PNG, PDF or EPS format).

• Personal report: fill out the CATME survey. This is due by Tuesday, April 5th.

Personal programming credit:
• Each person must accumulate at least three personal programming credits over the course of the semester (this project offers one)

• To receive credit, you must be the primary designer, implementer and debugger of the component. This does not mean that your other group members should not be looking over your shoulder. But: you must do the "driving."