Skip to content

Commit

Permalink
Replace Makefiles with shell scripts for building and running the demos
Browse files Browse the repository at this point in the history
Related to space-ros/space-ros#178

 - Remove makefiles for canadarm2 and curiosity rover demo
 - Add build.sh for building canadarm2 and curiosity rover demo
 - Add run.sh for running the demos
 - Update README.md of demos to the new process
  • Loading branch information
franklinselva committed Sep 9, 2024
1 parent f64c755 commit 7c5dbc6
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 142 deletions.
60 changes: 0 additions & 60 deletions canadarm2/Makefile

This file was deleted.

22 changes: 16 additions & 6 deletions canadarm2/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Curiosity Rover - Demo
# SSRMS CanadArm2 - Demo

This is a simple demo of controlling the canadarm using spaceROS.

Expand All @@ -18,19 +18,29 @@ To start the demo, there are few dependencies that need to be installed. The fol

1. Clone the demo repository
```bash
git clone http://github.com/space-ros/demo.git
git clone https://github.com/space-ros/demos.git
```
2. cd into the `canadarm2` directory
```bash
cd canadarm2
```
3. To build and run the demo, we use `Makefile`. Run the following command to build the docker image and run the container.
3. To build the demo, we use `./build.sh`. You can do the following to build the demo.
```bash
# To see the list of available commands
make help
./build.sh help
```
4. To build the demo, you can use the following command.
```bash
# To build the demos for the canadarm2
./build.sh
# To build and run the demo
make run
# Cleanup the build
./build.sh clean
```
5. To run the demo, you can use the following command.
```bash
# To run the demo
./run.sh
```

This will start the demo in one terminal and gazebo in another terminal. To control the canadarm2, we provide ros2 services for the demo. You can control the rover using the following services.
Expand Down
104 changes: 104 additions & 0 deletions canadarm2/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash

set -e

# Define variables
DOCKER_IMAGE="osrf/space-ros:canadarm_demo"
LOCAL_WORKSPACE=$(pwd)
SHELL="/bin/bash"

# Define packages
SIM_PACKAGES="canadarm_description canadarm_gazebo"
CONTROL_PACKAGE="canadarm_moveit_config canadarm_demo"
DEMO_PACKAGES="$CONTROL_PACKAGE $SIM_PACKAGES"

####################################################################################################
# High-level functions
####################################################################################################
# Help function to describe each target
help() {
echo "CanadArm2 Build Script"
echo "Usage: ./build.sh [subcommand] [demo]"
echo "Available subcommands:"
echo " ./build.sh help - Show this help message"
echo " ./build.sh clean - Clean the local workspace"
echo " ./build.sh - Build the demos"
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
}

####################################################################################################
# Control demo
####################################################################################################
build-control-demo() {
build-docker
build-gazebo
}

####################################################################################################
# Main script logic to call the appropriate function
####################################################################################################
case "$1" in
help)
help
;;
clean)
clean
;;
*)
check_docker
check_ros2

build
;;
esac
2 changes: 0 additions & 2 deletions canadarm2/canadarm_moveit_config/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@
<exec_depend>moveit_configs_utils</exec_depend>
<exec_depend>moveit_ros_move_group</exec_depend>
<exec_depend>moveit_ros_visualization</exec_depend>
<exec_depend>moveit_ros_warehouse</exec_depend>
<exec_depend>moveit_setup_assistant</exec_depend>
<exec_depend>robot_state_publisher</exec_depend>
<exec_depend>rviz2</exec_depend>
<exec_depend>rviz_common</exec_depend>
<exec_depend>rviz_default_plugins</exec_depend>
<exec_depend>simulation</exec_depend>
<exec_depend>tf2_ros</exec_depend>
<exec_depend>warehouse_ros_mongo</exec_depend>
<exec_depend>xacro</exec_depend>


Expand Down
58 changes: 58 additions & 0 deletions canadarm2/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# shellcheck disable=SC2089
XTERM_CONFIG="-bg black -fg white -fa 'Monospace' -fs 11"
DOCKER_IMAGE="osrf/space-ros:canadarm_demo"
LOCAL_WORKSPACE=$(pwd)

# Run the CanadArm Gazebo simulation locally
run-gazebo() {
# shellcheck disable=SC2090
# shellcheck disable=SC2086
xterm $XTERM_CONFIG -T 'CanadArm2 Gazebo' -e "source /opt/ros/\${ROS_DISTRO}/setup.bash \
&& source $LOCAL_WORKSPACE/install/setup.bash \
&& ros2 launch canadarm_gazebo canadarm.launch.py" &
}

run-control-demo() {
# shellcheck disable=SC2090
# shellcheck disable=SC2086
xterm $XTERM_CONFIG -T 'CanadArm2 Demo' -e "docker run -it --rm \
-e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp \
$DOCKER_IMAGE \
bash -c 'source ~/.bashrc && ros2 launch canadarm_demo canadarm.launch.py'" &
}

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
}

run() {

check_docker
check_xterm
check_ros2

run-gazebo
run-control-demo
}

run
60 changes: 0 additions & 60 deletions curiosity_rover/Makefile

This file was deleted.

Loading

0 comments on commit 7c5dbc6

Please sign in to comment.