Skip to content

VisionFrom Pixels to Steering

Finding the Center and Steering

The target's center is the average column of the pixels that pass; the steering error is that minus the image center.

Not started Jump to practice

The mask shows where the ball is. Now steer toward it.

Key idea

The target's center (centroid) is the average column of the pixels that passed. The steering error is that column minus the image's middle column, $w/2$. Feed it to a proportional controller: turn toward the target, harder when it is farther off center.
The cross marks the center of the kept pixels. The readout gives the steering error.

Why it works

This is closed-loop control with a camera as the sensor. Each frame measures the error and the robot corrects; as it turns, the ball moves toward the middle and the error shrinks. It is how many FIRST robots line up with targets.

Worked example: Steering error

Image 320 wide; kept pixels in columns 210, 214, 220, 224.
  1. Center: $(210 + 214 + 220 + 224)/4 = 217$.
  2. Error: $217 - 160 = 57$.

Answer: 57 pixels right of center: turn right.

Common mistake

Measuring the error from the left edge instead of from the center.

Hands-on: a ball-chasing robot

Put a camera on your mobile robot. Each frame: threshold for your ball's color, find the center, and set the wheel speeds from the steering error. Start with a small gain and raise it until the robot turns briskly without wobbling.

Safety. Chase a soft ball in an open room at low speed, with the power switch in reach. Keep the robot away from stairs.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Robot Vision.

Sources and further reading