Main Program¶
Summary¶
This file is the integration point for the entire ROMI project. It configures the hardware timers, creates the motor, encoder, bumper, and line-sensing objects, allocates all shared variables and queues, constructs each task, and starts the cooperative scheduler.
System setup¶
The program disables the UART REPL, enables automatic start by default, and creates one PWM timer for the motors plus two encoder timers for the left and right wheels. It then creates the two motor-driver objects, two encoder objects, and one front bumper-switch object.
Important objects¶
leftMotor/rightMotorInstances of
motor_driverused to command the left and right wheels.leftEncoder/rightEncoderInstances of
encoderused to measure wheel position and velocity.front_bumperInstance of
BumperSwitchused to detect a front bumper hit.
Interrupt behavior¶
The front bumper is connected to an interrupt service routine named
_front_bump_irq(). When the bumper is pressed, the ISR sets both the
bump_event share and the bump_state share so the task layer can react
without polling the pin directly.
Task creation¶
The main program constructs the following tasks:
leftMotorTask/rightMotorTaskClosed-loop wheel-speed tasks for the left and right motors.
lineSensorTaskTask that reads the QTR array and publishes the line centroid.
lineFollowTaskTask that converts centroid error into left and right wheel setpoints.
bumpTaskTask that translates a bumper event into a stop request.
courseTaskHigh-level supervisory task that runs the checkpoint sequence.
userTaskUSB serial command interface used to start, stop, and test segments.
Scheduler configuration¶
The task list is configured so that:
left and right motor tasks run every 20 ms at priority 2
line sensor and line-follow tasks run every 10 ms at priority 3
bump task runs every 10 ms at priority 4
course task runs every 20 ms at priority 4
user task runs at priority 1 with no fixed period
Program flow¶
After all objects are created, the garbage collector is run once and the
program enters an infinite loop which repeatedly calls task_list.pri_sched().
If a keyboard interrupt occurs, both motors are disabled and the program exits
the scheduler loop cleanly.