Back to Blog
AIDec 23, 2025

Teaching Robots to Drive: Rules vs. Reinforcement Learning

Teaching Robots to Drive: Rules vs. Reinforcement Learning

A trained PPO agent cut our robots’ crash rate from 48% to 19% compared with a hand-written state machine. It did not make them faster, though, and that surprised me more than the safety win.

This semester my partner Mubarak Andrabi and I built a multi-robot navigation system in Webots. Several small e-puck robots share one arena, each driving to a random target while dodging walls and each other. We wrote two controllers for the same job: a classic rule-based Finite State Machine (FSM), and a neural network trained with Proximal Policy Optimization (PPO). Then we ran them both and logged everything.

Here is what we built, what the numbers said, and where my expectations were wrong.

The setup

Everything runs in Webots, an open-source robot simulator. The robots are e-pucks: small two-wheeled educational robots with 8 infrared proximity sensors around their body. A supervisor process hands each robot a random target, and the robot has to get there without hitting walls, obstacles or its neighbours.

The hard part is the neighbours. A wall stays put. Another robot is moving, and it is making its own decisions at the same time you are.

Approach 1: a rule-based state machine

The baseline is a prioritized FSM. Every control step, it checks four rules from most to least urgent and acts on the first one that fires:

  1. Stuck recovery. If the motors are running but GPS says the robot is not moving, reverse and spin to break free.
  2. Virtual bumper. If any proximity sensor crosses a threshold, turn away from the strongest reading.
  3. Right-hand yield. If another robot is within 15 cm on the right, stop and wait until it clears.
  4. Go to goal. Otherwise, a proportional (P) controller steers to cut the heading error to the target.

This took an afternoon to write, and every decision it makes is easy to explain. When it misbehaves, you read the state log and you know why. That transparency turned out to matter a lot later.

Approach 2: a PPO agent

The second controller is a small neural network trained with PPO. It reads a 17-number observation each step:

  • the 8 proximity sensor readings
  • distance to the goal, and the goal’s angle (as sin and cos)
  • distance and angle to the nearest obstacle, plus how fast it is closing in
  • the robot’s own linear and angular speed

Two hidden layers of 64 neurons (tanh) map that to 2 outputs: continuous speeds for the left and right wheels.

Training it all at once did not work, so we used a three-phase curriculum:

  1. Find the target. An empty arena and a +20 reward for reaching the goal. This teaches the basic link between the goal inputs and driving forward.
  2. Drive well. Shape the reward around heading and speed. This is where the agent found its first exploit: it learned to spin in circles to farm the distance-based reward. We fixed it by penalizing high angular velocity.
  3. Avoid collisions. Add static and moving obstacles and a −20 crash penalty. The agent learned to slow down near threats and steer around them rather than stopping dead.

Training took several hours. Writing the FSM took one afternoon. That gap is the first real cost of the learned approach.

The results

The PPO agent was far safer and drove cleaner lines; the FSM reached its targets sooner. We logged 79 runs of the baseline and 200 runs of the trained agent (50 evaluation episodes, 4 robots each).

MetricFSM baselinePPO agent
Runs with a collision48.1%19.0%
Collisions per run (mean)1.89 (max 17)0.19 (max 1)
Path efficiency (actual ÷ straight-line, median)1.090.99
Time spent stopped (mean)3.21 s0 s
Time per run (median)8.5 s14.5 s
Average speed (mean)0.062 m/s0.067 m/s

Safety is the headline. The FSM crashed in almost half its runs, and its worst runs were ugly: five runs logged 10 or more collisions, with one hitting 17 as the robot got wedged against a neighbour and kept bumping. The PPO agent never collided more than once in a run.

The paths are tighter. The FSM’s “turn away from the sensor” reflex makes square, wall-following detours; seven of its runs travelled more than twice the straight-line distance. The PPO agent’s paths sit right on the straight line, because it learned to curve around obstacles early instead of reacting at the last moment.

It never stops. The right-hand yield rule cost the FSM about 3.2 seconds of standing still per run. The PPO agent has no stop rule at all; it modulates speed and swerves through gaps that the FSM would wait out.

What the data doesn’t say

I went in expecting the AI to be faster too, and in a small 5-trial test it was. The bigger evaluation disagrees, and a few quirks in how we logged things are worth being upfront about:

  • Time isn’t a clean comparison. In the PPO runs, the four robots in an episode share one timer, so a robot’s “time” is really the whole episode’s time. 80 of the 200 runs hit the ~16 s episode cap. Per-robot speed was actually slightly higher for PPO; the slower median comes from the logging and the timeout.
  • A crash means something different. The PPO episode ends a robot’s run at its first collision, so it can never log more than one. The FSM keeps driving after a bump. The crash-rate comparison holds; the collisions-per-run gap is partly by design.
  • Path efficiency under 1.0 shows up for PPO because a run that ends at the cap or a crash stops short of the target. It is a sign of tight paths, not a robot beating the straight line.
  • Different sample sizes. The baseline numbers come from one robot’s 79 runs; the PPO numbers from 200.

None of this flips the main finding on safety. It does mean I would not claim the AI was faster from this data.

What I took away

Learned policies find gaps rules can’t. The FSM treats any nearby robot as a reason to stop. The PPO agent learned to judge whether there was room to pass, and that alone removed both the stopping time and most crashes.

Reward functions are where the bugs live. The spinning-in-circles exploit is a classic reward-hacking story, and we only caught it by watching the robot. The network did exactly what we rewarded, not what we meant.

Debuggability is a real cost. When the FSM fails, the state log tells you why. When the network fails, you get a robot doing something odd and no explanation. For a simple, open arena, I would still ship the FSM. For a crowded one, the learned controller is clearly the better bet.

If I did this again, I’d fix the logging first: a per-robot timer, the same crash definition for both controllers, and an equal number of runs on each side.

The full code and training scripts are on GitHub: Mubicool/multi-robot-rl.