Feedback controllers and motion control algorithms for e-Yantra robotics projects.
PID Controller
The PID controller is the most commonly used feedback controller in robotics.
| Term | Symbol | Role |
|---|---|---|
| Proportional | Reacts to current error | |
| Integral | Eliminates steady-state error | |
| Derivative | Dampens oscillation |
python
class PIDController:
def __init__(self, kp, ki, kd, dt=0.01):
self.kp, self.ki, self.kd = kp, ki, kd
self.dt = dt
self.prev_error = 0.0
self.integral = 0.0
def compute(self, setpoint, measurement):
error = setpoint - measurement
self.integral += error * self.dt
derivative = (error - self.prev_error) / self.dt
self.prev_error = error
return self.kp * error + self.ki * self.integral + self.kd * derivativeDifferential Drive Kinematics
python
def diff_drive_velocities(v, omega, wheel_base):
v_r = v + (omega * wheel_base / 2)
v_l = v - (omega * wheel_base / 2)
return v_r, v_lPID Tuning Guide
WARNING
Always tune PID in a safe, open environment. Start with all gains at zero.
| Step | Action |
|---|---|
| 1 | Set , . Increase until oscillation. |
| 2 | Reduce to ~60% of the oscillation value. |
| 3 | Add gradually to reduce overshoot. |
| 4 | Add slowly to remove steady-state error. |