Skip to content

Mastering Docker and ROS for Roboclaw With Key Tips and Workflows

Introduction

Integrating Docker and ROS for robotics projects, especially with RoboClaw motor controllers, can seem daunting. This post streamlines critical steps, from saving Docker images to running ROS nodes with Xbox controller support, ensuring a smooth and efficient workflow.


Key Topics Covered

  • Saving Docker containers for future use
  • Opening new terminals in containers
  • Running containers with Bluetooth and port access
  • Setting up and using a ROS workspace in Docker
  • Debugging common integration issues

1. Saving Docker Containers

Why Save Containers?

  • Prevents loss of your setup if the container is stopped or deleted.
  • Allows easy re-creation of environments.

Steps:

  1. Stop the container:
    sudo docker stop <container_name>
    
  2. Commit the container as an image:
    sudo docker commit <container_id> <new_image_name>
    
  3. Verify the image:
    sudo docker images
    

Example:

sudo docker commit 96a9ad78d1e6 ros_noetic_with_rviz


2. Opening a New Terminal in a Running Container

Why Do This?

  • Manage multiple ROS nodes or debug processes.

Steps:

  1. List running containers:
    sudo docker ps
    
  2. Attach a terminal to the container:
    sudo docker exec -it <container_name> /bin/bash
    

Example:

sudo docker exec -it ros_rviz_container /bin/bash


3. Running Containers with Bluetooth and Port Access

Why Use These Flags?

  • --net=host: Enables seamless network communication.
  • --privileged: Grants full access to host devices.
  • --device: Connects peripherals like an Xbox controller.
  • -v: Mounts necessary directories for GUI and Bluetooth.

Command Example:

sudo docker run -it --name roboclaw_v02 \
    --net=host \
    --privileged \
    --device=/dev/input/js0:/dev/input/js0 \
    --device=/dev/input/event0:/dev/input/event0 \
    -v /var/run/dbus:/var/run/dbus \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    roboclaw_v02


4. Setting Up a ROS Workspace in Docker

Steps:

  1. Mount the workspace:
    sudo docker run -it --name <container_name> \
        -v ~/ros_noetic_ws:/root/ros_noetic_ws \
        <base_image>
    
  2. Inside the container:
    cd ~/ros_noetic_ws
    catkin_make
    source devel/setup.bash
    

5. Running ROS Nodes and Debugging

Starting roscore:

  1. Attach a terminal to the container:
    sudo docker exec -it <container_name> /bin/bash
    
  2. Run roscore:
    roscore
    

Running a ROS Node:

  1. Source the workspace:
    source ~/ros_noetic_ws/devel/setup.bash
    
  2. Run the node:
    rosrun roboclaw_node xbox_teleop_odom.py
    

6. Debugging Common Issues

Problem: "Master Not Found"

  • Ensure roscore is running in the same container.

Problem: Device Not Found

  • Check device mapping:
    ls /dev/input/js0
    

Problem: Missing ROS_PACKAGE_PATH

  • Add the workspace to ROS_PACKAGE_PATH:
    export ROS_PACKAGE_PATH=/root/ros_noetic_ws/src:$ROS_PACKAGE_PATH
    

Conclusion

By following these practices, you can efficiently develop robotics applications using Docker and ROS. This workflow allows for robust integration of peripherals, such as Xbox controllers, and ensures smooth communication between ROS nodes.

Stay innovative and focus on building your robotics vision without being bogged down by setup hurdles!

Happy Robotics! 🚀


Created 2025-01-26, Updated 2025-01-27
Authors: Harminder Singh Nijjar (5)

Comments