Skip to content

Ros2 projects templates

ROS2 jezzy

├── .devcontainer
│   ├── devcontainer.json
│   ├── Dockerfile.jazzy
│   ├── Dockerfile.runtime
│   ├── Dockerfile.dev
│   └── Dockerfile
├── .vscode
│   ├── tasks.json
│   └── settings.json
├── docker-compose.yml
├── .gitignore
├── README.md
├── colcon_defaults.md
├── env.sh
└── src
.devcontainer/Dockerfile.jazzy
.devcontainer/devcontainer.json
{
    "name": "gz_tutorial",
    "dockerComposeFile": "../docker-compose.yaml",
    "service": "ros",
    "shutdownAction": "stopCompose",
    "workspaceFolder": "/workspace",
    "remoteUser": "user",
    "customizations": {
      "vscode": {
        "extensions": [
            "ms-python.python",
            "ms-vscode.cpptools",
            "twxs.cmake",
            "redhat.vscode-xml",
            "redhat.vscode-yaml",
            "albert.tabout",
            "actboy168.tasks",
            "streetsidesoftware.code-spell-checker",
            "mhutchie.git-graph",
            "dlech.chmod",
            "smilerobotics.urdf"
        ],
        "settings": {}
      }
    }
  }
docker-compose.yaml
services:
  ros:
    image: jazzy:base
    user: "user:user"
    volumes:
      - .:/workspace:cached
      - /tmp/.X11-unix:/tmp/.X11-unix:rw 
      - /dev/dri:/dev/dri 
      - /dev/nvidia0:/dev/nvidia0 
      - /dev/nvidiactl:/dev/nvidiactl 
      - /dev/nvidia-modeset:/dev/nvidia-modeset 
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: [gpu]
    hostname: ros
    extra_hosts:
      - "ros:127.0.0.1"
    network_mode: host
    stdin_open: true
    tty: true
    environment:
      - DISPLAY=${DISPLAY}
      - QT_X11_NO_MITSHM=1
      - GZ_TRANSPORT_IP=ros
      - GZ_DISCOVERY_SERVER=gazebo
      - GZ_PARTITION=my_simulation
    devices:
      - /dev/dri:/dev/dri

ros

env.sh
source /home/ros/.bashrc
source /opt/ros/jazzy/setup.bash
source install/setup.bash
echo '🐢 Environment ready!'
# bash key bindings
# replace bringup with full bringup name
bind '"\C-b": "ros2 launch <bringup>"'

# Function to get git branch
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}

# Custom PS1 with turtle icon and git branch
export PS1="🐢 \[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$ "
colcon_defaults.yaml
build:
  # Use symlink install to speed up builds
  symlink-install: true
  # Set build type (e.g., Release or Debug)
  cmake-args:
    - "-DCMAKE_BUILD_TYPE=Release"

test:
  # Run tests in parallel
  parallel-workers: 4

# Additional settings for colcon test and other commands
test-result:
  verbose: true

VSCode

tasks.json

.vscode/tasks.json
{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "colcon",
        "detail": "Build all ros2 packages using colcon",
        "type": "shell",
        "command": "colcon build",
        "problemMatcher": [],
        "group": {
            "kind": "build",
            "isDefault": true
        }
      }
    ]
}
.vscode/settings.json
{
    "terminal.integrated.profiles.linux": {
      "bash": {
          "path": "bash",
          "icon": "terminal-bash",
          "args": ["--rcfile", "env.sh"]
      }
  },
   "python.autoComplete.extraPaths": [
        "${workspaceFolder}/install/**",
        "/opt/ros/humble/lib/python3.10/site-packages/",
        "/opt/ros/humble/local/lib/python3.10/dist-packages"

    ],

    "python.analysis.extraPaths": [
        "${workspaceFolder}/install/**",
        "/opt/ros/humble/lib/python3.10/site-packages/",
        "/opt/ros/humble/local/lib/python3.10/dist-packages/",
    ]

}