CodeTheRobot

ROS 2 Lyrical Luth · Lesson 66 of 86

Docking behaviors

The docking server, dock plugins, staging poses and charging detection.

Estimated time · 60–90 min

Learning goals

What you will understand

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

Docking means driving precisely onto a charger or a pallet station. Nav2's docking server takes a dock (an ID and a pose, or a database of docks), navigates to a staging pose in front of it, then uses a dock plugin (for example one based on the detected dock pose) to approach slowly with visual or fiducial feedback, and checks for charging. Undocking reverses the process.

You supply the dock database, the detection source (ArUco markers, lidar features or an AprilTag), speed limits for the final approach and the charging signal. Always test the approach in simulation, and ensure the robot stops if detection is lost near the dock.

Guided lesson

Work through these steps

  1. 1.

    Source the ROS 2 Lyrical environment in a fresh terminal.

  2. 2.

    Read the docking behaviors 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

docks:
# Dock database entries.
  - id: home_dock
# A dock named home_dock.
    type: simple_charging_dock
# Plugin used to detect and approach it.
    frame: map
# The pose below is in the map frame.
    pose: [1.0, 2.0, 1.57]
# Dock position x, y (m) and heading (rad).
# ros2 action send_goal /dock_robot nav2_msgs/action/DockRobot "{use_dock_id: true, dock_id: 'home_dock'}"
# Command the robot to dock.

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 Docking behaviors. Expected result: The robot drives to home_dock and reports success

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.

# TODO: send a DockRobot goal that uses the dock id 'home_dock'

Expected output

The robot drives to home_dock 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

  • 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

Define a dock with an ArUco marker, navigate to its staging pose, dock, and confirm charging state. Cover the marker mid-approach and check that the robot stops safely.

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.