# Controller Design An agnostic PID controller class is used so It can be applied to a variety of inputs and outputs. This controller is primarily used to set effort values for each motor based on error. This error is either positional error dictated by the offset from the IR sensor centroid, or angular position error based on IMU heading angles. The documented low-level controller class can be found [here](controller.md).
![PID Controller diagram](./image/MotorControlBlockDiagram.png) --- Our motor controller task in [main](main.md) implements a cascading control scheme, where the IR sensor position is regulated by the outer loop, which in turn adjusts the motor effort through the inner loop. This design enhances stability by ensuring that more accurate setpoints lead to less sensitivity to variations in system dynamics. To achieve this, we first tuned the inner motor controllers to reliably track the line position. Once the inner loop was stable, we tuned the outer IR sensor controller to further refine and smooth the system’s response. ![Cascading control diagram](./image/IR_Control_diagram.png)