From 032ef0a15b6dbc2684f6a4c56d4026f7d2e75e3b Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 7 Apr 2026 19:47:37 -0400 Subject: [PATCH] Add quadrature encoder starter course --- README.md | 9 +++++ .../meet-the-quadrature-encoder.md | 32 +++++++++++++++++ .../counting-direction-and-steps.md | 33 ++++++++++++++++++ .../measuring-wheel-speed.md | 32 +++++++++++++++++ .../closing-the-loop-with-a-pid.md | 34 +++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 README.md create mode 100644 lessons/01-reading-encoder-signals/01-meet-the-quadrature-encoder/meet-the-quadrature-encoder.md create mode 100644 lessons/01-reading-encoder-signals/02-counting-direction-and-steps/counting-direction-and-steps.md create mode 100644 lessons/02-using-encoder-feedback/01-measuring-wheel-speed/measuring-wheel-speed.md create mode 100644 lessons/02-using-encoder-feedback/02-closing-the-loop-with-a-pid/closing-the-loop-with-a-pid.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..2add2df --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Quadrature Encoder Course + +This sample course repo is for the Robot U prototype. + +It is intentionally small and follows the course structure the site expects: + +- `lessons///.md` + +The course walks from raw encoder signals to closed-loop motor control. diff --git a/lessons/01-reading-encoder-signals/01-meet-the-quadrature-encoder/meet-the-quadrature-encoder.md b/lessons/01-reading-encoder-signals/01-meet-the-quadrature-encoder/meet-the-quadrature-encoder.md new file mode 100644 index 0000000..b5cd3d5 --- /dev/null +++ b/lessons/01-reading-encoder-signals/01-meet-the-quadrature-encoder/meet-the-quadrature-encoder.md @@ -0,0 +1,32 @@ +--- +title: Meet the Quadrature Encoder +summary: Learn what the A and B channels are and why their phase offset lets you count motion. +chapter: Reading Encoder Signals +order: 1 +tags: + - encoders + - motors + - feedback +estimated_minutes: 8 +--- + +# Meet the Quadrature Encoder + +A quadrature encoder gives you two square-wave signals, usually called `A` and `B`. + +Those signals toggle as the shaft turns. The important detail is that they do not toggle at the same time. One channel leads the other by a quarter of a cycle, which is where the name quadrature comes from. + +That phase offset gives you two useful facts: + +1. You can count edges to measure motion. +2. You can compare which signal leads to determine direction. + +## What you should observe + +- Slow rotation produces clean transitions you can inspect with a logic analyzer. +- Reversing the shaft swaps which channel leads. +- More pulses per revolution means finer position measurement. + +## Checkpoint + +Capture both channels while rotating the shaft by hand and confirm that one channel leads the other. diff --git a/lessons/01-reading-encoder-signals/02-counting-direction-and-steps/counting-direction-and-steps.md b/lessons/01-reading-encoder-signals/02-counting-direction-and-steps/counting-direction-and-steps.md new file mode 100644 index 0000000..cbc75f6 --- /dev/null +++ b/lessons/01-reading-encoder-signals/02-counting-direction-and-steps/counting-direction-and-steps.md @@ -0,0 +1,33 @@ +--- +title: Counting Direction and Steps +summary: Decode edges from the A and B channels to recover step count and direction. +chapter: Reading Encoder Signals +order: 2 +tags: + - decoding + - interrupts + - firmware +estimated_minutes: 10 +--- + +# Counting Direction and Steps + +Once you can read the A and B channels, the next job is decoding. + +The most common approach is: + +- trigger on an edge +- read both channels +- use a lookup table or state machine to update the count + +If your decoder sees illegal state jumps, you are probably dropping edges or reading a noisy signal. + +## Practical notes + +- Start with low shaft speed. +- Add debounce or filtering only if the hardware needs it. +- Test forward and reverse explicitly. + +## Checkpoint + +Write firmware that increments a counter when the shaft turns forward and decrements when it turns backward. diff --git a/lessons/02-using-encoder-feedback/01-measuring-wheel-speed/measuring-wheel-speed.md b/lessons/02-using-encoder-feedback/01-measuring-wheel-speed/measuring-wheel-speed.md new file mode 100644 index 0000000..84bf8b7 --- /dev/null +++ b/lessons/02-using-encoder-feedback/01-measuring-wheel-speed/measuring-wheel-speed.md @@ -0,0 +1,32 @@ +--- +title: Measuring Wheel Speed +summary: Convert encoder counts over time into rotational speed for a drive wheel. +chapter: Using Encoder Feedback +order: 1 +tags: + - speed + - odometry + - robotics +estimated_minutes: 9 +--- + +# Measuring Wheel Speed + +Position counts become useful control signals once you add time. + +To estimate wheel speed: + +1. sample the encoder count at a fixed interval +2. subtract the previous count from the current count +3. divide by the sample period +4. convert counts per second into revolutions per second or wheel surface speed + +## Why this matters + +Speed feedback is the bridge between open-loop motor commands and predictable robot motion. + +If two drive motors get the same PWM value but spin at different speeds, your robot will drift. Encoder-based speed estimation lets you detect and correct that mismatch. + +## Checkpoint + +Plot wheel speed over time while ramping the motor command up and down. diff --git a/lessons/02-using-encoder-feedback/02-closing-the-loop-with-a-pid/closing-the-loop-with-a-pid.md b/lessons/02-using-encoder-feedback/02-closing-the-loop-with-a-pid/closing-the-loop-with-a-pid.md new file mode 100644 index 0000000..f405b3c --- /dev/null +++ b/lessons/02-using-encoder-feedback/02-closing-the-loop-with-a-pid/closing-the-loop-with-a-pid.md @@ -0,0 +1,34 @@ +--- +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.