CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/run_mission.py
Views: 1798
1
#!/usr/bin/env python3
2
3
'''
4
Run a mission in SITL
5
6
AP_FLAKE8_CLEAN
7
'''
8
9
import vehicle_test_suite
10
import os
11
import sys
12
import argparse
13
14
from pysim import util
15
16
17
class RunMission(vehicle_test_suite.TestSuite):
18
def __init__(self, vehicle_binary, model, mission_filepath, speedup=None, sim_rate_hz=None):
19
super(RunMission, self).__init__(vehicle_binary)
20
self.mission_filepath = mission_filepath
21
self.model = model
22
self.speedup = speedup
23
self.sim_rate_hz = sim_rate_hz
24
25
if self.speedup is None:
26
self.speedup = 100
27
28
def vehicleinfo_key(self):
29
'''magically guess vehicleinfo_key from filepath'''
30
path = self.binary.lower()
31
if "plane" in path:
32
return "ArduPlane"
33
if "copter" in path:
34
return "ArduCopter"
35
raise ValueError("Can't determine vehicleinfo_key from binary path")
36
37
def run(self):
38
self.start_SITL(
39
binary=self.binary,
40
model=self.model,
41
sitl_home=self.sitl_home_string_from_mission_filepath(self.mission_filepath),
42
speedup=self.speedup,
43
sim_rate_hz=self.sim_rate_hz,
44
defaults_filepath=self.model_defaults_filepath(self.model),
45
)
46
self.get_mavlink_connection_going()
47
48
# hack; Plane defaults are annoying... we should do better
49
# here somehow.
50
if self.vehicleinfo_key() == "ArduPlane":
51
self.set_parameter("RTL_AUTOLAND", 1)
52
53
self.load_mission_from_filepath(self.mission_filepath, strict=False)
54
self.change_mode('AUTO')
55
self.set_streamrate(1)
56
self.wait_ready_to_arm()
57
self.arm_vehicle()
58
self.wait_disarmed(timeout=600)
59
self.stop_SITL()
60
61
62
if __name__ == "__main__":
63
''' main program '''
64
os.environ['PYTHONUNBUFFERED'] = '1'
65
66
if sys.platform != "darwin":
67
os.putenv('TMPDIR', util.reltopdir('tmp'))
68
69
parser = argparse.ArgumentParser("run_mission.py")
70
parser.add_argument(
71
'vehicle_binary',
72
type=str,
73
help='vehicle binary to use'
74
)
75
parser.add_argument(
76
'model',
77
type=str,
78
help='vehicle model to use'
79
)
80
parser.add_argument(
81
'mission_filepath',
82
type=str,
83
help='mission file path'
84
)
85
parser.add_argument(
86
'--speedup',
87
type=int,
88
help='simulation speedup',
89
default=None,
90
)
91
parser.add_argument(
92
'--sim-rate-hz',
93
type=int,
94
help='simulation physics rate',
95
default=None,
96
)
97
98
args = parser.parse_args()
99
100
x = RunMission(
101
args.vehicle_binary,
102
args.model,
103
args.mission_filepath,
104
speedup=args.speedup,
105
sim_rate_hz=args.sim_rate_hz
106
)
107
x.run()
108
109