Intro
The Robot Operating System (ROS) is an essential platform for developing robotic applications. However, getting ROS up and running on various systems can be challenging due to issues like dependency conflicts, varying operating system versions, and hardware inconsistencies.
One way to simplify this is by using Docker, which allows you to containerize your ROS environment. This method provides a portable, isolated environment that can be shared across different machines without affecting your host system.
In this guide, we will walk through the process of setting up ROS Noetic inside a Docker container and using it to:
- Run
ROS Noetic
in Docker
.
- Simulate a mobile robot using
Gazebo
.
- Control the robot with
teleop_twist_keyboard
.
- Customize launch files for different simulation environments.
Benefits of Using Docker for ROS:
- Consistency: Docker ensures the environment is the same across all systems.
- Portability: Easily share and deploy ROS applications without worrying about installation or configuration.
- Cross-Platform: Works on Linux, macOS, and Windows, providing flexibility.
- Isolation: Keeps your ROS environment separate from your host system, minimizing conflicts.
For more about Docker, visit the official Docker documentation.
Setting Up ROS Noetic in Docker
To begin, you need Docker installed on your machine. If you haven’t installed Docker yet, follow the official guide to install Docker.
Run a ROS Noetic Docker Container in your Windows Terminal
Start by pulling the official ROS Noetic image and running it in an interactive terminal:
docker run -it --name ros_container --net=host --privileged osrf/ros:noetic-desktop-full bash
Explanation of Parameters:
docker run -it
: Launches the container in interactive mode.
--name ros_container
: Assigns a custom name to the container for easy reference.
--net=host
: Ensures that ROS nodes can communicate with each other on the same network as the host.
--privileged
: Grants the container full access to the host’s devices, which is necessary for simulation.
osrf/ros:noetic-desktop-full
: Uses the ROS Noetic image, which includes the desktop version with tools like Gazebo.
Once you execute this command, you’ll be inside the Docker container, where ROS Noetic is fully set up and ready to use.
Creating a ROS Workspace and Building Packages
A ROS workspace is essential for organizing your projects and packages. Here’s how you can set up a basic workspace:
Create and Build a Catkin Workspace
mkdir -p ~/Workspaces/smb_ws/src
cd ~/Workspaces/smb_ws
catkin_make
source devel/setup.bash
Running a Robot Simulation in Gazebo
To test ROS in a real-world scenario, we will simulate a Small Mobile Robot (SMB) in Gazebo, a popular robot simulation tool integrated with ROS.
Clone the SMB Simulation Repository
cd ~/Workspaces/smb_ws/src
git clone https://github.com/ethz-asl/smb_common.git
Build the Package
cd ~/Workspaces/smb_ws
catkin_make
source devel/setup.bash
Launch the Simulation
roslaunch smb_gazebo smb_gazebo.launch
Controlling the Robot with Teleoperation
To manually control the simulated robot, we’ll use the teleop_twist_keyboard
package, which allows control via keyboard input.
Clone and Build the Teleoperation Package
cd ~/Workspaces/smb_ws/src
git clone https://github.com/ros-teleop/teleop_twist_keyboard.git
cd ~/Workspaces/smb_ws
catkin_make
source devel/setup.bash
Run the Teleoperation Node
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Use the W/A/S/D keys to move the robot forward, backward, left, and right, and the Q/E keys to rotate it.
Verifying and Debugging ROS Nodes
As with any ROS application, debugging is an essential part of development.
Here are some common commands to verify the status of your ROS nodes and topics.
Check Running ROS Nodes
rosnode list
Check Available ROS Topics
rostopic list
Publish Velocity Commands Manually
To control the robot directly via command line, you can publish velocity command
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.5}}'
This command will move the robot forward while rotating it at a rate of 0.5 radians per second.
Conclusion
In this guide, we’ve set up ROS Noetic in Docker and demonstrated how to simulate a robot in Gazebo, control it manually.
Further Resources
If you have any feedback or questions, feel free to reach out through the ROS Discourse.
Hope this helps 
5 posts - 4 participants
Read full topic