ME 405 Romi
Loading...
Searching...
No Matches
control_task.control_task Class Reference

This file contains a class to create a control_task object which is compatible with the cotask scheduler to run as a cooperative task. More...

Public Member Functions

 __init__ (self, fwd_ref, arc_ref, piv_ref, c_state, my_controller_left, my_controller_right, position_l, velocity_l, position_r, velocity_r, PWM_l, PWM_r, encoder_Right, encoder_Left, m_state_l, m_state_r, centroid, line_controller, automatic_mode, line_sensor, need_Calibrate, real_yaw, centroid_goal, yaw_goal, controller_yaw)

Public Attributes

 fwd_ref = fwd_ref
 arc_ref = arc_ref
 piv_ref = piv_ref
 c_state = c_state
 controller_left = my_controller_left
 controller_right = my_controller_right
 position_l = position_l
 velocity_l = velocity_l
 position_r = position_r
 velocity_r = velocity_r
 PWM_l = PWM_l
 PWM_r = PWM_r
int state = 0
 enc_R = encoder_Right
 enc_L = encoder_Left
 m_state_l = m_state_l
 m_state_r = m_state_r
 centroid = centroid
 line_controller = line_controller
 automatic_mode = automatic_mode
int yaw_rate = 0
 line_sensor = line_sensor
 need_Calibrate = need_Calibrate
 real_yaw = real_yaw
 centroid_goal = centroid_goal
 yaw_goal = yaw_goal
 controller_yaw = controller_yaw
int idx = 0
int startup = 0

Detailed Description

This file contains a class to create a control_task object which is compatible with the cotask scheduler to run as a cooperative task.

The active control_task object uses a finite state machine design to control the motion of the Pololu ROMI kit used in ME 405, Fall 2025. The task is given 4 PI controllers made in main that are linked to the left wheel, right wheel, the centroid of the line sensor, and the heading of the IMU sensor. Each state sets the appropriate set point of each controller according the expected motion of the bot.

Author
Alex Power, Lucas Heuchert, Erik Heuchert
ChatGPT5 was used for debugging purposes but not to generate this code
Date
2025-Nov-10 Approximate date of creation of file
2025-Dec-12 Final alterations made

control_task class that can be initialized to be run with the cotask scheduler. See run for behavior.

init is the control_task object initializer which takes 25 arguments. The arguments are a mix of controllers, data shares, and flag shares.

Parameters
fwd_ref: fwd_ref is an integer share that holds the expected forward reference speed of ROMI in mm.s. It is set by the UI task for testing purposes or by pathing plan task for course navigation.
arc_ref: arc_ref is an integer share that holds the expected turning arc of ROMI in mm of arc radius. It is set by the UI task for testing purposes.
piv_ref: piv_ref is a float share that holds the expected pivoting reference angular speed of ROMI in rad/s. It is set by the UI task for testing purposes or by pathing plan task for course navigation.
c_state: c_state is an integer share flag that holds the expected state of control_task. It is set by UI or pathing plan to tell control_task the expected motion of ROMI.
my_controller_left: my_controller_left is a controller object made in main that has gains for controlling the motion of the left wheel.
my_controller_rightmy_controller_right is a controller object made in main that has gains for controlling the motion of the right wheel.
position_lposition_l is a float share that the left motor and encoder class fills with the current left motor position.
velocity_lvelocity_l is a float share that the left motor and encoder class fills with the current left motor velocity.
position_rposition_r is a float share that the right motor and encoder class fills with the current right motor position.
velocity_rvelocity_r is a float share that the right motor and encoder class fills with the current right motor velocity.
PWM_l: PWM_l is a float share that control_task sets to a value -100 to 100 as the duty cycle of the left wheel's enable pin. The motor_encoder_left_class will use it.
PWM_r: PWM_r is a float share that control_task sets to a value -100 to 100 as the duty cycle of the right wheel's enable pin. The motor_encoder_right_class will use it.
encoder_Rightencoder_Right is an encoder object attached to the right encoder. It is used here to save an offset and zero the encoders for accurate observer behavior. It is also used to get the dt between runs for the integral sums in the motor controllers.
encoder_Left:encoder_Left is an encoder object attached to the left encoder. It is used here to save an offset and zero the encoders for accurate observer behavior. It is also used to get the dt between runs for the integral sums in the motor controllers.
m_state_l: m_state_l is an integer share flag used by control task to tell the left motor encoder class which state the left motor needs to be in.
m_state_r: m_state_r is an integer share flag used by control task to tell the right motor encoder class which state the right motor needs to be in.
centroid: centroid is a float share that the line sensor task fills with the current location of the line that ROMI is following. It is used for the automatic line following mode in control task.
line_controller: line_controller is a controller object made in main that has gains for changing the set point of the wheel controllers slightly to move the centroid of the line to a certain point.
automatic_mode: automatic_mode is an integer share flag that is set to tell control_task that it should start automatically following a line. It is set by UI for testing or pathing plan for course navigation.
line_sensor: line_sensor is the line_sensor object made in main. It is not used in control task's current implementation but was used before for debugging the line following.
need_Calibrate: need_Calibrate is an integer share flag that tells control task whether the IR sensors are calibrated and control task is ok to start line following. It is set by the line sensor task.
real_yaw: real_yaw is a float share that the IMU task fills with the current yaw of ROMI. control_task uses it for heading control.
centroid_goalcentroid_goal is a float share that the pathing plan task sets. It is then used as the line following centroid controller set point.
yaw_goal: yaw_goal is a float share that is the set point of the heading control. It is the angle ROMI should turn to on the course and is set by pathing plan for course navigation.
controller_yaw: controller_yaw is a controller object made in main. It looks at the current yaw of ROMI to get new wheel speeds for pivoting towards the yaw_goal. It is set by the pathing plan for course navigation.

Definition at line 17 of file control_task.py.

Constructor & Destructor Documentation

◆ __init__()

control_task.control_task.__init__ ( self,
fwd_ref,
arc_ref,
piv_ref,
c_state,
my_controller_left,
my_controller_right,
position_l,
velocity_l,
position_r,
velocity_r,
PWM_l,
PWM_r,
encoder_Right,
encoder_Left,
m_state_l,
m_state_r,
centroid,
line_controller,
automatic_mode,
line_sensor,
need_Calibrate,
real_yaw,
centroid_goal,
yaw_goal,
controller_yaw )

Definition at line 19 of file control_task.py.

Member Data Documentation

◆ arc_ref

control_task.control_task.arc_ref = arc_ref

Definition at line 23 of file control_task.py.

◆ automatic_mode

control_task.control_task.automatic_mode = automatic_mode

Definition at line 41 of file control_task.py.

◆ c_state

control_task.control_task.c_state = c_state

Definition at line 25 of file control_task.py.

◆ centroid

control_task.control_task.centroid = centroid

Definition at line 39 of file control_task.py.

◆ centroid_goal

control_task.control_task.centroid_goal = centroid_goal

Definition at line 47 of file control_task.py.

◆ controller_left

control_task.control_task.controller_left = my_controller_left

Definition at line 26 of file control_task.py.

◆ controller_right

control_task.control_task.controller_right = my_controller_right

Definition at line 27 of file control_task.py.

◆ controller_yaw

control_task.control_task.controller_yaw = controller_yaw

Definition at line 49 of file control_task.py.

◆ enc_L

control_task.control_task.enc_L = encoder_Left

Definition at line 36 of file control_task.py.

◆ enc_R

control_task.control_task.enc_R = encoder_Right

Definition at line 35 of file control_task.py.

◆ fwd_ref

control_task.control_task.fwd_ref = fwd_ref

Definition at line 22 of file control_task.py.

◆ idx

int control_task.control_task.idx = 0

Definition at line 50 of file control_task.py.

◆ line_controller

control_task.control_task.line_controller = line_controller

Definition at line 40 of file control_task.py.

◆ line_sensor

control_task.control_task.line_sensor = line_sensor

Definition at line 44 of file control_task.py.

◆ m_state_l

control_task.control_task.m_state_l = m_state_l

Definition at line 37 of file control_task.py.

◆ m_state_r

control_task.control_task.m_state_r = m_state_r

Definition at line 38 of file control_task.py.

◆ need_Calibrate

control_task.control_task.need_Calibrate = need_Calibrate

Definition at line 45 of file control_task.py.

◆ piv_ref

control_task.control_task.piv_ref = piv_ref

Definition at line 24 of file control_task.py.

◆ position_l

control_task.control_task.position_l = position_l

Definition at line 28 of file control_task.py.

◆ position_r

control_task.control_task.position_r = position_r

Definition at line 30 of file control_task.py.

◆ PWM_l

control_task.control_task.PWM_l = PWM_l

Definition at line 32 of file control_task.py.

◆ PWM_r

control_task.control_task.PWM_r = PWM_r

Definition at line 33 of file control_task.py.

◆ real_yaw

control_task.control_task.real_yaw = real_yaw

Definition at line 46 of file control_task.py.

◆ startup

int control_task.control_task.startup = 0

Definition at line 51 of file control_task.py.

◆ state

int control_task.control_task.state = 0

Definition at line 34 of file control_task.py.

◆ velocity_l

control_task.control_task.velocity_l = velocity_l

Definition at line 29 of file control_task.py.

◆ velocity_r

control_task.control_task.velocity_r = velocity_r

Definition at line 31 of file control_task.py.

◆ yaw_goal

control_task.control_task.yaw_goal = yaw_goal

Definition at line 48 of file control_task.py.

◆ yaw_rate

int control_task.control_task.yaw_rate = 0

Definition at line 42 of file control_task.py.


The documentation for this class was generated from the following file: