Module T_Collision.c Description This is a HSM module for the collision service of our robot Notes Private definitions ENTRY_STATE Left Right FORWARD North East South West CollisionReverse CollisionRotate CollisionDrive REVERSE FORWARD /*---------------------------- Module Functions ---------------------------*/ /* prototypes for private functions for this service.They should be functions relevant to the behavior of this service */ ES_Event_t RunCollision(ES_Event_t CurrentEvent) //Set make transition to false //Set next state to current state //Create return event //If case reversing //Set return event to during reversing //If current event is a timeout //If event parameter is collision timer //Set next state to rotating //Set make transition to true //Consume event //else if case rotating //Set return event to during rotating //If event is a timeout //If event parameter is collision timer //Set next state to driving //Set make transition to true //Consume event //else if case driving //Set return event to during driving //If event is a timeout //if event parameter is collision timer //Do nothing //Return timeout event //If make transition is true //Create exit event //Run collision on exit event //Set next state //Run entry event on collision void StartCollision (ES_Event_t CurrentEvent) //Set current state to entry state //Calculate rotate direction and set it //Rotate //Run collision static ES_Event_t DuringReversing(ES_Event_t Event) //If event is an entry or entry history event //Drive //Init collision timer //Else if exit event //Stop static ES_Event_t DuringRotating(ES_Event_t Event) //If event is an entry or entry history event //Rotate in rotation direction //Init collision timer //Else if exit event //Stop static ES_Event_t DuringDriving(ES_Event_t Event) //If event is an entry or entry history event //Drive //Init collision timer //Else if exit event //Stop static uint8_t CalcRotateDirection (uint8_t x, uint8_t y, uint16_t heading) //If heading is west //if x is zero //return right //else if x is 3 //return left //else if heading is east //if x is zero //return left //else if x is 3 //return right //else if heading is north //if y is zero //return left //else if y is 3 //return right //else if heading is south //if y is zero //return right //else if y is 3 //return left //return left