Skip to content

Commit b14838a

Browse files
committed
Fix launch and build tasks from vscode, now F5 and Ctrl-Shift-B work in robot and GCS containers
Also ensure doesn't autolaunch when opening vscode container
1 parent f50a4a2 commit b14838a

12 files changed

Lines changed: 146 additions & 91 deletions

File tree

.devcontainer/gcs/devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
],
99
"service": "gcs",
1010
"workspaceFolder": "/home/gcs/AirStack",
11-
"remoteEnv": {
12-
"AUTOLAUNCH": "false"
13-
},
11+
"initializeCommand": "export AUTOLAUNCH=false && echo 'You may close this window'",
1412
"customizations": {
1513
"vscode": {
1614
"extensions": [

.devcontainer/gcs/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "2.0.0",
3+
"configurations": [
4+
{
5+
"name": "ROS2: Launch GCS Bringup",
6+
"type": "ros2",
7+
"request": "launch",
8+
"target": "${workspaceFolder}/gcs/ros_ws/src/gcs_bringup/launch/gcs.launch.xml"
9+
}
10+
]
11+
}

.devcontainer/robot/devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
],
99
"service": "robot",
1010
"workspaceFolder": "/home/robot/AirStack",
11-
"remoteEnv": {
12-
"AUTOLAUNCH": "false",
13-
},
11+
"initializeCommand": "export AUTOLAUNCH=false && echo 'You may close this window'",
1412
"customizations": {
1513
"vscode": {
1614
"extensions": [

.devcontainer/robot/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "2.0.0",
3+
"configurations": [
4+
{
5+
"name": "ROS2: Launch Robot Bringup",
6+
"type": "ros2",
7+
"request": "launch",
8+
"target": "${workspaceFolder}/robot/ros_ws/src/robot_bringup/launch/robot.launch.xml"
9+
}
10+
]
11+
}

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode-remote.remote-containers",
4+
"ms-vscode.cpptools",
5+
"ms-python.python",
6+
"ms-python.black-formatter"
7+
]
8+
}

.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Dummy file. This file meant to be empty because it gets mounted over when a Dev Container is opened.
2+
// This enables container-specific launch.json

.vscode/tasks.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
// `bws` is the same command across robot and gcs containers
3+
"version": "2.0.0",
4+
"tasks": [
5+
{
6+
"label": "Build ros_ws Debug",
7+
"type": "shell",
8+
"options": {
9+
"cwd": "${workspaceFolder}"
10+
},
11+
"command": [
12+
"source ${userHome}/.bashrc &&",
13+
"bws --cmake-args '-DCMAKE_BUILD_TYPE=Debug'"
14+
],
15+
"problemMatcher": [],
16+
"group": {
17+
"kind": "build",
18+
"isDefault": true
19+
}
20+
},
21+
],
22+
"configurations": [
23+
24+
]
25+
}

docs/development/vscode/index.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
# VS Code: Docker Integration and Debugger Setup
1+
# Visual Studio Code: Docker Integration and Debugger Setup
22

3-
Start containers
4-
```bash
5-
# optionally prepend NUM_ROBOTS=N argument to start N robots
6-
airstack up -d
7-
```
3+
This guide explains how to set up Visual Studio Code (VSCode) to work with AirStack's Docker containers and use the built-in debugger.
84

