# AME 3623: Project 5: Sensor Models

• All components of the project are due by Thursday, March 5th at 8: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: 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 should 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), think about which set of values need to be most accurate. 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

Define a new variable type in "project.h":
```typedef enum {
LEFT = 0,
RIGHT = 1
}DistanceSensor;

```

DistanceSensor is the variable type. LEFT and RIGHT are the two values that DistanceSensor variables can take on.

Implement the following functions:

• uint16_t get_distance(DistanceSensor side) will read the analog port attached to the left distance sensor (if side == LEFT) or the right distance sensor (if side == RIGHT) and return the value in mm. Computing the distance from the sensor value must be done using integer math (i.e., no floating point variables).

• void display_distance(uint16_t dist) and will change the state of the ten LEDs to reflect the current distance.

## Component 3: Testing

Write a test main() function that repeatedly:

• Reads both the left and right sensors
• Displays 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. Include both sensors on this graph (one curve for each)

### What to Hand In

All components of the project are due by Thursday, March 5th at 8:00 am.
• Demonstration/Code Review: All group members must be present. Given time, this can be done during class.

• Check in the following to your group dropbox on D2L for project 5:
• Documented code:

Remember that documentation is about helping you and others looking at your code to understand what it is doing. Therefore, it will generally describe the logic of the code (and not-necessarily the low-level details). For this class:

1. At the top of your C file, document the project number, group members, date and the group member responsible for the code.
2. Each function must be documented (at the top of the function) as to what it does logically, what the meaning is of its inputs, and what the returned value is. If the function has external effects (e.g., commanding an actuator or modifying a global variable, these should also be documented here)
3. In-line comments should be used to describe logically what is happening at that line or group of lines.

• Figures: a copy of the graph that you generated (JPG, PNG, PDF or EPS format).

• Personal report: fill out the CATME survey. This is due by Monday, March 9th at 11:59pm.

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."