Skip to content

Instantly share code, notes, and snippets.

@willGuimont
Last active November 6, 2023 20:55
Show Gist options
  • Save willGuimont/5eae3425468fd69923248496ed4af013 to your computer and use it in GitHub Desktop.
Save willGuimont/5eae3425468fd69923248496ed4af013 to your computer and use it in GitHub Desktop.
Run ROS2 inside of VSCode's remote development

ROS2 in vscode

Copy the following files into your project directory:

  • Dockerfile to the root of your project; and
  • devcontainer.json to .devcontainer/devcontainer.json in your project.

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.

{
"name": "ros2",
"build": {
"context": "..",
"dockerfile": "../Dockerfile"
},
"workspaceFolder": "/workspaces/project",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/project,type=bind",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
"ms-python.isort",
"ms-python.vscode-pylance",
"ms-python.gather",
"ms-python.autopep8",
"ms-python.debugpy",
"ms-vscode.cpptools-extension-pack",
"GitHub.copilot",
"GitHub.copilot-chat"
]
}
},
"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 && echo \"source /workspaces/project/install/setup.bash\" >> ~/.bashrc"
}
FROM osrf/ros:iron-desktop-full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment