control_task¶
- class control_task.ControlTask(gains, offset)¶
Bases:
object
A class to implement a PID controller for motor speed adjustments.
- k_p¶
Proportional gain.
- Type:
float
- k_i¶
Integral gain.
- Type:
float
- k_d¶
Derivative gain (not used in this version).
- Type:
float
- offset¶
Offset value for control adjustments.
- Type:
int
- integral¶
Accumulated integral term for PID control.
- Type:
float
- prev_error¶
Previous error value for integral calculation.
- Type:
float
- now¶
Current timestamp (milliseconds).
- Type:
int
- prev_time¶
Previous timestamp (milliseconds).
- Type:
int
- del_time¶
Time difference between control updates.
- Type:
int
- base_speed¶
Base speed for each motor.
- Type:
int
- speed¶
Speed used for control commands that can be positive or negative.
- Type:
int
- left_output¶
Output speed for left motor.
- Type:
int
- right_output¶
Output speed for right motor.
- Type:
int
- controller(shares)¶
Implements the PID control loop.
State 0: Initializes the system and moves to PID state. State 1: Reads the error, applies PID corrections, and updates motor speeds.
- Parameters:
shares (list[line_error, right_speed, left_speed, line_heading, heading, heading_set]) – Shared variables for error, right motor speed, and left motor speed.
- Yields:
state (int) – The current FSM state.