-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.sh
executable file
·160 lines (144 loc) · 4.6 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
set -e
# Define variables
DOCKER_IMAGE="osrf/space-ros:canadarm_demo"
LOCAL_WORKSPACE=$(pwd)
SHELL="/bin/bash"
# shellcheck disable=SC2089
XTERM_CONFIG="-bg black -fg white -fa 'Monospace' -fs 11"
# Define packages
SIM_PACKAGES="canadarm_description canadarm_gazebo"
CONTROL_PACKAGE="canadarm_moveit_config canadarm_demo"
DEMO_PACKAGES="$CONTROL_PACKAGE"
AVAIABLE_DEMOS="control-demo"
####################################################################################################
# High-level functions
####################################################################################################
# Help function to describe each target
help() {
echo "CanadArm2 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 CanadArm2 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" .
}
# 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" &
}
# 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
}
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'" &
}
####################################################################################################
# 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