📘 CodingMarble Learn

Path Planning and Motion Control

Path planning means choosing a safe, short route from start to goal around obstacles. Motion control means making the wheels follow that route: speed and turning come from the two wheel speeds. A line-following robot uses floor sensors and a steering rule to stay on a line.

🎬 Step-by-step story

  1. A robot must reach the goal. Before it moves, it needs a route. The green circle is the start and the blue cone is the goal.
  2. A wall now blocks the middle. The red straight line cannot be used, so the robot must go around.
  3. Path planning: the computer checks the open squares and finds the shortest route. The yellow squares are the plan. Slide the gap and the plan changes.
  4. Motion control: the robot drives the plan. To turn, one wheel runs slower than the other. Read the wheel speeds below.
  5. Line following: two floor sensors look for the black line. The sensor that sees the line turns green, and the robot steers that way.
  6. Free play: change the speed. The robot reads its sensors only a few times a second, so at a very high speed it slips off the line.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why not just go in a straight line?

A wall or obstacle may block it. The red line in the 3D shows the blocked straight path, so the robot needs a detour.

How does the computer know the shortest route?

It looks at the open squares step by step and counts moves. The yellow squares are the route with the fewest moves.

What if the wall opening moves?

The plan changes. Slide the gap and watch the yellow squares and the step count update. This is re-planning.

How can a robot turn if the wheels are fixed?

By running the two wheels at different speeds. The slower wheel is on the side it turns towards.

How does the robot know where the line is?

Floor sensors turn green when they see the dark line. The controller turns towards the green sensor.

Why does it lose the line at high speed?

It reads the sensors only a few times a second. At high speed it travels too far between readings. Raise the speed in the last step to see it.

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):

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

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

Practice quiz

1. Path planning decides:
2. To turn left, a two-wheel robot runs:
3. A line-follower sensor mostly tells apart:
4. Which control uses sensors to correct errors?
5. Distance = ?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

How does a line follower robot work?

Infrared sensors look at the floor. They tell dark line from bright floor. The controller steers towards the side where the line is seen, again and again.

What is the difference between path planning and motion control?

Path planning chooses the route on a map. Motion control drives the wheels so the robot really follows that route.

Which algorithm is used for the shortest path on a grid?

Breadth-first search finds the fewest steps when each move costs the same. A* and Dijkstra are used when moves have different costs.

Where this is taught

China高二Sel.2 Robot design and making (engineering)

Learn first

Learn next

Related lessons

All Computer Science lessons