/**************************************************************************** Module T_Transporting.c Private Definitions CurrentState desCol currCol desRow currRow prevDesRow prevDesCol reposition xcoordinate ycoordinate ES_Event_t RunTransportingSM(ES_Event_t CurrentEvent)------------------------- // default to normal entry to new state // based on our current state: // if current state is AlignNS // Execute During function for AlignNS // process any events // if we are done rotating // if aligned NS, set next state to AlignEW // else set next state to DroppingOff // consume eventcase // if HEADING_WAIT_TIMER times out // get current heading // calculate desired heading change depending on desired and current column // adjust for direction to prevent turning more than 180 degrees // Rotate if heading is more than 15 degrees off // Otherwise skip the rotating and post rotate done // if current sate is AlignEW // Execute During function for AlignEW //process any events // if we are done rotating // mark that we are taking a transition // set NextState to DroppingOff // consume this event for the upper state machines // if HEADING_WAIT_TIMER times out // get current heading // calculate desired heading change depending on desired and current column // adjust for direction to prevent turning more than 180 degrees // Rotate if heading is more than 15 degrees off // Otherwise skip the rotating and post rotate done // if current state is DroppingOff // Execute During function for DroppingOff State. // process any events // if we entered new tile move to Centering state // if we are driving along white for a while, make a 90 degree turn // mark that we are taking a transition // set next state to GettingBack state // if current state is GettingBack // Execute During function for GettingBack State. // process any events // if DROP_OFF_TIMER times out // consume this event for the upper state machines // if we are done rotating // mark that we are taking a transition // set next state to DroppingOff state // if current state is Centering // Execute During function for Centering State. // process any events // if DROP_OFF_TIMER times out // if current column is not desired column // mark that we are taking a transition // set next state to AlignNS // consume this event for the upper state machines // if current column equals desired column and current row does not equal the desired row // mark that we are taking a transition // set next state to AlignEW // consume this event for the upper state machines // if current column and row equals the desired column and row, and reposition is false // mark that we are making a transition // set next state to LiftingGate // consume this event for the upper state machines // if current column and row equals the desired column and row, and reposition is true // remap this event for the upper state machines as CENTERING_TO_SEARCHING // if current state is LiftingGate // Execute During function for LiftingGate State. // process any events // if SERVO_TIMER times out // mark that we are making a transition // set next state to Reversing // consume this event for the upper state machines // if current state is LiftingGate // Execute During function for LiftingGate State. // process any events // if REVERSE_TIMER times out, do nothing // if we are making a state transition // Execute exit function for current state // Modify state variable // Execute entry function for new state void StartTransportingSM (ES_Event_t CurrentEvent)-------------------------------------- // set current state to AlignNS // call the entry function (if any) for the ENTRY_STATE // if reposition is true, set desired position to (2,2) for generic repositioning // otherwise, set the desired position to the nearest unoccupied mining region TransportingState QueryTransportingSM (void)------------------------------------------- // return CurrentState variable return(CurrentState); void updateCurrPos(void)--------------------------------------------------------------- // set currCol and currRow based on querying the values from the color service void SetReposition(bool cmd)------------------------------------------------------------ // set reposition to the cmd value passed in static ES_Event_t DuringAlignNS(ES_Event_t Event)--------------------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY // init HEADING_WAIT_TIMER // process ES_EXIT event // none // process other events // none static ES_Event_t DuringAlignEW(ES_Event_t Event)--------------------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY // init HEADING_WAIT_TIMER // process ES_EXIT event // none // process other events // none static ES_Event_t DuringDroppingOff(ES_Event_t Event)----------------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY // Drive forward // if we are already at the desired location, post a NEW_COLOR event // process ES_EXIT event // init the DROP_OFF_TIMER // process other events // none static ES_Event_t DuringCentering(ES_Event_t Event)------------------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY // Recalculate current position // set desired position to the nearest mining region // process ES_EXIT event // stop driving // process other events // none static ES_Event_t DuringLiftingGate(ES_Event_t Event)----------------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY // Move servo // Init SERVO_TIMER // process ES_EXIT event // stop driving // process other events // none static ES_Event_t DuringReversing(ES_Event_t Event)------------------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY // Drive in reverse // Init REVERSE_TIMER // process ES_EXIT event // stop driving // process other events // none static void setDesPosToNearestMiningRegion(void)--------------------------------------- // calc distances to mining locations that don't have a miner there already // query regions from spud HSM // neutral region 1 stored in bits 0-3 of PUR2 // neutral region 1 stored in bits 4-7 of PUR2 // if the team is CKH, company region is stored in bits 0-3 in PUR1 register // otherwise GHI, company region 2 stored in bits 4-7 // set up array for iterating through the three regions // dummy initialization values for nearestRegion and minDist -- should be overwritten during for loop // iterate through locations array to find closest option without a miner already theres // set desired column and row based on results of for loop bool IsTileOccupied(uint8_t tile)------------------------------------------------------ // get my own location as 0-indexed tile // iterate through the four miners // grab register contents from SPUD // get the Location Good value (bit 7) // mask out the 4 MSB (location is stored in bits 0-3) // if miner has valid location and miner and robot are not in same tile, change return true // if none of the miners were in the tile, return false