-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_sitl_px4.sh
executable file
·91 lines (60 loc) · 1.85 KB
/
run_sitl_px4.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
#!/bin/bash
export PX4_SIM_SPEED_FACTOR=10
export AUTOSTART_SITL=1
export PX4_FIRMWARE_DIR=$PX4_FIRMWARE_DIR
export HEADLESS=1
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$#" -ne 1 ]; then
echo "Model argument needed"
exit 1
fi
sitl_model=$1
echo "SITL model: $sitl_model"
sitl_world="empty"
set -e
# This script spawns the Gazebo PX4 software in the loop (SITL) simulation.
# Options:
# AUTOSTART_SITL=1 if SITL is started manually or real hardware is used.
# PX4_FIRMWARE_DIR=<path> to specify where the source of the PX4 Firmware is.
# HEADLESS=1 if you don't need the simulation viewer.
if [[ $AUTOSTART_SITL != 1 ]]; then
echo "Not autostarting SITL (use AUTOSTART_SITL=1)"
exit 0
fi
if [[ -n "$PX4_FIRMWARE_DIR" ]]; then
px4_firmware_dir=$PX4_FIRMWARE_DIR
else
# Try to use the default path on the same folder level.
px4_firmware_dir=`realpath ../Firmware`
fi
# Make sure everything is stopped first.
${script_dir}/stop_px4_sitl.sh
# To prevent any races.
sleep 1
current_dir=$(pwd)
log_dir=$current_dir/logs
# Create log dir in case it doesn't exist yet
mkdir -p $log_dir
# No user input needed, run it in deamon mode.
export NO_PXH=1
# The logs are saved with a timestamp.
timestamp=`date +%Y-%m-%dT%H-%M-%S%z`
# Before changing dir, save where we start from.
pushd .
# Go to Firmware build dir.
cd $px4_firmware_dir/build/px4_sitl_default/tmp/rootfs
# 1.11 onwards requires the world argument
$px4_firmware_dir/Tools/sitl_run.sh \
$px4_firmware_dir/build/px4_sitl_default/bin/px4 \
none \
gazebo \
$sitl_model \
$sitl_world \
$px4_firmware_dir \
$px4_firmware_dir/build/px4_sitl_default &
# Go back to dir where we started
popd
echo "waiting for SITL to be running"
sleep 10
echo "done"
# /home/user/tools/examples/apm_missions/build/apm_missions udp://:14540