Run ROS2 inside of VSCode's remote development - norlab-ulaval/Norlab_wiki GitHub Wiki
ROS2 in vscode
This tutorial is based on Run ROS2 inside of VSCode's remote development by William Guimont-Martin.
Create a Dockerfile
with the following content in your project:
FROM osrf/ros:iron-desktop-full
Create .devcontainer/devcontainer.json
with the following content in your project:
{
"name": "ros2",
"build": {
"context": "..",
"dockerfile": "../Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python"
]
}
},
"mounts": [
"source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind",
"source=/dev/shm,target=/dev/shm,type=bind"
],
"containerEnv": {
"DISPLAY": ":1",
"NVIDIA_VISIBLE_DEVICES": "all",
"NVIDIA_DRIVER_CAPABILITIES": "all"
},
"runArgs": [
"--ipc=host",
"--pid=host",
"--net=host"
],
"postCreateCommand": "echo \"source /opt/ros/$ROS_DISTRO/setup.bash\" >> ~/.bashrc"
}
To allow the container to run GUI applications (e.g., rviz2), you need to run the following command:
# Allow xhost access to local user
xhost +si:localuser:root
In VSCode, install the extension pack Remote Development that allows remote development inside of Docker containers.
Open your project in VSCode, and start remote development by entering Dev Containers: Rebuild and Reopen in Container
into the command palette (CTRL-SHIFT-P
). You can now open a terminal and run your ROS2 nodes:
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
colcon build
source install/setup.bash
ros2 launch launch/launch.py
There might me some error in IntelliSense (e.g., some imports not found), run Python: Clear Cache and Reload Window
in the command palette.