Software Description:
The software is decomposed into modules to handle gameplay. Four modules handle sensor input and responses to them (IRSensor, FlashSensor, TapeSensor, and Switch). Another three modules handle motor actuation (DriveMotor, DrawbridgeMotor, BallRequester). Two additional small modules helps with timing (GameTimer, Wait).
The overall framework is events and services based (see below image). A header file (stateDefines) contains #define values for each of the states of the game, and all of the modules have access to this header file. When a sensor event occurs, the current state is passed into the handle function, the handle function does the appropriate response, and the updated state is returned. The main function primarily consists of initialization of all the modules, checks and handles of sensor events (i.e. flash, IR, switch, and tape sensing), and function calls to actuators at appropriate states (i.e. to request and release balls).
The program starts with waiting for a flash to be sensed. The robot then turns until it senses a 50% duty cycle IR signal and drives forward. When it crosses black tape, it turns to align itself along it and then follows it until it ends in a T in front of the Happy Fun Ball Dispenser. Then it rams into the Happy Fun Ball Dispenser five times to request five balls. Each time it rams it drives forward into the Happy Fun Ball Dispenser and holds for 1 second, and then backs up and drives forward to ram again. After requesting five balls, it then reverses for a bit, turns 90 degrees, and heads toward Goal 3. When it crosses green tape, it turns 90 degrees to align itself along the green tape and follows the green tape until it ends in a T. If the robot is on Side A, the drawbridge is already facing Goal 3 when the robot has reached the end of the T. However, if the robot is on Side B, in order to orient the drawbridge toward Goal 3 it needs to make a 180 degree turn when it reaches the end of the T. In both cases, the drawbridge lowers to dispenses the balls into the goal. It then reverses, turns 90 degrees, and drives straight till it hits black tape again and repeats the sequence of requesting and releasing balls until two minutes have expired or three trips have been made to goal 3.
Click on the image to see a larger version (you may have to click on the image again in the new window to see the non-scaled size).
Software Design Module Breakdown:
- IRSensor: Captures input from a phototransistor positioned to sense signals from IR beacons on goals and ball dispenser. Two timer channels of the E128 timer capture the time of rising and falling edges respectively with interrupt-driven code. The instantaneous duty cycle is calculated, added to a running total, and then averaged every 8 ms (using another output capture interrupt). Check function returns whether a non-zero average duty cycle is being sensed. Service function coordinates drive motors response.
- FlashSensor: Captures input from a phototransistor pointed vertically (i.e. not at a beacon signal). Check function returns whether the signal has gone high (indicating a flash has occurred). Service function coordinates drive motors response.
- TapeSensor: Captures A/D input from seven tape sensors located on the underside of the robot and determines what type of tape they are sensing. The threshold values for different tape colors were found empirically and #defined. Check function returns whether the middle tape sensor is over tape (not over white floor). Services for the middle sensor being over tape and not over tape along with various other functions coordinate drive motors response.
- Switch: Captures input from a switch that is closed when the drawbridge is up. Check function returns whether the switch is closed.
- DriveMotor: Manages signal output to two DC motors that control the motion of the robot: forward, backward, turn left, turn right, and stop. These functions were decomposed into setting a left motor speed and a right motor speed and direction (by adjusting DC of PWM output channels) in order to achieve the desired action.
- BallRequester: Calls DriveMotor functions to manage sequence (backward, stop, forward, stop, wait 1 second) that causes robot to request balls from the ball dispenser.
- DrawbridgeMotor: Manages signal output to DC motor that controls the motion of the drawbridge: raise, lower, and stop.
- GameTimer: Timer that returns when 2 minutes have passed and thus the game is over and the robot should stop.
- Wait: Provides a function to wait for a specific (passed in as a parameter) amount of time
Pseudocode Listings:
Final Code Listings:
- Main File: Main.c
- State Defines Header File: stateDefines.h
- IRSensor: Module IRSensor.h, IRSensor.c
- FlashSensor Module: FlashSensor.h, FlashSensor.c
- TapeSensor Module: TapeSensor.h, TapeSensor.c
- Switch Module: Switch.h, Switch.c
- DriveMotor Module: DriveMotor.h, DriveMotor.c
- BallRequester Module: BallRequester.h, BallRequester.c
- DrawbridgeMotor Module: DrawbridgeMotor.h, DrawbridgeMotor.c
- GameTimer Module: GameTimer.h, GameTimer.c
- Wait Module: Wait.h, Wait.c
- ADS12 Module: ADS12.h, ADS12.c
|