Overview | Main | State Machine | Events | IR | Tape | Drivetrain | PWM | Flash | Two Minute Timer | Bump
void CalibrateTapeSensors(void):  calibration routine to correlate light levels with colors
              
              void TapeSensorInit(void): initialize  the tape sensing subsystem
              
              void TapeSensorRead(void): read in new  values from the tape sensors
              
              char getTapeColor(char sensor): get the  last seen color from a given tape sensor
              
              void main(void): test harness for tape  module
The tape module provides a simple interface to the tape sensors.
PSEUDOCODE
(Download Pseudocode .doc 27kb)
TapeSensorInit()
Initalize all states on tape sensor to be NO_TAPE
    Sets all the integral values to zero
    Initialize the TIM1 timer (it may be already initialized in beacon sensors)
    Set pre-scale to /128 or 187.5 kHz clock
    Set up an output compare
    Set the fourth TCx on TIM1 to output compare
    Set first event
    Clear the event flag.
  
    IF calibration is defined, 
        run calibration sequence
TapeSensorRead()
    For each sensor, every 20ms reads the value of the corresponding AD port and adds it to an integral array. 
 
    After 5 cycles of this (100ms) it checks if the integral is below a certain threshold area and updates the states of each of the sensors 
    IF 20ms timer is up.   
    set up next compare
    Add all the values to the appropriate integral array.
    IF 5 cycles have passed
        FOR each tape sensor
            Check the integral array value, and assign the TapeStateArray to the corresponding color
        Reset integral step to zero.
        Reset the integral array to zero.  
        Add 1 to number of cycles.
        return if 5 cycles have passed
    ELSE return  
getTapeColor(sensor)
    returns the State of the tape 'sensor' 
CalibrateTapeSensors()
CalibrateTapeSensors allows the tape module to store different analog thresholds
for white, green, and black tape which result from differing ambient light
conditions. The bot is placed in the four different configurations on the board
to allow for each sensor to be in a position to sense the levels of white,green,
and black.
    FOR each of four configurations of bot on board
        Store the AD reading from tape sensors to the center value of the current color the tape sensor is on.
Test Harness
main()
    TapeSensorRead
    Continuously print out states from each tape sensor
    

