CodeTheRobot

Ubuntu Linux for Robotics · Lesson 79 of 96

Global planner

NavFn and Smac planners, testing a plan with the compute_path action.

Estimated time · 45–60 min

Learning goals

What you will understand

  • Explain global planner in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

The global planner finds a path from the robot to the goal on the global costmap. NavFn (Dijkstra/A*) is simple and fast; Smac 2D is grid A*; Smac Hybrid-A* respects a minimum turning radius for car-like robots. The planner server hosts the plugins named in planner_plugins.

You can test a planner without moving the robot by calling the ComputePathToPose action and looking at the path in RViz2. Plugin names and parameters differ between Nav2 releases, so read the documentation for your distribution.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the global planner commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

ros2 param get /planner_server planner_plugins
# Which planner plugins are loaded.
ros2 action send_goal /compute_path_to_pose nav2_msgs/action/ComputePathToPose "{goal: {header: {frame_id: map}, pose: {position: {x: 2.0, y: 1.0}, orientation: {w: 1.0}}}, planner_id: 'GridBased'}"
# Ask for a path to (2, 1) without driving.
ros2 topic echo /plan --once
# Read the resulting path.
ros2 param set /planner_server GridBased.use_astar true
# Switch NavFn to A* while running.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

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 Global planner. Expected result: The list of loaded planner plugins

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# TODO: read the parameter planner_plugins of /planner_server

Expected output

The list of loaded planner plugins
Stuck? Show the full solution (try it yourself first)
ros2 param get /planner_server planner_plugins

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Compute paths to the same goal with two planners, compare their length and smoothness in RViz2, and read the planning time from the planner server log.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.