1
1
# -*- coding: utf-8 -*-
2
2
3
- from .async_plugin_manager import AsyncPluginManager # NOQA
4
- from .generated import * # NOQA
3
+ from .async_plugin_manager import AsyncPluginManager
4
+ from .generated import Action
5
+ from .generated import Calibration
6
+ from .generated import Camera
7
+ from .generated import Core
8
+ from .generated import FollowMe
9
+ from .generated import Ftp
10
+ from .generated import Geofence
11
+ from .generated import Gimbal
12
+ from .generated import Info
13
+ from .generated import LogFiles
14
+ from .generated import Mission
15
+ from .generated import MissionRaw
16
+ from .generated import Mocap
17
+ from .generated import Offboard
18
+ from .generated import Param
19
+ from .generated import Shell
20
+ from .generated import Telemetry
21
+ from .generated import Tune
5
22
6
23
from . import bin
7
24
@@ -12,15 +29,20 @@ class System:
12
29
"Calibration" ,
13
30
"Camera" ,
14
31
"Core" ,
32
+ "FollowMe" ,
33
+ "Ftp" ,
15
34
"Geofence" ,
16
35
"Gimbal" ,
17
36
"Info" ,
37
+ "LogFiles" ,
18
38
"Mission" ,
39
+ "MissionRaw" ,
19
40
"Mocap" ,
20
- "Param" ,
21
41
"Offboard" ,
42
+ "Param" ,
22
43
"Shell" ,
23
- "Telemetry"
44
+ "Telemetry" ,
45
+ "Tune" ,
24
46
]
25
47
26
48
def __init__ (self , mavsdk_server_address = None , port = 50051 ):
@@ -71,83 +93,118 @@ async def _init_plugins(self, host, port):
71
93
for plugin in self ._core_plugins :
72
94
self ._plugins [plugin .lower ()] = globals ()[plugin ](plugin_manager )
73
95
96
+ @staticmethod
97
+ def error_uninitialized (plugin_name : str ) -> str :
98
+ return "{plugin_name} plugin has not been initialized!" \
99
+ "Did you run `System.connect()`?"
100
+
74
101
@property
75
102
def action (self ) -> Action :
76
103
if "action" not in self ._plugins :
77
- raise RuntimeError ("Action plugin has not been initialized! Did you run `System.connect()`?" )
104
+ raise RuntimeError (self . error_uninitialized ( "Action" ) )
78
105
return self ._plugins ["action" ]
79
106
80
107
@property
81
108
def calibration (self ) -> Calibration :
82
109
if "calibration" not in self ._plugins :
83
- raise RuntimeError ("Calibration plugin has not been initialized! Did you run `System.connect()`?" )
110
+ raise RuntimeError (self . error_uninitialized ( "Calibration" ) )
84
111
return self ._plugins ["calibration" ]
85
112
86
113
@property
87
114
def camera (self ) -> Camera :
88
115
if "camera" not in self ._plugins :
89
- raise RuntimeError ("Camera plugin has not been initialized! Did you run `System.connect()`?" )
116
+ raise RuntimeError (self . error_uninitialized ( "Camera" ) )
90
117
return self ._plugins ["camera" ]
91
118
92
119
@property
93
120
def core (self ) -> Core :
94
121
if "core" not in self ._plugins :
95
- raise RuntimeError ("Core plugin has not been initialized! Did you run `System.connect()`?" )
122
+ raise RuntimeError (self . error_uninitialized ( "Core" ) )
96
123
return self ._plugins ["core" ]
97
124
125
+ @property
126
+ def follow_me (self ) -> FollowMe :
127
+ if "follow_me" not in self ._plugins :
128
+ raise RuntimeError (self .error_uninitialized ("FollowMe" ))
129
+ return self ._plugins ["follow_me" ]
130
+
131
+ @property
132
+ def ftp (self ) -> Ftp :
133
+ if "ftp" not in self ._plugins :
134
+ raise RuntimeError (self .error_uninitialized ("Ftp" ))
135
+ return self ._plugins ["Ftp" ]
136
+
98
137
@property
99
138
def geofence (self ) -> Geofence :
100
139
if "geofence" not in self ._plugins :
101
- raise RuntimeError ("Geofence plugin has not been initialized! Did you run `System.connect()`?" )
140
+ raise RuntimeError (self . error_uninitialized ( "Geofence" ) )
102
141
return self ._plugins ["geofence" ]
103
142
104
143
@property
105
144
def gimbal (self ) -> Gimbal :
106
145
if "gimbal" not in self ._plugins :
107
- raise RuntimeError ("Gimbal plugin has not been initialized! Did you run `System.connect()`?" )
146
+ raise RuntimeError (self . error_uninitialized ( "Gimbal" ) )
108
147
return self ._plugins ["gimbal" ]
109
148
110
149
@property
111
150
def info (self ) -> Info :
112
151
if "info" not in self ._plugins :
113
- raise RuntimeError ("Info plugin has not been initialized! Did you run `System.connect()`?" )
152
+ raise RuntimeError (self . error_uninitialized ( "Info" ) )
114
153
return self ._plugins ["info" ]
115
154
155
+ @property
156
+ def log_files (self ) -> LogFiles :
157
+ if "log_files" not in self ._plugins :
158
+ raise RuntimeError (self .error_uninitialized ("LogFiles" ))
159
+ return self ._plugins ["log_files" ]
160
+
116
161
@property
117
162
def mission (self ) -> Mission :
118
163
if "mission" not in self ._plugins :
119
- raise RuntimeError ("Mission plugin has not been initialized! Did you run `System.connect()`?" )
164
+ raise RuntimeError (self . error_uninitialized ( "Mission" ) )
120
165
return self ._plugins ["mission" ]
121
166
122
167
@property
123
- def param (self ) -> Param :
124
- if "param" not in self ._plugins :
125
- raise RuntimeError ("Param plugin has not been initialized! Did you run `System.connect()`?" )
126
- return self ._plugins ["param" ]
168
+ def mission_raw (self ) -> MissionRaw :
169
+ if "mission_raw" not in self ._plugins :
170
+ raise RuntimeError (self .error_uninitialized ("MissionRaw" ))
171
+ return self ._plugins ["mission_raw" ]
172
+
173
+ @property
174
+ def mocap (self ) -> Mocap :
175
+ if "mocap" not in self ._plugins :
176
+ raise RuntimeError (self .error_uninitialized ("Mocap" ))
177
+ return self ._plugins ["mocap" ]
127
178
128
179
@property
129
180
def offboard (self ) -> Offboard :
130
181
if "offboard" not in self ._plugins :
131
- raise RuntimeError ("Offboard plugin has not been initialized! Did you run `System.connect()`?" )
182
+ raise RuntimeError (self . error_uninitialized ( "Offboard" ) )
132
183
return self ._plugins ["offboard" ]
133
184
134
185
@property
135
- def telemetry (self ) -> Telemetry :
136
- if "telemetry " not in self ._plugins :
137
- raise RuntimeError ("Telemetry plugin has not been initialized! Did you run `System.connect()`?" )
138
- return self ._plugins ["telemetry " ]
186
+ def param (self ) -> Param :
187
+ if "param " not in self ._plugins :
188
+ raise RuntimeError (self . error_uninitialized ( "Param" ) )
189
+ return self ._plugins ["param " ]
139
190
140
191
@property
141
192
def shell (self ) -> Shell :
142
193
if "shell" not in self ._plugins :
143
- raise RuntimeError ("Shell plugin has not been initialized! Did you run `System.connect()`?" )
194
+ raise RuntimeError (self . error_uninitialized ( "Shell" ) )
144
195
return self ._plugins ["shell" ]
145
196
146
197
@property
147
- def mocap (self ) -> Mocap :
148
- if "mocap" not in self ._plugins :
149
- raise RuntimeError ("Mocap plugin has not been initialized! Did you run `System.connect()`?" )
150
- return self ._plugins ["mocap" ]
198
+ def telemetry (self ) -> Telemetry :
199
+ if "telemetry" not in self ._plugins :
200
+ raise RuntimeError (self .error_uninitialized ("Telemetry" ))
201
+ return self ._plugins ["telemetry" ]
202
+
203
+ @property
204
+ def tune (self ) -> Tune :
205
+ if "tune" not in self ._plugins :
206
+ raise RuntimeError (self .error_uninitialized ("Tune" ))
207
+ return self ._plugins ["tune" ]
151
208
152
209
@staticmethod
153
210
def _start_mavsdk_server (system_address = None ):
@@ -174,8 +231,23 @@ def _start_mavsdk_server(system_address=None):
174
231
stdout = subprocess .DEVNULL ,
175
232
stderr = subprocess .DEVNULL )
176
233
except FileNotFoundError :
177
- raise Exception ("\n It seems like this installation does not provide an embedded 'mavsdk_server' binary. If you installed from pip, it means that 'mavsdk_server' is not distributed for your platform (yet). You will need to get and run it manually:\n \n \t 1. Build 'mavsdk_server': https://github.com/mavlink/mavsdk.\n \t 2. Run it, e.g. on port 50051: './mavsdk_server -p 50051'.\n \t 3. Set the 'mavsdk_server_address' and port when creating the System: 'drone = System(mavsdk_server_address='localhost', port=50051)\n " )
234
+ print ("""
235
+ This installation does not provide an embedded 'mavsdk_server' binary.
236
+ If you installed using pip, this means that 'mavsdk_server' is not distributed
237
+ for your platform yet (e.g. arm).
238
+
239
+ You will need to get and run the 'mavsdk_server' binary manually:
240
+
241
+ 1. Download 'mavsdk_server' from: https://github.com/mavlink/mavsdk/releases
242
+ or build it from source.
243
+
244
+ 2. Run it, e.g. on port 50051:
245
+ './mavsdk_server -p 50051'
178
246
247
+ 3. Set the 'mavsdk_server_address' and port when creating the System:
248
+ 'drone = System(mavsdk_server_address='localhost', port=50051)'
249
+ """ )
250
+ sys .exit (1 )
179
251
180
252
def cleanup ():
181
253
p .kill ()
0 commit comments