quadrature-encoder-course/lessons/02-using-encoder-feedback/02-closing-the-loop-with-a-pid/closing-the-loop-with-a-pid.md

34 lines
919 B
Markdown

---
title: Closing the Loop with a PID
summary: Use encoder speed feedback to hold a target wheel speed with a simple controller.
chapter: Using Encoder Feedback
order: 2
tags:
- control
- pid
- robotics
estimated_minutes: 12
---
# Closing the Loop with a PID
With encoder speed feedback in place, you can command a target speed and adjust motor output based on error.
The basic control loop is:
- measure current speed
- compute `error = target - measured`
- update the controller
- send the new motor command
Start simple. A proportional controller is often enough to prove the loop works before adding integral or derivative terms.
## What good behavior looks like
- the wheel reaches the target speed quickly
- overshoot stays limited
- the response remains stable when load changes
## Checkpoint
Tune a controller so the wheel returns to the target speed after you briefly drag on the tire by hand.