Path planning: choosing the route
Path planning decides which way a robot should travel. The robot needs three things: a map (where things are), a start and a goal.
A simple map is a grid of squares. Each square is free or blocked by an obstacle. The planner then looks for a chain of free squares from start to goal. A common method, breadth-first search, spreads out one step at a time, like ripples in water, and so finds the route with the fewest steps.
Planning has a cost to compare routes: number of steps, distance or time. If the map changes (someone puts a box on the road), the robot must re-plan. A global plan covers the whole trip; a local plan avoids a sudden obstacle nearby.
Motion control: making the wheels follow the plan
Motion control turns the plan into wheel movement. Most small robots have two driven wheels (differential drive):
- Both wheels same speed: the robot goes straight.
- Left slower than right: the robot turns left. Right slower than left: it turns right.
- One forward, one backward: it spins on the spot.
The speed of a wheel is set with PWM. Open-loop control just sends commands and hopes. Closed-loop control uses sensors (wheel encoders, line sensors) to check and correct. Closed loop is more accurate because the wheels can slip.
Useful sums: distance = speed × time, and wheel turns = distance ÷ (π × wheel diameter).
Line-following robot
A line-following robot has two (or more) infrared sensors facing the floor. A black line reflects little light, a white floor reflects a lot, so the sensor can tell them apart.
Simple rule: no sensor sees the line, go straight. Right sensor sees it, the line is drifting right, so steer right. Left sensor sees it, steer left. This is an ON/OFF rule.
A better rule is proportional control: steer by an amount that matches the error. Correction = K × error. Bigger error, bigger turn. The robot then moves smoothly.
Limits: the robot reads the sensors only some times a second. Too fast, and the line is gone before the robot turns. Lower the speed, move the sensors forward, or read faster.
Try it: draw a track
Draw a thick black line on white paper with a marker. Put a toy car on it and move it by hand with this rule: if the line is under your right finger, turn right. Next, on squared paper, draw start, goal and a wall. Count the steps of two routes and pick the shortest. In the 3D, slide the gap and guess the new number of steps before you read it.
Key formulas and definitions
- Distance = speed × time
- Wheel turns = distance / (π × wheel diameter)
- Straight: left speed = right speed
- Turn right: right wheel slower than left wheel
- Proportional control: correction = K × error; left = base + correction, right = base − correction
Worked examples
1. A robot moves at 0.5 m/s. How long does it take to go 2 m?
time = distance / speed = 2 / 0.5 = 4 s.
2. A wheel has diameter 6 cm. How many turns does it make for 1.884 m (188.4 cm)?
One turn = π × 6 = 18.84 cm. Turns = 188.4 / 18.84 = 10.
3. On a grid with no obstacles, the start is at column 0, row 0 and the goal at column 4, row 3. Fewest steps (moves up, down, left, right)?
4 steps across and 3 steps down: 4 + 3 = 7 steps.
4. A line follower has base speed 60. The line is to the right by error +0.5 and K = 20. Find both wheel speeds (positive error = line on the right).
Correction = 20 × 0.5 = 10. Left = 60 + 10 = 70. Right = 60 − 10 = 50. The right wheel is slower, so the robot turns right.
5. In the 3D with the gap at the bottom row, the route is 2 steps down, 6 across and 2 up. How many steps?
2 + 6 + 2 = 10 steps.
Common mistakes
- Thinking the shortest straight line is always possible. Obstacles force a longer route.
- Mixing up the turn direction. To turn right the RIGHT wheel must be the slower one.
- Setting the speed as high as possible. The robot reacts too late and leaves the line.
- Planning once and never checking. If the map changes the robot must re-plan, and sensors should confirm the motion.