Line Sensor Task¶
Summary¶
This task reads the QTR line-sensor driver, computes the line centroid, updates shared state for the rest of the control system, and optionally logs centroid data over USB serial and into queues.
Important class¶
task_line_sensor(goFlag, centroid_share, centroidQ, timeQ, line_seen_share, oversample=4)Periodic sensing task that wraps the
QTRMD07A_Analogdriver and exports processed line information to the rest of the robot.
Important methods¶
run()Generator-based task loop. It reads normalized sensor values, computes the centroid, updates the
line_seenflag, and optionally logs time-stamped centroid data.
Important state constants¶
S0_INITInitialization state.
S1_RUNMain sensing and logging state.
Important variables¶
self._goFlagShare controlling task behavior. In this file, mode
1enables time-stamped logging while other modes simply keep the centroid updated.self._centroid_shareShare that publishes the most recent centroid estimate.
self._centroidQ/self._timeQQueues used to store logged centroid samples and timestamps.
self._line_seenShare that indicates whether the line is currently detected.
self._serUSB serial interface used to stream logged centroid data.
self._printed_headerFlag used to print the CSV header only once per logging run.
self._qtrInstance of
QTRMD07A_Analogused to acquire sensor data.self._startTimeStart timestamp for relative time logging.
Behavior notes¶
Each run computes normalized sensor values n and centroid c, then
updates line_seen according to whether max(n) > 0.40. When logging is
enabled, the task outputs CSV-style text with the header t_us,centroid and
stores matching samples in the centroid queues.