सामग्री पर जाएँ

लेसन 18 · Actuators and Control

Mobile Robot Control

Control wheeled robots: go-to-goal with heading error, line following with PID, pure pursuit path tracking and a speed limiter, simulated in Python.

You now have the pieces: a kinematic model of how a wheeled robot moves, sensors that report the world, and PID to correct errors. This lesson joins them into behaviors that make a mobile robot do useful things: drive to a point, follow a line, track a planned path and slow down for obstacles.

All controllers work in a loop: read the pose or sensor, compute the errors, output a forward speed v and turn rate ω, and convert those to wheel speeds with vR = v + ωL/2, vL = v - ωL/2.

flowchart LR
    G["Goal / path"] --> C["Behavior controller<br/>(v, omega)"]
    P["Pose estimate or sensors"] --> C
    C --> W["Wheel speeds<br/>vL, vR"]
    W --> R["Robot"]
    R --> P

Behavior controllers produce a velocity command; kinematics converts it to wheel speeds.

Go to a point

Suppose the robot knows its pose (x, y, θ) (from odometry or localization) and wants to reach (gx, gy). Two errors drive it:

  • Distance error ρ = sqrt((gx - x)² + (gy - y)²).
  • Heading error α = atan2(gy - y, gx - x) - θ, wrapped to (-π, π].

Control law: ω = Kα · α turns toward the goal, and v = Kρ · ρ slows down as the goal nears. Scaling the speed by cos α (or setting it near zero when the heading error is large) keeps the robot from driving away from a goal behind it.

The angle wrap is a classic bug: the difference between 179 and -179 degrees is 2 degrees, not 358. Always normalize with atan2(sin α, cos α).

Python Go-to-goal controller

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All three starts reach the goal even when the robot starts facing away, because the heading error drives a turn first.

Line following

A line-following robot has a row of reflectance sensors under its body. The sensor array gives a position error: where the line is relative to the center, say -1 (far left) to +1 (far right). A PID on that error steers the robot: ω = Kp e + Ki ∫e + Kd de/dt. The derivative term is valuable here because it anticipates curves. A common racing trick is to also reduce the forward speed when the error is large, so the robot slows through sharp bends.

Python PD line follower on a curved track

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Experiment with the gains: too little Kd weaves around the line, while a very high Kp oscillates.

Pure pursuit: tracking a path

When a planner gives the robot a path (a list of waypoints, from path planning), the goal moves along it. Pure pursuit picks a lookahead point on the path a fixed distance Ld ahead of the robot, then steers on a circular arc that passes through that point. If the lookahead point is at angle α from the robot's heading, the required curvature is

κ = 2 sin α / Ld, and ω = v κ.

A short lookahead tracks tightly but wobbles; a long lookahead is smooth but cuts corners. Often Ld is made proportional to speed.

Python Pure pursuit on a waypoint path

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The longer lookahead cuts the corners and has a larger cross-track error but a smoother path; the short one hugs the path.

Slow down for obstacles

Behaviors can be combined with a simple speed limiter: reduce v as the nearest obstacle in front gets closer. A common form scales v linearly between a stop distance and a slow-down distance.

Python Safety speed limiter

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The limiter sits between planning and the motors, so a faulty plan still cannot drive into a wall. Layering simple reflexes under higher-level behavior is a classic robot architecture (subsumption), and it recurs in the later software chapters.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In go-to-goal control, what is the heading error?

    alpha = atan2(dy, dx) - theta, wrapped into (-pi, pi].
  2. 2. Why must angle differences be wrapped?

    Without wrapping, the robot would take the long way around.
  3. 3. What is the effect of a longer lookahead distance in pure pursuit?

    Long lookahead gives gentle arcs and cuts corners; short lookahead hugs the path but oscillates.
  4. 4. Why does a line follower benefit from a derivative term?

    D acts as damping and looks ahead along the changing error.

Summary

  • Mobile behaviors output (v, ω); kinematics converts them into wheel speeds.
  • Go-to-goal steers on the wrapped heading error and slows with distance.
  • Line followers use PID on a lateral error from a sensor array.
  • Pure pursuit steers toward a lookahead point on the path with curvature 2 sin α / Ld.
  • A speed limiter based on the nearest obstacle adds a safety layer.

Next: Configuration Space and the Planning Problem

अपनी प्रगति ट्रैक करें

मुफ़्त अकाउंट बनाएँ, लेसन पूरे के रूप में चिह्नित करें और किसी भी डिवाइस पर वहीं से शुरू करें जहाँ छोड़ा था।