Skip to content

Commit

Permalink
Added make target/recipe to test the ros2 installation with 'make tes…
Browse files Browse the repository at this point in the history
…t_ros2_installation'
  • Loading branch information
akoerner1 committed Dec 12, 2024
1 parent 45eeee3 commit 7c747f1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tools/test_ros2_installation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -euo pipefail

echoerr() { printf "%b" "$*\n" >&2;}
exiterr (){ printf "%s\n" "$@" >&2; exit 1;}

SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"


if ! command -v ros2 &> /dev/null; then
exiterr "ERROR: ROS 2 is not installed or not in PATH"
fi

ros_version=$(ros2 pkg prefix ros2cli)
echo "ROS 2 Version: $ros_version"
if [[ -z "$ros_version" ]]; then
exiterr "ERROR: Failed to get ROS 2 version"
fi

if [[ -z "$ROS_DISTRO" ]]; then
exiterr "ERROR ROS_DISTRO environment variable is not set"
fi
echo "ROS_DISTRO is set to: $ROS_DISTRO"

echo "Testing 'ros2 topic list' command..."
if ! ros2 topic list; then
exiterr "ERROR: Failed to run 'ros2 topic list'"
else
echo "'ros2 topic list' command succeeded"
fi

echo "ROS 2 is installed correctly"

0 comments on commit 7c747f1

Please sign in to comment.