Course Supervisor Task¶
Summary¶
This task is the top-level finite-state machine for the ROMI time-trial run. It decides when the robot should line-follow, when it should drive open-loop, when it should stop, and how the robot transitions between checkpoint segments, garage contact handling, recovery, and the return-home behavior.
Important class¶
task_course(auto_start, course_mode, stop_request, bump_mode, left_go, right_go, line_enable, line_mode, base_speed, setpoint_L, setpoint_R, left_pos, right_pos, centroid_share, line_seen_share, line_enable_share)Generator-based supervisory state machine that coordinates the whole course.
Important helper methods¶
_avg_dist()Computes the average of the left and right wheel positions.
_reset_segment()Resets the segment start distance and segment start time.
_seg_dist()Returns distance traveled within the current segment.
_seg_time()Returns elapsed time within the current segment.
_manual_drive(left_mps, right_mps)Disables line following and directly commands the wheel setpoints.
_line_drive(speed_mps)Enables line following and sets the desired base speed.
_stop()Disables motion and zeroes wheel setpoints.
_finish_segment_or_continue(next_state)Either advances to the next full-course state or stops if the robot is only running a segment test.
_start_mode(mode)Starts the correct state based on the selected course mode.
Important state constants¶
S0_INITInitial setup state.
S1_WAIT_STARTWaits for
auto_startto become true.S2_CP0_TO_CP1First segment, including line following and some scripted maneuvers.
S3_GARAGE_CONTACTDrives into the garage/contact segment and waits for a bumper-triggered stop.
S4_GARAGE_RECOVERRecovery state that searches for the line again.
S5_CP2_TO_CP3Intermediate line-following segment after recovery.
S6_CP3_TO_CP4Another timed line-following segment.
S7_RETURN_HOMEFinal open-loop return maneuver.
S8_DONEFinal stopped state.
S9_BUMP_RECOVERYEmergency bump-recovery state used outside the garage-contact sequence.
Important mode constants¶
MODE_IDLENo automatic motion.
MODE_FULLRun the full multi-segment course.
MODE_SEG_CP0_CP1Test only the first segment.
MODE_SEG_GARAGE_CONTACTTest the garage-contact segment.
MODE_SEG_GARAGE_RECOVERTest the recovery segment.
MODE_SEG_CP2_CP3Test the mid-course line-follow segment.
MODE_SEG_CP3_CP4Test the later line-follow segment.
MODE_SEG_RETURNTest the return-home segment.
Important variables¶
self._auto_startShare that begins the selected course run.
self._course_modeShare that selects full-course or segment-test behavior.
self._stop_requestShare that signals a stop or recovery condition.
self._bump_modeShare containing interpreted bumper status.
self._left_go/self._right_goShares controlling the left and right motor tasks.
self._line_enable/self._line_modeShares controlling the line follower and line-sensor task behavior.
self._base_speedShare holding the desired line-follow base speed.
self._spL/self._spRWheel setpoint shares.
self._left_pos/self._right_posWheel position shares used to measure segment distance.
self._centroidShared line-centroid estimate.
self._line_seenShared flag indicating whether the line is currently detected.
self._state_start_usTimestamp marking the start of the current state.
self._segment_start_distReference distance used to compute how far the robot has traveled in the current segment.
self._recover_turn_speedStored recovery-speed parameter for recovery maneuvers.
self._recover_start_usTimestamp used during recovery behavior.
State-machine behavior¶
The task begins in a stopped state, waits for auto_start, and then launches
either the full course or one selected segment test. The code mixes line
following with short open-loop maneuvers.
Some key hard-coded transition conditions include:
first segment thresholds near
0.63,0.80,0.82, and0.90mfirst-segment completion when
left_pos >= 1.011line-follow transition after roughly
7.0s inS5_CP2_TO_CP3later segment transition after roughly
21.0s inS6_CP3_TO_CP4return-home completion after roughly
1.5semergency bump-recovery backup duration of roughly
0.25s
Role in the project¶
This module is the highest-level behavior controller in the project. It decides which lower-level task should currently dominate: pure line following, manual open-loop wheel commands, bumper handling, or final stop behavior.