@@ -27,10 +27,10 @@ class Result(Enum):
27
27
Values
28
28
------
29
29
UNKNOWN
30
- Unknown error
30
+ Unknown result
31
31
32
32
SUCCESS
33
- Success: the action command was accepted by the vehicle
33
+ Request was successful
34
34
35
35
NO_SYSTEM
36
36
No system is connected
@@ -54,7 +54,7 @@ class Result(Enum):
54
54
Request timed out
55
55
56
56
VTOL_TRANSITION_SUPPORT_UNKNOWN
57
- Hybrid/VTOL transition refused because VTOL support is unknown
57
+ Hybrid/VTOL transition support is unknown
58
58
59
59
NO_VTOL_TRANSITION_SUPPORT
60
60
Vehicle does not support hybrid/VTOL transitions
@@ -79,38 +79,58 @@ class Result(Enum):
79
79
PARAMETER_ERROR = 11
80
80
81
81
def translate_to_rpc (self , rpcResult ):
82
- return {
83
- 0 : action_pb2 .ActionResult .UNKNOWN ,
84
- 1 : action_pb2 .ActionResult .SUCCESS ,
85
- 2 : action_pb2 .ActionResult .NO_SYSTEM ,
86
- 3 : action_pb2 .ActionResult .CONNECTION_ERROR ,
87
- 4 : action_pb2 .ActionResult .BUSY ,
88
- 5 : action_pb2 .ActionResult .COMMAND_DENIED ,
89
- 6 : action_pb2 .ActionResult .COMMAND_DENIED_LANDED_STATE_UNKNOWN ,
90
- 7 : action_pb2 .ActionResult .COMMAND_DENIED_NOT_LANDED ,
91
- 8 : action_pb2 .ActionResult .TIMEOUT ,
92
- 9 : action_pb2 .ActionResult .VTOL_TRANSITION_SUPPORT_UNKNOWN ,
93
- 10 : action_pb2 .ActionResult .NO_VTOL_TRANSITION_SUPPORT ,
94
- 11 : action_pb2 .ActionResult .PARAMETER_ERROR
95
- }.get (self .value , None )
82
+ if self == ActionResult .Result .UNKNOWN :
83
+ return action_pb2 .ActionResult .RESULT_UNKNOWN
84
+ if self == ActionResult .Result .SUCCESS :
85
+ return action_pb2 .ActionResult .RESULT_SUCCESS
86
+ if self == ActionResult .Result .NO_SYSTEM :
87
+ return action_pb2 .ActionResult .RESULT_NO_SYSTEM
88
+ if self == ActionResult .Result .CONNECTION_ERROR :
89
+ return action_pb2 .ActionResult .RESULT_CONNECTION_ERROR
90
+ if self == ActionResult .Result .BUSY :
91
+ return action_pb2 .ActionResult .RESULT_BUSY
92
+ if self == ActionResult .Result .COMMAND_DENIED :
93
+ return action_pb2 .ActionResult .RESULT_COMMAND_DENIED
94
+ if self == ActionResult .Result .COMMAND_DENIED_LANDED_STATE_UNKNOWN :
95
+ return action_pb2 .ActionResult .RESULT_COMMAND_DENIED_LANDED_STATE_UNKNOWN
96
+ if self == ActionResult .Result .COMMAND_DENIED_NOT_LANDED :
97
+ return action_pb2 .ActionResult .RESULT_COMMAND_DENIED_NOT_LANDED
98
+ if self == ActionResult .Result .TIMEOUT :
99
+ return action_pb2 .ActionResult .RESULT_TIMEOUT
100
+ if self == ActionResult .Result .VTOL_TRANSITION_SUPPORT_UNKNOWN :
101
+ return action_pb2 .ActionResult .RESULT_VTOL_TRANSITION_SUPPORT_UNKNOWN
102
+ if self == ActionResult .Result .NO_VTOL_TRANSITION_SUPPORT :
103
+ return action_pb2 .ActionResult .RESULT_NO_VTOL_TRANSITION_SUPPORT
104
+ if self == ActionResult .Result .PARAMETER_ERROR :
105
+ return action_pb2 .ActionResult .RESULT_PARAMETER_ERROR
96
106
97
107
@staticmethod
98
108
def translate_from_rpc (rpc_enum_value ):
99
109
""" Parses a gRPC response """
100
- return {
101
- 0 : ActionResult .Result .UNKNOWN ,
102
- 1 : ActionResult .Result .SUCCESS ,
103
- 2 : ActionResult .Result .NO_SYSTEM ,
104
- 3 : ActionResult .Result .CONNECTION_ERROR ,
105
- 4 : ActionResult .Result .BUSY ,
106
- 5 : ActionResult .Result .COMMAND_DENIED ,
107
- 6 : ActionResult .Result .COMMAND_DENIED_LANDED_STATE_UNKNOWN ,
108
- 7 : ActionResult .Result .COMMAND_DENIED_NOT_LANDED ,
109
- 8 : ActionResult .Result .TIMEOUT ,
110
- 9 : ActionResult .Result .VTOL_TRANSITION_SUPPORT_UNKNOWN ,
111
- 10 : ActionResult .Result .NO_VTOL_TRANSITION_SUPPORT ,
112
- 11 : ActionResult .Result .PARAMETER_ERROR ,
113
- }.get (rpc_enum_value , None )
110
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_UNKNOWN :
111
+ return ActionResult .Result .UNKNOWN
112
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_SUCCESS :
113
+ return ActionResult .Result .SUCCESS
114
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_NO_SYSTEM :
115
+ return ActionResult .Result .NO_SYSTEM
116
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_CONNECTION_ERROR :
117
+ return ActionResult .Result .CONNECTION_ERROR
118
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_BUSY :
119
+ return ActionResult .Result .BUSY
120
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_COMMAND_DENIED :
121
+ return ActionResult .Result .COMMAND_DENIED
122
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_COMMAND_DENIED_LANDED_STATE_UNKNOWN :
123
+ return ActionResult .Result .COMMAND_DENIED_LANDED_STATE_UNKNOWN
124
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_COMMAND_DENIED_NOT_LANDED :
125
+ return ActionResult .Result .COMMAND_DENIED_NOT_LANDED
126
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_TIMEOUT :
127
+ return ActionResult .Result .TIMEOUT
128
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_VTOL_TRANSITION_SUPPORT_UNKNOWN :
129
+ return ActionResult .Result .VTOL_TRANSITION_SUPPORT_UNKNOWN
130
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_NO_VTOL_TRANSITION_SUPPORT :
131
+ return ActionResult .Result .NO_VTOL_TRANSITION_SUPPORT
132
+ if rpc_enum_value == action_pb2 .ActionResult .RESULT_PARAMETER_ERROR :
133
+ return ActionResult .Result .PARAMETER_ERROR
114
134
115
135
def __str__ (self ):
116
136
return self .name
@@ -257,7 +277,7 @@ async def takeoff(self):
257
277
"""
258
278
Send command to take off and hover.
259
279
260
- This switches the drone into position control mode and commands
280
+ This switches the drone into position control mode and commands
261
281
it to take off and hover at the takeoff altitude.
262
282
263
283
Note that the vehicle must be armed before it can take off.
@@ -322,9 +342,33 @@ async def reboot(self):
322
342
raise ActionError (result , "reboot()" )
323
343
324
344
345
+ async def shutdown (self ):
346
+ """
347
+ Send command to shut down the drone components.
348
+
349
+ This will shut down the autopilot, onboard computer, camera and gimbal.
350
+ This command should only be used when the autopilot is disarmed and autopilots commonly
351
+ reject it if they are not already ready to shut down.
352
+
353
+ Raises
354
+ ------
355
+ ActionError
356
+ If the request fails. The error contains the reason for the failure.
357
+ """
358
+
359
+ request = action_pb2 .ShutdownRequest ()
360
+ response = await self ._stub .Shutdown (request )
361
+
362
+
363
+ result = self ._extract_result (response )
364
+
365
+ if result .result is not ActionResult .Result .SUCCESS :
366
+ raise ActionError (result , "shutdown()" )
367
+
368
+
325
369
async def kill (self ):
326
370
"""
327
- Send command to kill the drone.
371
+ Send command to kill the drone.
328
372
329
373
This will disarm a drone irrespective of whether it is landed or flying.
330
374
Note that the drone will fall out of the sky if this command is used while flying.
@@ -349,7 +393,7 @@ async def return_to_launch(self):
349
393
"""
350
394
Send command to return to the launch (takeoff) position and land.
351
395
352
- This switches the drone into [RTL mode](https://docs.px4.io/en/flight_modes/rtl .html) which
396
+ This switches the drone into [Return mode](https://docs.px4.io/master/ en/flight_modes/return .html) which
353
397
generally means it will rise up to a certain altitude to clear any obstacles before heading
354
398
back to the launch (takeoff) position and land there.
355
399
@@ -369,7 +413,50 @@ async def return_to_launch(self):
369
413
raise ActionError (result , "return_to_launch()" )
370
414
371
415
372
- async def transition_to_fixed_wing (self ):
416
+ async def goto_location (self , latitude_deg , longitude_deg , absolute_altitude_m , yaw_deg ):
417
+ """
418
+ Send command to move the vehicle to a specific global position.
419
+
420
+ The latitude and longitude are given in degrees (WGS84 frame) and the altitude
421
+ in meters AMSL (above mean sea level).
422
+
423
+ The yaw angle is in degrees (frame is NED, 0 is North, positive is clockwise).
424
+
425
+ Parameters
426
+ ----------
427
+ latitude_deg : double
428
+ Latitude (in degrees)
429
+
430
+ longitude_deg : double
431
+ Longitude (in degrees)
432
+
433
+ absolute_altitude_m : float
434
+ Altitude AMSL (in meters)
435
+
436
+ yaw_deg : float
437
+ Yaw angle (in degrees, frame is NED, 0 is North, positive is clockwise)
438
+
439
+ Raises
440
+ ------
441
+ ActionError
442
+ If the request fails. The error contains the reason for the failure.
443
+ """
444
+
445
+ request = action_pb2 .GotoLocationRequest ()
446
+ request .latitude_deg = latitude_deg
447
+ request .longitude_deg = longitude_deg
448
+ request .absolute_altitude_m = absolute_altitude_m
449
+ request .yaw_deg = yaw_deg
450
+ response = await self ._stub .GotoLocation (request )
451
+
452
+
453
+ result = self ._extract_result (response )
454
+
455
+ if result .result is not ActionResult .Result .SUCCESS :
456
+ raise ActionError (result , "goto_location()" , latitude_deg , longitude_deg , absolute_altitude_m , yaw_deg )
457
+
458
+
459
+ async def transition_to_fixedwing (self ):
373
460
"""
374
461
Send command to transition the drone to fixedwing.
375
462
@@ -383,14 +470,14 @@ async def transition_to_fixed_wing(self):
383
470
If the request fails. The error contains the reason for the failure.
384
471
"""
385
472
386
- request = action_pb2 .TransitionToFixedWingRequest ()
387
- response = await self ._stub .TransitionToFixedWing (request )
473
+ request = action_pb2 .TransitionToFixedwingRequest ()
474
+ response = await self ._stub .TransitionToFixedwing (request )
388
475
389
476
390
477
result = self ._extract_result (response )
391
478
392
479
if result .result is not ActionResult .Result .SUCCESS :
393
- raise ActionError (result , "transition_to_fixed_wing ()" )
480
+ raise ActionError (result , "transition_to_fixedwing ()" )
394
481
395
482
396
483
async def transition_to_multicopter (self ):
0 commit comments