CodeTheRobot

Ubuntu Linux for Robotics · Lesson 83 of 96

Docking

Sending a dock goal, the docking server and verifying charging.

Estimated time · 45–75 min

Learning goals

What you will understand

  • Explain docking 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

Docking means driving precisely onto a charging station. Nav2's docking server navigates to a staging pose in front of the dock, uses a dock plugin and a detection source (for example an ArUco marker) to approach slowly, and checks that charging began. Docks are described in a YAML database with an ID, type and pose.

Send a goal to the DockRobot action with the dock ID. Test with the simulated robot first, cover the marker mid-approach to check that the robot stops, and keep the final-approach speed low. Undocking is a separate action that reverses out.

Guided lesson

Work through these steps

  1. 1.

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

  2. 2.

    Read the docking 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 action list | grep dock
# Check the docking actions exist.
ros2 action send_goal /dock_robot nav2_msgs/action/DockRobot "{use_dock_id: true, dock_id: 'home_dock'}"
# Dock at the dock called home_dock.
ros2 topic echo /battery_state --once
# Check the battery or charging state.
ros2 action send_goal /undock_robot nav2_msgs/action/UndockRobot "{dock_type: 'simple_charging_dock'}"
# Leave the dock.

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 Docking. Expected result: The robot docks and reports success

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: send a DockRobot goal with use_dock_id true and dock_id 'home_dock'

Expected output

The robot docks and reports success
Stuck? Show the full solution (try it yourself first)
ros2 action send_goal /dock_robot nav2_msgs/action/DockRobot "{use_dock_id: true, dock_id: 'home_dock'}"

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

Define a dock in the database, send the dock goal, confirm the charging state, undock, and test what the robot does when the marker is hidden during the approach.

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.