Robotics Lab Labs / Fix the oscillating robot

Lab 03, beginner robotics control

Fix the oscillating robot

Something is wrong with this robot controller.

The problem

Something is wrong with this robot controller. A differential-drive robot must follow the straight path to the target flag 16 m away. It starts 1 m to the side of the path.

The robot is trying to follow the path, but its motion is oscillatory. Run the simulation and study the response.

How the robot steers

The robot drives forward at a constant 0.8 m/s. The controller only chooses how fast to turn:

heading_error = desired_heading − heading ω = Kp · heading_error + Kd · d(heading_error)/dt

The desired heading points at a spot 1 m ahead on the path, so the farther off the path the robot is, the more sharply it wants to turn back.

The robot model
ẋ = v cos θ ẏ = v sin θ θ̇ = ω

Like a real robot, it cannot change its turn rate instantly (motors and inertia take about half a second to respond), and its position estimate arrives 0.2 s late.

Words used in this lab

Tracking error

How far the robot is from the path, sideways. Positive means left of the path, negative means right.

Overshoot

How far the robot swings past the path to the other side, as a percentage of its starting distance from the path.

Settling time

How long the robot takes to remain close to the desired trajectory: within ±5 cm for the rest of the run.

Oscillation measure

How many times the robot crosses the path. A well-tuned robot crosses it at most once.

Control effort

How hard the controller steers overall: the root-mean-square of the turn-rate command, in rad/s.

Starting controller

Tracking error vs time (m)

Angular velocity vs time (rad/s)

Tap a measure to see what it means.

Heading controllerRuns in your browser
Advanced: maximum turn rate

Why robots oscillate

Oscillation is one of the most common problems when a robot first runs on real hardware: a line follower that snakes, a mobile robot that zig-zags around its planned path, a joint that buzzes around its setpoint. It almost always comes from a controller that reacts too hard for how quickly the robot can actually respond, with too little damping.

In this lab you debug it the way engineers do: watch the behaviour, read the tracking-error plot, form a hypothesis, change one parameter, and compare. Then you prove the fix is real by testing it against disturbances it was not tuned for.

Read the guide: Why is my robot oscillating? A practical guide to controller tuning. New to PID? Start with Lab 02: tune a PID controller. Ready for more? Lab 01: build a CBF safety filter.

Get the next lab

Get notified when new robotics labs are released. One email per new lab, nothing else.