/********************************************************************* Angels_EventCheckers.c Module This module holds all the functions that are checked by the ES framework ********************************************************************** /********************************************************************* Functions initBumpSensors Initializes bump sensors and limit swtiches Parameters: None Returns: None **********************************************************************/ Function initBumpSensors Sets the U ports setting bits 4-7 as inputs Sets AD Ports 0-3 as inputs End function /********************************************************************* Functions X____X____Bumped() Checks if the button has been pressed. Parameters: None Returns: boolean TRUE if expired, FALSE otherwise **********************************************************************/ Function AtLowerLimit if Lower Limit switch hit return True; otherwise return False; End function Function LowerLimitBumped Initialize ES_Event ThisEvent, Return value, last_lowerlimit, current_lowerlimit, time of last sample and current time. ReturnVal set to false; if currentlower limit doesnt equal last lower limit, and lower limit is hit post EV_HOPPER_BOTTOM_LIMIT set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_lowerlimit as the current lower limit return returnVal End function Function MiddleLimitBumped Initialize ES_Event ThisEvent, Return value, last_middlelimit, current_middlelimit, time of last sample and current time. ReturnVal set to false; if currentmiddlelimit doesnt equal last_middlelimit, and middle limit is hit post EV_HOPPER_MIDDLE_LIMIT set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_middlelimit as the current_middlelimit return returnVal End function Function UpperLimitBumped Initialize ES_Event ThisEvent, Return value, last_upperlimit, current_upperlimit, time of lastsample and current time. ReturnVal set to false; if currentlower upper doesnt equal last_upperlimit, and upperlimit is hit post EV_HOPPER_UPPER_LIMIT set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_upperlimit as the current_upperlimit return returnVal End function Function FrontRightBumped Initialize ES_Event ThisEvent, Return value, last_frontRight, current_frontRight, time of lastsample and current time. ReturnVal set to false; if current_frontRight doesnt equal last_frontRight, and frontRight is hit post EV_BUMP_FRONT_RIGHT; set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_frontRight as the current_frontRight return returnVal End function Function FrontLeftBumped Initialize ES_Event ThisEvent, Return value, last_frontLeft, current_frontLeft, time of lastsample and current time. ReturnVal set to false; if current_frontLeft doesnt equal last_frontLeft, and frontLeft is hit post EV_BUMP_FRONT_LEFT; set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_frontLeft as the current_frontLeft return returnVal End function Function BackRightBumped Initialize ES_Event ThisEvent, Return value, last_backRight, current_backRight, time of lastsample and current time. ReturnVal set to false; if current_backRight doesnt equal last_backRight, and backRight is hit post EV_BUMP_BACK_RIGHT; set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_backRight as the current_backRight return returnVal End function Function BackLeftBumped Initialize ES_Event ThisEvent, Return value, last_backLeft, current_backLeft, time of lastsample and current time. ReturnVal set to false; if current_backLeft doesnt equal last_backLeft, and backLeft is hit post EV_BUMP_BACK_LEFT; set ReturnVal to True; return ReturnVal; end if Reset TimeOfLastSample Set Last_backLeft as the current_backLeft return returnVal End function /************************************** Event Checking Functions for IR Beacons: Parameter: Nothing Returns: boolean TRUE if expired, FALSE otherwise ***************************************/ Function CheckLeftBeaconEvent Set boolean ReturnVal to FALSE; Inititialize ES_Event ThisEvent, LastPeriod[ArraySize], WorkingPeriod BeaconSeen=0, LastBeaconSeen=0, LastBeaconFoundTime, and LastPeriod[0] as LeftPeriod_uS(); if we havent seen a becon in 63 seconds, LastPeriod[0] = 0; end if set WorkingPeriod to LastPeriod[0]; // not averaging yet! // Characterize the beacon seen: if beacon period falls within range of beacon 1 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else if beacon period falls within range of beacon 2 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else if beacon period falls within range of beacon 3 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else if beacon period falls within range of beacon 4 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else else BeaconSeen set to 0; // Create an Event if things have changed: if BeaconSeen doesnt equal LastBeaconSeen if BeaconSeen value is 0 post event EV_LOSE_LEFT_SIGNAL with parameter 0; set ReturnVal to True; end if else post event EV_FIND_LEFT_SIGNAL with parameter BeaconSeen; ThisEvent.EventParam = BeaconSeen; set ReturnVal to True; end else set LastBeaconSeen to BeaconSeen; return ReturnVal; End function Function CheckRight BeaconEvent Set boolean ReturnVal to FALSE; Inititialize ES_Event ThisEvent, LastPeriod[ArraySize], WorkingPeriod BeaconSeen=0, LastBeaconSeen=0, LastBeaconFoundTime, and LastPeriod[0] as RightPeriod_uS(); if we havent seen a becon in 63 seconds, LastPeriod[0] = 0; end if set WorkingPeriod to LastPeriod[0]; // not averaging yet! // Characterize the beacon seen: if beacon period falls within range of beacon 1 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else if beacon period falls within range of beacon 2 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else if beacon period falls within range of beacon 3 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else if beacon period falls within range of beacon 4 period BeaconSeen=BEACON_1; LastBeaconFoundTime = ES_Timer_GetTime(); end if else else BeaconSeen set to 0; // Create an Event if things have changed: if BeaconSeen doesnt equal LastBeaconSeen if BeaconSeen value is 0 post event EV_LOSE_RIGHT_SIGNAL with parameter 0; set ReturnVal to True; end if else post event EV_FIND_RIGHT_SIGNAL with parameter BeaconSeen; ThisEvent.EventParam = BeaconSeen; set ReturnVal to True; end else set LastBeaconSeen to BeaconSeen; return ReturnVal; End function