diff --git a/.cruft.json b/.cruft.json index cde929e..1b0bce9 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/UrbanMachine/create-ros-app.git", - "commit": "3d4731e5661e8cbac11d71c60c8e925a989c150c", + "commit": "93e541631403e2c2c091c65d6583d61bd85a472c", "checkout": null, "context": { "cookiecutter": { diff --git a/docker-compose.yaml b/docker-compose.yaml index 299260b..2e408ab 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -38,6 +38,8 @@ services: DISPLAY: $DISPLAY # Necessary for PulseAudio passthrough PULSE_SERVER: "unix:/pulse-socket" + # Enable serial passthrough + privileged: true # Gives the container access to kernel capabilities, useful for most robots network_mode: host cap_add: diff --git a/docker/_shared.sh b/docker/_shared.sh index d4e6ad8..8314171 100644 --- a/docker/_shared.sh +++ b/docker/_shared.sh @@ -71,4 +71,27 @@ function deploy_and_wait { done echo "Another process brought down the stack." >&2 return 1 +} + +# Shows the user the available launch profiles +function launch_profiles_helper_msg { + echo "Available launch profiles are:" >&2 + # shellcheck disable=SC2012 + ls -1 launch-profiles/ | sed 's/^/ - /' >&2 + echo "" >&2 + echo "Read more about 'launch-profiles' under 'docs/about_template.md'" >&2 + exit 1 +} + +# Inform the user that the chosen launch profile is invalid if it is not a directory +function validate_launch_profile { + local chosen_profile + chosen_profile="$1" + + # Check if the chosen profile is a directory under 'launch-profiles' + if [[ ! -d "launch-profiles/${chosen_profile}" ]]; then + echo "Error: '${chosen_profile}' is not a valid launch profile." >&2 + echo "It should be a directory under 'launch-profiles/'." >&2 + launch_profiles_helper_msg + fi } \ No newline at end of file diff --git a/docker/launch b/docker/launch index 828fcc5..d48b1b7 100755 --- a/docker/launch +++ b/docker/launch @@ -24,14 +24,11 @@ set -o errexit set -o pipefail set -o nounset +source docker/_shared.sh + function usage { echo "Usage: docker/launch [--no-pull] " >&2 - echo "Available launch profiles are:" >&2 - # shellcheck disable=SC2012 - ls -1 launch-profiles/ | sed 's/^/ - /' >&2 - echo "" >&2 - echo "Read more about 'launch-profiles' under 'docs/about_template.md'" >&2 - exit 1 + launch_profiles_helper_msg } function main { @@ -64,9 +61,7 @@ function main { echo "Missing argument, specify a directory under 'launch-profiles/'" >&2 usage fi - - source docker/_shared.sh - + validate_launch_profile "${launch_profile}" # To reduce downtime, build the latest images before stopping any existing stacks. if [[ "${pull_upstream_images}" = true ]]; then diff --git a/docker/reload-ros-nodes b/docker/reload-ros-nodes new file mode 100755 index 0000000..3934d5a --- /dev/null +++ b/docker/reload-ros-nodes @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Builds and re-runs the ROS nodes container. This is useful if you want to restart +# the container over and over, oftentimes when developing on you ROS code. +# The container is only re-run if the image has changed. +# +# Usage: +# docker/reload-ros-nodes +# +# Examples: +# docker/reload-ros-nodes node_helpers_showcase + +set -o errexit +set -o pipefail +set -o nounset + +source docker/_shared.sh + +function main { + local launch_profile + launch_profile="${1:-}" + + if [[ -z "${launch_profile}" ]]; then + echo "Missing argument, specify a directory under 'launch-profiles/'" >&2 + echo "Usage: docker/reload-ros-nodes " >&2 + launch_profiles_helper_msg + fi + validate_launch_profile "${launch_profile}" + + build_images # Build any images that need to be built + enable_display_passthrough # Enable passthrough for the stack + + export LAUNCH_PROFILE="${launch_profile}" + docker compose up -d --force-recreate ros-nodes +} + +main "${@}" diff --git a/docs/about_template.md b/docs/about_template.md index 493951b..3c0c3f1 100644 --- a/docs/about_template.md +++ b/docs/about_template.md @@ -31,6 +31,9 @@ Here's a quick guide on the features of this template # Enter a currently running ROS container to poke around docker/exec + + # Rebuild and restart the ROS nodes in the container, useful for fast development + docker/reload-ros-nodes ``` More usage examples for the above scripts are documented at the top of the script files.