RunFree4AllSM If current state is Going2Stage_4all Execute During function for Going2Stage. If an event is active If event is event increment stage Increment stage counter if target stage reached post target stage reached event If event is event decrement stage Decrement stage counter if target stage reached post target stage reached event If event is event get target stage if CowsOnRobot is less than maximum set target stage to Loading Depot else set target stage as 1 endif if current stage > target stage Drive forward Post set target stage event with direction as param if current stage < target stage Drive reverse Post set target stage event with direction as param else Post Target Stage Reached event If event is event StageReached Next State is Shooting4All Mark that we are taking a transition Consume event If event is event DepotReached Update current stage to loading depot if current stage = target Stage Next State is Loading4All Mark that we are taking a transition Consume event else Next State is Going2Stage4All Mark that we are taking a transition Consume event Next State is Shooting4All Mark that we are taking a transition Consume event Else Return CurrentEvent If current state is Shooting_4all Execute During function for Shooting. If an event is active If event is event ShotCOW Decrement CowsOnRobot counter Consume event If event is event ShootingDone Next State is Going2Stage4All Mark that we are taking a transition Consume event Else Return CurrentEvent If current state is Loading Execute During function for Loading. If an event is active If event is event LoadedCOW Increment COWs on Robot if CowsOnRobot < 5 Next State is Loading4All Mark that we are taking a transition Consume event else Next State is Going2Stage4All Mark that we are taking a transition Consume event If event is Indicator pulse timeout Toggle indicator LED DuringStateGoing2Stage on Entry Post navigating event to hall service Enable wire following ISR Run Going2StageSM On Exit Run Going2StageSM Stop drivetrain Disable wireFollowingISR else Run Going2Stage DuringStateShooting On Entry Start shootingSM On Exit Run shootingSM else RunShootingSM DuringStateLoading On Entry Toggle indicator LED Start LoadingSM On Exit Run LoadingSM else Run LoadingSM Decrement CowsOnRobot counter Consume event If event is event ShootingDone Next State is Going2Stage4All Mark that we are taking a transition Consume event Else Return CurrentEvent