99 def __init__(self, total_dist, automatic_mode, c_state, fwd_ref, piv_ref, yaw, centroid_goal, yaw_goal, bump_on, bump_flg):
101 @brief Initialize the pathing_plan_task object
103 @param total_dist Float share containing total distance traveled by ROMI (set by observer)
104 @param automatic_mode Integer share flag to enable automatic line following mode
105 @param c_state Integer share flag holding the expected state of control_task
106 @param fwd_ref Integer share holding forward reference speed in mm/s
107 @param piv_ref Float share holding pivoting reference angular speed in rad/s
108 @param yaw Float share containing current yaw from IMU task
109 @param centroid_goal Float share for line following centroid controller set point
110 @param yaw_goal Float share for heading control set point (target angle)
111 @param bump_on Integer share flag to turn on bump sensors
112 @param bump_flg Integer share flag set by bump task when sensors are triggered
128 self.
yaw_goals_5 = [YAWGOAL5, EXPYAWGOAL1, EXPYAWGOAL2, EXPYAWGOAL3]
130 self.
dist = [CP4_GARAGE, 3600, 3800, 4000]
230 @brief Main task generator for cooperative scheduler
232 Implements a 34-state finite state machine for autonomous course navigation.
233 Each state executes once in sequence and never returns. The generator yields
234 control after processing each state.
236 @details State sequence overview:
238 States execute in the following order: LINE_FOLLOW_STATE_0, CENTROID_OFFSET_STATE,
239 ALIGNMENT_GOAL_1, ALIGNMENT_CONTROL_1, FORK, ALIGNMENT_GOAL_2, ALIGNMENT_CONTROL_2,
240 FREE_TRAVERSE_1, CP2_PIVOT_1, CP2_PIVOT_2, LINE_FOLLOWING_2, ALIGNMENT_GOAL_3,
241 ALIGNMENT_CONTROL_3, FREE_TRAVERSE_2, LINE_FOLLOW_3, ALIGNMENT_GOAL_4,
242 ALIGNMENT_CONTROL_4, FREE_TRAVERSE_3, LINE_FOLLOW_GRG, ALIGNMENT_GOAL_5,
243 ALIGNMENT_CONTROL_5, FREE_TRAVERSE_4, ALIGNMENT_GOAL_6, ALIGNMENT_CONTROL_6,
244 FREE_TRAVERSE_5, WALL, ALIGNMENT_GOAL_7, ALIGNMENT_CONTROL_7, CUP, ALIGNMENT_GOAL_8,
245 ALIGNMENT_CONTROL_8, FINISH, FINISH_LINE
247 Path overview: Start line following to the Y, move the centroid to the left to keep right,
248 face CP1, drive directly there, face CP2, drive directly there, line follow briefly,
249 turn to CP3, drive there pushing cup out of the way, turn to CP4, drive there and line
250 follow at the end to align, align at garage entrance, drive through, turn towards wall,
251 drive out, hit wall and backup, turn towards cup, drive over it, turn towards finish,
252 drive back to the line, use line following to get into CP6.
254 @note Alignments use two-stage process: goal state for large turns at set speeds,
255 then control state for precise alignment using controller
256 @note Yaw drift is inconsistent making the path unreliable - do not run unsupervised
258 @return Yields state number after each iteration
267 print(f
"Yaw Offset : {self.yaw_init}")
269 if self.
state == LINE_FOLLOW_STATE_0:
272 print(
"Going to CENTROID OFFSET STATE")
275 elif self.
state == CENTROID_OFFSET_STATE:
280 print(
"Going to ALIGNMENT GOAL 1")
283 self.
state = ALIGNMENT_GOAL_1
286 elif self.
state == ALIGNMENT_GOAL_1:
289 print(
"Going to ALIGNMENT CONTROL 1")
290 yield ALIGNMENT_GOAL_1
293 elif self.
state == ALIGNMENT_CONTROL_1:
296 print(
"Going to FORK")
297 yield ALIGNMENT_CONTROL_1
299 elif self.
state == FORK:
302 print(
"Going to ALIGNMENT GOAL 2")
309 elif self.
state == ALIGNMENT_GOAL_2:
312 print(
"Going to ALIGNMENT CONTROL 2")
313 yield ALIGNMENT_GOAL_2
315 elif self.
state == ALIGNMENT_CONTROL_2:
318 print(
"Going to FREE_TRAVERSE_1")
319 yield ALIGNMENT_CONTROL_2
321 elif self.
state == FREE_TRAVERSE_1:
324 print(
"Going to CP2_PIVOT_1")
325 yield FREE_TRAVERSE_1
327 elif self.
state == CP2_PIVOT_1:
330 print(
"Going to CP2_PIVOT_2")
333 elif self.
state == CP2_PIVOT_2:
336 print(
"Going to LINE_FOLLOWING_2")
339 elif self.
state == LINE_FOLLOWING_2:
342 print(
"Going to ALIGNMENT GOAL 3 / START OF FUNCTION TESTS")
344 self.
state = ALIGNMENT_GOAL_3
345 yield LINE_FOLLOWING_2
351 elif self.
state == ALIGNMENT_GOAL_3:
354 print(
"Going to ALIGNMENT CONTROL 3")
355 yield ALIGNMENT_GOAL_3
357 elif self.
state == ALIGNMENT_CONTROL_3:
360 print(
"Going to FREE_TRAVERSE_2")
361 yield ALIGNMENT_CONTROL_3
363 elif self.
state == FREE_TRAVERSE_2:
366 print(
"Going to ALIGNMENT_GOAL_4")
367 yield FREE_TRAVERSE_2
369 elif self.
state == LINE_FOLLOW_3:
371 print(
"Going to ALIGNMENT GOAL 4")
378 elif self.
state == ALIGNMENT_GOAL_4:
381 print(
"Going to ALIGNMENT CONTROL 4")
382 yield ALIGNMENT_GOAL_3
384 elif self.
state == ALIGNMENT_CONTROL_4:
387 print(
"Going to FREE_TRAVERSE_3")
388 yield ALIGNMENT_CONTROL_4
390 elif self.
state == FREE_TRAVERSE_3:
393 print(
"Going to LINE_FOLLOW_GRG")
394 yield FREE_TRAVERSE_3
396 elif self.
state == LINE_FOLLOW_GRG:
399 print(
"Going to ALIGNMENT GOAL 5")
400 yield LINE_FOLLOW_GRG
406 elif self.
state == ALIGNMENT_GOAL_5:
409 print(
"Going to Alignment Control 5")
410 yield ALIGNMENT_GOAL_5
412 elif self.
state == ALIGNMENT_CONTROL_5:
415 print(
"Going to FREE_TRAVERSE_4")
416 yield ALIGNMENT_CONTROL_5
418 elif self.
state == FREE_TRAVERSE_4:
421 print(
"Going to ALIGNMENT GOAL 5")
422 print(f
"Total Dist: {self.total_dist.get()}")
423 yield FREE_TRAVERSE_4
425 elif self.
state == ALIGNMENT_GOAL_6:
428 print(
"Going to ALIGNMENT CONTROL 6")
429 yield ALIGNMENT_GOAL_6
431 elif self.
state == ALIGNMENT_CONTROL_6:
434 print(
"Going to FREE_TRAVERSE_5")
435 yield ALIGNMENT_CONTROL_6
437 elif self.
state == FREE_TRAVERSE_5:
440 print(
"Going to WALL")
441 yield FREE_TRAVERSE_5
446 elif self.
state == WALL:
453 print(
"Bump flag on")
458 self.
state = ALIGNMENT_GOAL_7
464 print(f
"Total dist: {self.total_dist.get()}")
467 elif self.
state == ALIGNMENT_GOAL_7:
470 print(
"Going to ALIGNMENT CONTROL 7")
471 yield ALIGNMENT_GOAL_7
473 elif self.
state == ALIGNMENT_CONTROL_7:
476 print(
"Going to CUP")
477 yield ALIGNMENT_CONTROL_7
479 elif self.
state == CUP:
482 print(
"Going to ALIGNMENT GOAL 8")
485 elif self.
state == ALIGNMENT_GOAL_8:
488 print(
"Going to ALIGNMENT CONTROL 8")
489 yield ALIGNMENT_GOAL_8
491 elif self.
state == ALIGNMENT_CONTROL_8:
494 print(
"Going to FINISH")
495 yield ALIGNMENT_CONTROL_8
497 elif self.
state == FINISH:
500 print(
"Going to STOP")
503 elif self.
state == FINISH_LINE:
508 elif self.
state == STOP:
513 elif self.
state == 40:
518 raise ValueError(
"Not that many states")