CS 1020 - Lab 4 - Sensor Calibration

One of the challenges with physical sensors is that, for a variety reasons, two "identical" sensors will give you different values in the exact same situation. This can be problematic if you're using two sensors together like in our line following sciborgs or if you have to change sensors. Even for good sensors, when we change setting, like from the lab table to the hallway, the settings may need to change.

In this lab we are going to try and write some code that can help make our life easier by trying to automatically determine sensor-dependent thresholds. For this class, most of the decisions we're trying to make from the sensors are binary, e.g. are we on the line or off or is the light shining on the flashlight or not. What we'd like to do is take a number of measurements from each sensor in the settings that we will be using it in, record the values and then based on the values we see learn sensor-specific and situation-specific thresholds for making the decisions we need to make. This is called "sensor calibration"

Writing Your Own Sensor Calibration Code

For the IR sensors it would be very nice if the "black" threshold could be set automatically for both sensors and when we move to a different setting. For this lab, we're going to write code to do this.

As many of you noted, a good blackness threshold for the IR sensors was write in the middle of the readings the sensors saw on the tape and the readings off of the tape. Write code that automatically determines this value. Specifically:

  1. Write a procedure called calibrate that takes 300 sample readings from the two IR sensors. The procedure should keep track in "global" variables the min and max values read during these 300 sample readings for each sensor. After taking all of these readings, it should beep to indicate that it's done then save in global variable the average of the min and max for each sensor. Finally, the procedures should print out the min, max and average of the left sensor on the top line and the values for the right sensor on the bottom line.
  2. Load your calibrate procedure onto the Handy board and the run it. As you run it, move the sensors around both on and off tape (if you took your sciborg apart, just build a simple mechanism that keeps the sensors at the right height and allows you to move them on and off tape). After you run it, check the min, max and average values and make sure they make sense by comparing values that you see from the sensor display menu on the Handy boards. Run it a second time and make sure you get similar values.
  3. Write two procedures called sees-blackL? and sees-blackR? that determine if the left and right sensor is over black respectively based on your learned thresholds. These should return/output whether or not the respective sensor sees black.
When you're done, print out this code and submit it at the beginning of class on Wednesday.

Although we wrote this code for the IR sensors and for checking for black you could use similar code to calibrate your light sensors as well.