CodeTheRobot

ROS 2 Lyrical Luth · Lesson 62 of 86

Local planners: DWB and TEB

Controllers that follow the path, DWB critics, and how TEB differs.

Estimated time · 60–90 min

Learning goals

What you will understand

  • Explain local planners: dwb and teb in your own words
  • Use it in a small robotics example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

The local planner (controller) turns the global path into velocity commands while avoiding obstacles seen in the local costmap. DWB samples many velocity pairs, simulates each forward for about a second, scores the trajectories with critics (path alignment, goal distance, obstacles) and picks the best. Regulated Pure Pursuit is a simpler alternative shipped with Nav2.

TEB (Timed Elastic Band) optimizes a whole time-parameterized trajectory and handles tight spaces and car-like motion; it is a community plugin that you install separately and check for your release. Tune max velocities and accelerations to the real robot, otherwise the commands will not be achievable.

Guided lesson

Work through these steps

  1. 1.

    Source the ROS 2 Lyrical environment in a fresh terminal.

  2. 2.

    Read the local planners: dwb and teb example and identify what each line does.

  3. 3.

    Build only the affected package, source the workspace overlay, and run the example.

  4. 4.

    Inspect the result from a second terminal with the ros2 CLI or RViz2 and compare it with the expected result.

Worked example

Read it before you run it

controller_server:
# Node section.
  ros__parameters:
# ROS parameters.
    controller_frequency: 20.0
# Compute commands 20 times a second.
    controller_plugins: ["FollowPath"]
# Which controller to load.
    FollowPath:
# Its settings.
      plugin: "dwb_core::DWBLocalPlanner"
# The DWB controller.
      max_vel_x: 0.5
# Maximum forward speed in m/s.
      max_vel_theta: 1.0
# Maximum turn speed in rad/s.
      critics: ["RotateToGoal", "Oscillation", "ObstacleFootprint", "GoalAlign", "PathAlign", "PathDist", "GoalDist"]
# The scoring rules for candidate trajectories.

What the example is doing

  1. 1.The ros2 commands query the running graph; they do not prove that a node's internal behavior is correct.
  2. 2.Build from the workspace root, then source install/setup.bash so the shell can discover the new package.
  3. 3.Use a second sourced terminal to inspect nodes and interfaces while the example runs.

Watch it run · Mobile robot

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

goalMOBILE ROBOT

Demo for Local planners: DWB and TEB. Expected result: The robot follows the path at up to 0.5 m/s

Practice code

Now type it yourself

Copy the starter into your ROS 2 package, replace every TODO, then build with colcon build and run it from a sourced terminal.

controller_server:
  ros__parameters:
    controller_frequency: 20.0
    controller_plugins: ["FollowPath"]
    FollowPath:
      plugin: "dwb_core::DWBLocalPlanner"
# TODO: set max_vel_x to 0.5 and max_vel_theta to 1.0

Expected output

The robot follows the path at up to 0.5 m/s
Stuck? Show the full solution (try it yourself first)
controller_server:
  ros__parameters:
    controller_frequency: 20.0
    controller_plugins: ["FollowPath"]
    FollowPath:
      plugin: "dwb_core::DWBLocalPlanner"
      max_vel_x: 0.5
      max_vel_theta: 1.0

Expected result

How you know it worked

  • ROS_DISTRO is lyrical in every terminal used for the exercise.
  • The complete package from the exercise builds and the expected graph entity appears in a second terminal.

Practical exercise

Apply the lesson

Run navigation with DWB, then lower max_vel_x from 0.5 to 0.2 and raise it to 1.0; record behaviour near obstacles. Try the Regulated Pure Pursuit controller and compare.

Before you continue

  • ROS_DISTRO reports lyrical in every terminal you used
  • The example builds and runs without errors
  • You checked the result with a ros2 command, RViz2 or a test, not just by reading the code

If something goes wrong

ros2 cannot find a package or executable.

Source /opt/ros/lyrical/setup.bash, build from the workspace root, then source install/setup.bash in that terminal.

Nodes run but cannot discover each other.

Confirm both terminals use Lyrical, the same ROS_DOMAIN_ID, and compatible network/discovery settings.