-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlaunch_as2.bash
More file actions
executable file
·135 lines (120 loc) · 3.73 KB
/
launch_as2.bash
File metadata and controls
executable file
·135 lines (120 loc) · 3.73 KB
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
#!/bin/bash
usage() {
echo " options:"
echo " -r: record rosbag"
echo " -c: motion controller plugin (pid_speed_controller, differential_flatness_controller), choices: [pid, df]. Default: pid"
echo " -m: 12 agent. For mission_12"
echo " -n: select drones namespace to launch, values are comma separated. By default, it will get all drones from world description file"
echo " -g: launch using gnome-terminal instead of tmux. Default not set"
}
# Initialize variables with default values
motion_controller_plugin="pid"
swarm12="false"
drones_namespace_comma=""
use_gnome="false"
# Arg parser
while getopts "rcmn:g" opt; do
case ${opt} in
r )
record_rosbag="true"
;;
c )
motion_controller_plugin="${OPTARG}"
;;
m )
swarm12="true"
;;
n )
drones_namespace_comma="${OPTARG}"
;;
g )
use_gnome="true"
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
exit 1
;;
: )
if [[ ! $OPTARG =~ ^[wrt]$ ]]; then
echo "Option -$OPTARG requires an argument" >&2
usage
exit 1
fi
;;
esac
done
# HOW TO INCLUDE MODULES FROM THE PROJECT
export AS2_MODULES_PATH=$AS2_MODULES_PATH:$(pwd)/as2_python_api_modules
## DEFAULTS
record_rosbag=${record_rosbag:="false"}
# Set simulation world description config file for 4 drones or 12 drones
if [[ ${swarm12} == "true" ]]; then
simulation_config="config/world_swarm_12.yaml"
as2_config_file="config/config.yaml"
mission_file="mission_12"
echo "$swarm12"
else
simulation_config="config/world_swarm_3.yaml"
as2_config_file="config/config.yaml"
rviz_config="config_ground_station/rviz3_config.rviz"
mission_file="mission_swarm"
echo "Default configuration used"
fi
# If no drone namespaces are provided, get them from the world description config file
if [ -z "$drones_namespace_comma" ]; then
drones_namespace_comma=$(python3 utils/get_drones.py -p ${simulation_config} --sep ',')
fi
IFS=',' read -r -a drone_namespaces <<< "$drones_namespace_comma"
# Check if motion controller plugins are valid
case ${motion_controller_plugin} in
pid )
motion_controller_plugin="pid_speed_controller"
;;
df )
motion_controller_plugin="differential_flatness_controller"
;;
* )
echo "Invalid motion controller plugin: ${motion_controller_plugin}" >&2
usage
exit 1
;;
esac
# Select between tmux and gnome-terminal
tmuxinator_mode="start"
tmuxinator_end="wait"
tmp_file="/tmp/as2_project_launch_${drone_namespaces[@]}.txt"
if [[ ${use_gnome} == "true" ]]; then
tmuxinator_mode="debug"
tmuxinator_end="> ${tmp_file} && python3 utils/tmuxinator_to_genome.py -p ${tmp_file} && wait"
fi
# Launch aerostack2 for each drone namespace
for namespace in ${drone_namespaces[@]}; do
base_launch="false"
if [[ ${namespace} == ${drone_namespaces[0]} ]]; then
base_launch="true"
fi
eval "tmuxinator ${tmuxinator_mode} -n ${namespace} -p tmuxinator/aerostack2.yaml \
drone_namespace=${namespace} \
drone_namespace_list=${drones_namespace_comma} \
simulation_config_file=${simulation_config} \
motion_controller_plugin=${motion_controller_plugin} \
as2_config_file=${as2_config_file} \
rviz_config_file=${rviz_config}\
mission_file=${mission_file} \
base_launch=${base_launch} \
${tmuxinator_end}"
sleep 0.1 # Wait for tmuxinator to finish
done
if [[ ${record_rosbag} == "true" ]]; then
tmuxinator start -p tmuxinator/rosbag.yml \
drones=${drones_namespace_comma} &
wait
fi
# Attach to tmux session
if [[ ${use_gnome} == "false" ]]; then
tmux attach-session -t ${drone_namespaces[0]}
# If tmp_file exists, remove it
elif [[ -f ${tmp_file} ]]; then
rm ${tmp_file}
fi