9-
Open AirStack folder
5+
Integration with the Docker containers works by using the [Dev Containers extension](https://code.visualstudio.com/docs/remote/containers). This allows you to open a folder within a container, and use VSCode's features (like the debugger) as if you were working on your local machine.
106

11-
```bash
12-
cd AirStack
13-
code .
14-
```
7+
The two available containers for breakpoint debugging are `robot` and `gcs`.
158

16-
Install the ["Dev Containers" extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
9+
## Open Container
1710

18-
Now click the "Remote Explorer" icon on the left side bar, hover over a robot container, and attach to the container.
11+
1. Open AirStack folder in VSCode on your host machine.
12+
2. If it's your first time, VSCode will prompt with a popup to install recommended extensions. Click "Install All". Or, you can manually install the ["Dev Containers" extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
13+
3. Now open the Command Palette (F1) and type "Dev Containers: Reopen in Container". Select "Robot Container" or "GCS Container" depending on which you want to work with.
1914

20-
![attach_container](attach_container.png)
15+
This will build the container (if it hasn't been built before) and open the AirStack folder within the container. This may take a few minutes.
2116

22-
Install recommended extensions within the image. This installs the `ROS`, `C++`, and `Python` extensions in the container.
23-
![extensions.png](extensions.png)
17+
If you want to customize the container (for example, to add additional tools), you can edit `.devcontainer/devcontainer.json` and `.devcontainer/Dockerfile`.
18+
19+
You can also open a terminal in the container by hitting `Ctrl-`` (backtick).
20+
21+
4. You should now be able to build the workspace and launch the debugger as described below.
22+
5. To switch back to your host machine, you can use the "Dev Containers: Reopen Folder Locally" command from the Command Palette (F1).
2423

2524
## Build ROS Workspace
2625
Hit `Ctrl-Shift-B` to build the project. This is a shortcut for `bws --cmake-args '-DCMAKE_BUILD_TYPE=Debug'`, which adds debug symbols to the build.
2726

2827
Build tasks are defined in `.vscode/tasks.json`.
2928

3029

31-
## Launch
30+
## Launch and Debug
31+
32+
Debugging uses the [Robot Developers Extension for ROS2](https://ranchhandrobotics.com/rde-ros-2/debug-support.html#). We recommend consulting their docs for more details.
3233

33-
Hit `F5` to launch `robot.launch.xml`, or click the "Run and Debug" button on the left side of the screen and click the green play button.
34+
To start debugging, hit `F5` to launch `robot.launch.xml`, or click the "Run and Debug" button on the left side of the screen and click the green play button.
3435

3536
Launch tasks are defined in `.vscode/launch.json`.
3637

gcs/docker/.bashrc

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,68 @@
33
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
44
# for examples
55

6+
# --- ROS2 workspace setup ---
7+
8+
# Define the ROS2 workspace directory
9+
ROS2_WS_DIR="$HOME/AirStack/gcs/ros_ws"
10+
# needed for communication with Isaac Sim ROS2 # https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_ros.html#enabling-the-ros-bridge-extension
11+
export FASTRTPS_DEFAULT_PROFILES_FILE="$ROS2_WS_DIR/fastdds.xml"
12+
# for local development, prevent conflict with other desktops
13+
export ROS_LOCALHOST_ONLY=1
14+
15+
# fix ROS2 humble setuptools deprecation warning https://robotics.stackexchange.com/questions/24230/setuptoolsdeprecationwarning-in-ros2-humble/24349#24349
16+
PYTHONWARNINGS="ignore:easy_install command is deprecated,ignore:setup.py install is deprecated"
17+
export PYTHONWARNINGS
18+
19+
# Convenience functions for ROS2 workspace
20+
21+
function bws(){
22+
echo "Running \`colcon build $@\` in $ROS2_WS_DIR"
23+
COLCON_LOG_PATH="$ROS2_WS_DIR"/log colcon build --symlink-install --base-paths "$ROS2_WS_DIR"/ --build-base "$ROS2_WS_DIR"/build/ --install-base "$ROS2_WS_DIR"/install/ "$@"
24+
}
25+
function sws(){
26+
echo "Sourcing "$ROS2_WS_DIR"/install/local_setup.bash"
27+
source "$ROS2_WS_DIR"/install/local_setup.bash || echo "Please make sure to build first with 'bws'"
28+
}
29+
30+
# Function to prompt user for confirmation
31+
confirm_cws() {
32+
while true; do
33+
read -p "Are you sure you want to clean the ROS2 workspace under $ROS2_WS_DIR? (y/N): " yn
34+
yn=${yn:-no} # Default to 'no' if no answer is given
35+
case $yn in
36+
[Yy] | [Yy][Ee][Ss] ) return 0;;
37+
[Nn] | [Nn][Oo] ) return 1;;
38+
* ) echo "Please answer yes or no.";;
39+
esac
40+
done
41+
}
42+
function cws(){
43+
# Call the confirmation function
44+
if confirm_cws; then
45+
echo "Cleaning ROS2 workspace..."
46+
set -x
47+
# Remove build, install, and log directories
48+
if ! rm -rf "$ROS2_WS_DIR"/build/ "$ROS2_WS_DIR"/install/ "$ROS2_WS_DIR"/log/; then
49+
{ set +x; } 2>/dev/null
50+
echo "Error: Failed to remove ROS2 workspace directories."
51+
exit 1
52+
fi
53+
54+
# Set environment variables
55+
export AMENT_PREFIX_PATH="/opt/ros/humble"
56+
export CMAKE_PREFIX_PATH=""
57+
58+
{ set +x; } 2>/dev/null # set +x w/out it being printed
59+
echo "ROS2 workspace has been cleaned successfully."
60+
else
61+
echo "Operation cancelled."
62+
fi
63+
}
64+
65+
source /opt/ros/humble/setup.bash
66+
sws # source the ROS2 workspace by default
67+
668
# If not running interactively, don't do anything
769
[ -z "$PS1" ] && return
870

@@ -102,68 +164,6 @@ fi
102164
# . /etc/bash_completion
103165
#fi
104166

105-
# --- ROS2 workspace setup ---
106-
107-
# Define the ROS2 workspace directory
108-
ROS2_WS_DIR="$HOME/AirStack/gcs/ros_ws"
109-
# needed for communication with Isaac Sim ROS2 # https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_ros.html#enabling-the-ros-bridge-extension
110-
export FASTRTPS_DEFAULT_PROFILES_FILE="$ROS2_WS_DIR/fastdds.xml"
111-
# for local development, prevent conflict with other desktops
112-
export ROS_LOCALHOST_ONLY=1
113-
114-
# fix ROS2 humble setuptools deprecation warning https://robotics.stackexchange.com/questions/24230/setuptoolsdeprecationwarning-in-ros2-humble/24349#24349
115-
PYTHONWARNINGS="ignore:easy_install command is deprecated,ignore:setup.py install is deprecated"
116-
export PYTHONWARNINGS
117-
118-
# Convenience functions for ROS2 workspace
119-
120-
function bws(){
121-
echo "Running \`colcon build $@\` in $ROS2_WS_DIR"
122-
COLCON_LOG_PATH="$ROS2_WS_DIR"/log colcon build --symlink-install --base-paths "$ROS2_WS_DIR"/ --build-base "$ROS2_WS_DIR"/build/ --install-base "$ROS2_WS_DIR"/install/ "$@"
123-
}
124-
function sws(){
125-
echo "Sourcing "$ROS2_WS_DIR"/install/local_setup.bash"
126-
source "$ROS2_WS_DIR"/install/local_setup.bash || echo "Please make sure to build first with 'bws'"
127-
}
128-
129-
# Function to prompt user for confirmation
130-
confirm_cws() {
131-
while true; do
132-
read -p "Are you sure you want to clean the ROS2 workspace under $ROS2_WS_DIR? (y/N): " yn
133-
yn=${yn:-no} # Default to 'no' if no answer is given
134-
case $yn in
135-
[Yy] | [Yy][Ee][Ss] ) return 0;;
136-
[Nn] | [Nn][Oo] ) return 1;;
137-
* ) echo "Please answer yes or no.";;
138-
esac
139-
done
140-
}
141-
function cws(){
142-
# Call the confirmation function
143-
if confirm_cws; then
144-
echo "Cleaning ROS2 workspace..."
145-
set -x
146-
# Remove build, install, and log directories
147-
if ! rm -rf "$ROS2_WS_DIR"/build/ "$ROS2_WS_DIR"/install/ "$ROS2_WS_DIR"/log/; then
148-
{ set +x; } 2>/dev/null
149-
echo "Error: Failed to remove ROS2 workspace directories."
150-
exit 1
151-
fi
152-
153-
# Set environment variables
154-
export AMENT_PREFIX_PATH="/opt/ros/humble"
155-
export CMAKE_PREFIX_PATH=""
156-
157-
{ set +x; } 2>/dev/null # set +x w/out it being printed
158-
echo "ROS2 workspace has been cleaned successfully."
159-
else
160-
echo "Operation cancelled."
161-
fi
162-
}
163-
164-
source /opt/ros/humble/setup.bash
165-
sws # source the ROS2 workspace by default
166-
167167
export RCUTILS_COLORIZED_OUTPUT=1
168168

169169
export ROS_DOMAIN_ID=0

gcs/docker/gcs-base-docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ services:
99
- ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${DOCKER_IMAGE_TAG}_gcs
1010
command: >
1111
bash -c "ssh service restart;
12-
tmux new -d -s gcs_bringup;
1312
autolaunch=${AUTOLAUNCH:-'false'};
1413
if [ $$autolaunch = 'true' ]; then
14+
tmux new -d -s gcs_bringup;
1515
tmux send-keys -t gcs_bringup 'bws && sws; ros2 launch ${GCS_LAUNCH_PACKAGE} ${GCS_LAUNCH_FILE}' ENTER;
1616
fi;
1717
sleep infinity"
@@ -42,8 +42,8 @@ services:
4242
- ../../common/.bash_profile:/home/gcs/.bash_profile:rw
4343
- .bashrc:/home/gcs/.bashrc:rw
4444
- ../../common/.tmux.conf:/home/gcs/.tmux.conf:rw
45-
- ../../common/ros_packages:/home/gcs/ros_ws/src/common:rw
4645
- ../../common/inputrc:/etc/inputrc:rw
46+
- ../../.devcontainer/gcs/launch.json:/home/gcs/AirStack/.vscode/launch.json:rw
4747
# autonomy stack stuff
4848
- ../..:/home/gcs/AirStack
4949
- ../../common/ros_packages:/home/gcs/AirStack/gcs/ros_ws/src/common:rw # common ROS packages

0 commit comments

Comments
 (0)