-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Makefile with shell scripts for curiosity rover demo
Related to space-ros/space-ros#178 - Revert the purpose of makefiles - Add a new shell script for building and running the demos - Update README.md for shell script usage
- Loading branch information
1 parent
bd5e472
commit 95acc36
Showing
4 changed files
with
185 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Define variables | ||
DOCKER_IMAGE="osrf/space-ros:curiosity_demo" | ||
LOCAL_WORKSPACE=$(pwd) | ||
SHELL="/bin/bash" | ||
# shellcheck disable=SC2089 | ||
XTERM_CONFIG="-bg black -fg white -fa 'Monospace' -fs 11" | ||
|
||
# Define packages | ||
SIM_PACKAGES="curiosity_description curiosity_gazebo" | ||
CONTROL_PACKAGE="curiosity_rover_demo" | ||
DEMO_PACKAGES="$CONTROL_PACKAGE" | ||
AVAIABLE_DEMOS="control-demo" | ||
|
||
#################################################################################################### | ||
# High-level functions | ||
#################################################################################################### | ||
# Help function to describe each target | ||
help() { | ||
echo "Curiosity Rover Bash Script" | ||
echo " ./build.sh list - List all available demos" | ||
echo " ./build.sh build - Build all the demo components. This will include all supported demos and the Docker image" | ||
echo " ./build.sh clean - Clean the local workspace" | ||
echo " ./build.sh build control-demo - Build the control demo" | ||
echo " ./build.sh run control-demo - Build and run the Curiosity Rover demo" | ||
exit 0 | ||
} | ||
|
||
# Build all | ||
build() { | ||
build-control-demo | ||
} | ||
|
||
# Clean the local workspace | ||
clean() { | ||
rm -rf "$LOCAL_WORKSPACE"/install "$LOCAL_WORKSPACE"/log "$LOCAL_WORKSPACE"/build | ||
} | ||
|
||
check_docker() { | ||
if ! command -v docker &>/dev/null; then | ||
echo "Docker is not installed. Please install Docker to continue." | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_xterm() { | ||
if ! command -v xterm &>/dev/null; then | ||
echo "xterm is not installed. Please install xterm to continue." | ||
echo "On Ubuntu, you can install xterm with 'sudo apt install xterm'." | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_ros2() { | ||
if ! command -v ros2 &>/dev/null; then | ||
echo "ROS 2 is not installed. Please install ROS 2 to continue." | ||
exit 1 | ||
fi | ||
} | ||
|
||
#################################################################################################### | ||
# Low-level functions | ||
#################################################################################################### | ||
# Build the Docker image | ||
build-docker() { | ||
docker build -t "$DOCKER_IMAGE" . | ||
} | ||
|
||
# Build the Gazebo workspace locally | ||
build-gazebo() { | ||
# shellcheck source=/opt/ros/${ROS_DISTRO}/setup.bash | ||
# shellcheck disable=SC1091 | ||
source /opt/ros/"${ROS_DISTRO}"/setup.bash && | ||
rosdep install --from-paths . -r -y --skip-keys "$DEMO_PACKAGES" && | ||
colcon build --symlink-install --base-paths "$LOCAL_WORKSPACE" --install-base "$LOCAL_WORKSPACE"/install \ | ||
--cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
--packages-select $SIM_PACKAGES | ||
} | ||
|
||
# Run the CanadArm Gazebo simulation locally | ||
run-gazebo() { | ||
# shellcheck disable=SC2090 | ||
# shellcheck disable=SC2086 | ||
xterm $XTERM_CONFIG -T 'Curiosity Rover Gazebo' -e "source /opt/ros/\${ROS_DISTRO}/setup.bash \ | ||
&& source $LOCAL_WORKSPACE/install/setup.bash \ | ||
&& ros2 launch curiosity_gazebo curiosity_gazebo.launch.py" & | ||
} | ||
|
||
#################################################################################################### | ||
# Curiosity Rover Control Demo | ||
####################################################################################################n | ||
# Build the control demo | ||
build-control-demo() { | ||
build-docker | ||
build-gazebo | ||
} | ||
|
||
# Run the control demo | ||
run-control-demo() { | ||
# shellcheck disable=SC2090 | ||
# shellcheck disable=SC2086 | ||
xterm $XTERM_CONFIG -T 'Curiosity Rover Control Demo' -e "docker run -it --rm -e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp $DOCKER_IMAGE \ | ||
bash -c 'source ~/.bashrc && ros2 launch curiosity_rover_demo mars_rover.launch.py'" & | ||
} | ||
|
||
#################################################################################################### | ||
# Main script logic to call the appropriate function | ||
#################################################################################################### | ||
case "$1" in | ||
help) | ||
help | ||
;; | ||
list) | ||
echo "Available demos:" | ||
for demo in $AVAIABLE_DEMOS; do | ||
echo " - $demo" | ||
done | ||
echo "Available subcommands:" | ||
echo " - build, clean, run" | ||
exit 0 | ||
;; | ||
clean) | ||
clean | ||
;; | ||
build) | ||
check_ros2 | ||
check_docker | ||
case "$2" in | ||
control-demo) | ||
build-control-demo | ||
;; | ||
*) | ||
build | ||
;; | ||
esac | ||
;; | ||
run) | ||
check_xterm | ||
check_ros2 | ||
check_docker | ||
|
||
run-gazebo | ||
case "$2" in | ||
control-demo) | ||
run-control-demo | ||
;; | ||
*) | ||
echo "Invalid target. 'run" "$2" "' is not a valid demo. Try './build.sh list' to see available demos." | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
*) | ||
echo "Invalid target. Use './build.sh help' to see available subcommands." | ||
exit 1 | ||
;; | ||
esac |