-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun
executable file
·156 lines (134 loc) · 3.8 KB
/
run
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
#!/bin/bash
LOG_FILE="command_output.log"
# Function to print messages in green
print_green() {
echo -e "\e[0m\e[32m$1\e[0m"
}
# Function to print messages in blue
print_blue() {
echo -e "\e[34m$1\e[0m"
}
# Function to print messages in red
print_red() {
echo -e "\e[0m\e[31m$1\e[0m"
}
# Print the blue welcome message
print_blue "------------------------------------------"
print_blue "Purdue RoboMaster Club: Auto Aiming Suite"
print_blue "------------------------------------------"
# Function to clean the workspace
clean() {
print_green "Cleaning workspace..."
rm -rf build install log Testing $LOG_FILE
print_green "Clean complete."
}
# Function to build the project
build() {
print_green "[*] Building project with Release configuration and optimization flags."
build_args="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE=-O3 -DPYTHON_EXECUTABLE=/usr/bin/python3.8"
# Add the DEBUG flag if '--debug' or '-d' was provided
if [[ "$debug" == "true" ]]; then
build_args="-DCMAKE_CXX_FLAGS=-DDEBUG $build_args"
fi
if [[ "$quiet" == "true" ]]; then
colcon build --symlink-install --cmake-args $build_args --allow-overriding opencv_armor_detector >> "$LOG_FILE" 2>&1
else
colcon build --symlink-install --cmake-args $build_args --allow-overriding opencv_armor_detector
fi
if [ $? -eq 0 ]; then
# print checkmark
print_green "[☺ ] Build successful."
source install/setup.sh
else
print_red "Build failed. See $LOG_FILE for more information."
exit 1
fi
}
# Function to run tests for each ROS module (non-recursively at first)
test() {
print_green "Running tests for ROS modules..."
# Run build first
build
# Check if a package name is provided
local package_name=$1
# Run tests
if [[ -z "$package_name" ]]; then
print_green "Running all tests..."
else
print_green "Running tests for package: $package_name"
fi
if [[ "$quiet" == "true" ]]; then
if [[ -n "$package_name" ]]; then
colcon test --packages-select "$package_name" >> "$LOG_FILE" 2>&1
else
colcon test >> "$LOG_FILE" 2>&1
fi
colcon test-result --verbose >> "$LOG_FILE" 2>&1
else
if [[ -n "$package_name" ]]; then
colcon test --packages-select "$package_name"
else
colcon test
fi
colcon test-result --verbose
fi
# Check if tests passed
if [ $? -ne 0 ]; then
print_red "Tests failed. See $LOG_FILE for more information."
exit 1
fi
print_green "Test execution complete."
}
# Function to run a ROS2 launch command
run() {
if [[ -z "$1" ]]; then
print_red "Error: No launch argument provided."
echo "Usage: $0 run <launch_file>"
exit 1
fi
launch_file="$1"
# Run build first
build
print_green "[*] Running ROS2 launch: prm_launch $launch_file"
ros2 launch prm_launch "$launch_file"
if [ $? -ne 0 ]; then
print_red "Launch failed."
exit 1
fi
}
# Parse script options
while [[ $# -gt 0 ]]; do
case "$1" in
-q|--quiet)
quiet=true
shift
;;
-d|--debug)
debug=true
shift
;;
build)
build
shift
;;
clean)
clean
shift
;;
test)
shift
test "$1" # Pass the next argument (package name) to the test function
shift
;;
run)
shift
run "$@"
shift $#
;;
*)
echo "Usage: $0 [--quiet] [--debug] {build|clean|test [package_name]|run <launch_file>}"
exit 1
;;
esac
done
exit 0