Skip to content

ramsafin/ros-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ROS with Docker

This project provides a ready-to-use Docker container for ROS 1 (ROS Noetic) for development and testing. It simplifies the process of working with ROS in an isolated, reproducible environment that can run on both Windows (via WSL) and Linux. The setup includes GUI support for ROS development in WSLg and native Linux systems, along with easy integration with your existing ROS workspace.

Prerequisites

Before you begin, make sure you have the following installed:

Ensure you have WSLg installed, as it enables GUI support for Docker containers in Windows. If you're unsure about this, refer to the WSLg Installation guide.

Setting Up the Project

1. Clone the Project

If you haven't already, clone this repository to your local machine:

git clone https://github.com/ramsafin/ros-docker.git
cd ros-docker

2. Build the Docker Image

There are two build options available depending on your environment: WSL and Linux.

Build the Docker image optimized for WSL:

make build_wsl

Build the Docker image optimized for Linux:

make build_linux

The Makefile handles the setup for different environments, adjusting the Dockerfile build arguments accordingly.

3. Running the Docker Container

To start a container with GUI support and mount your ROS workspace, use:

make run_wsl

or

make run_linux

This will automatically handle display forwarding if you are using WSLg. For non-WSLg setups, you may need to configure access to the X server (e.g., with xhost in non-WSL2 environments).

4. Building the ROS Workspace

By default your ROS workspace inside the container is ROS_WORKSPACE=/home/ros/catkin_ws.

Once inside the container, navigate to your ROS workspace and build it:

cd $ROS_WORKSPACE && catkin_make

Alternatively, using catkin-tools:

cd $ROS_WORKSPACE && catkin build

This will generate the build/, devel/, and install/ directories in the catkin_ws directory.

If you have uninstalled dependencies, use:

rosdep install --from-paths $ROS_WORKSPACE/src --ignore-src -y

5. Running ROS Nodes

After building your workspace, you can start working with ROS nodes. For example, you can run the ROS master:

roscore

Do not forget to source your ROS environment and workspace:

source /opt/ros/$ROS_DISTRO/setup.bash
source $ROS_WORKSPACE/devel/setup.bash

6. Stopping the Container

When you're finished, you can stop the container by typing exit or pressing Ctrl+D. Since the container was started with --rm, it will be automatically removed when stopped.

To manually stop the container, run:

make stop

Troubleshooting

How to select GPU in WSLg?

The NVIDIA GPU can be selected in WSL by setting MESA_D3D12_DEFAULT_ADAPTER_NAME:

echo "export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA" >> ~/.bashrc
source ~/.bashrc

Follow the instructions in the GPU selection in WSLg guide.

Containerizing GUI apps with WSLg

Follow the instructions in the wslg/containers guide.

Docker container cannot connect to X server

Ensure that the xhost command is used to allow Docker to connect to the X server:

xhost +SI:localuser:$(whoami)

Additionally, verify that your X server is running.

How to check that NVIDIA is used for OpenGL rendering?

Check the output of the command:

glxinfo -B | grep Device

It should be your NVIDIA GPU.

Auxiliary

  1. For more detailed documentation on setting up and using ROS Noetic, visit the official ROS documentation.
  2. For more information about WSLg, visit the WSLg official repository.

Contributing

If you'd like to contribute to this project, feel free to fork the repository and submit a pull request. You can also open an issue if you encounter any bugs or have suggestions for improvement.

This project is licensed under the MIT License - see the LICENSE file for details.