-
Notifications
You must be signed in to change notification settings - Fork 0
Control System
The Auto-Aiming System employs a discrete PID (Proportional-Integral-Derivative) controller implemented on the ESP32 microcontroller to achieve precise and dynamic control of the pan-tilt mechanism. The PID controller is responsible for calculating servo adjustments based on the error between the target's position (centroid) and the center of the camera's field of view.
The core of the PID control is encapsulated in the method calculateControl
, which computes the control output using the following principles:
-
Proportional Control (P): Directly proportional to the error, providing immediate correction.
$$u_p = k_p \cdot \text{error}$$ -
Integral Control (I): Accumulates past errors to address steady-state offset.
$$u_i = \text{prev}_{\text{ui}} + k_p \cdot k_i \cdot \text{prev-ui}$$ -
Derivative Control (D): Predicts future trends by considering the rate of change in error.
$$u_d = k_p \cdot k_d \cdot (\text{error} - \text{prev-error})$$ -
Scaled Output (S): A scaling factor ( k_s ) adjusts the overall control output.
$$u = k_s \cdot (u_p + u_i + u_d)$$
The combined output is then used to adjust the servo positions, minimizing the error in subsequent iterations.
Below is a detailed explanation of the key components of the PID controller:
-
calculateControl
:
This function receives the current error as input, computes the proportional, integral, and derivative terms, and scales the total output before returning it to the servo control logic. The state variablesprev_error
andprev_ui
are updated for the next iteration. -
reset
:
Resets the internal state of the controller, clearing accumulated integral values and the last error. This is particularly useful when initializing the system or recovering from disturbances. -
Parameter Update Functions:
updateKp(double kp)
updateKi(double ki)
updateKd(double kd)
-
updateKs(double ks)
These functions allow runtime adjustment of the PID gains and the scaling factor, providing flexibility to fine-tune the control system for optimal performance.
The PID controller's modular design ensures that it is reusable and easily configurable. It logs all updates and resets using the ESP-IDF logging library, ensuring traceability during debugging and testing. Each parameter can be adjusted dynamically, allowing real-time experimentation without recompilation.
- The Raspberry Pi calculates the positional error based on the target's centroid.
- The error is transmitted to the ESP32 via I2C.
- The ESP32’s PID controller processes the error to compute servo adjustments.
- The servos move the pan-tilt mechanism, aiming the camera to center the target.
By leveraging the PID controller, the system achieves smooth and responsive movements, maintaining consistent tracking accuracy even under dynamic conditions.