Skip to content

Commit 8320ad7

Browse files
authored
Merge pull request #676 from mavlink/pr-update-to-2.7.0
Update to mavsdk_server v2.7.0
2 parents 3592858 + a19ff37 commit 8320ad7

13 files changed

+1484
-20
lines changed

MAVSDK_SERVER_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.6.0
1+
v2.7.0

mavsdk/action.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class Result(Enum):
130130
FAILED
131131
Action failed
132132
133+
INVALID_ARGUMENT
134+
Invalid argument
135+
133136
"""
134137

135138

@@ -147,6 +150,7 @@ class Result(Enum):
147150
PARAMETER_ERROR = 11
148151
UNSUPPORTED = 12
149152
FAILED = 13
153+
INVALID_ARGUMENT = 14
150154

151155
def translate_to_rpc(self):
152156
if self == ActionResult.Result.UNKNOWN:
@@ -177,6 +181,8 @@ def translate_to_rpc(self):
177181
return action_pb2.ActionResult.RESULT_UNSUPPORTED
178182
if self == ActionResult.Result.FAILED:
179183
return action_pb2.ActionResult.RESULT_FAILED
184+
if self == ActionResult.Result.INVALID_ARGUMENT:
185+
return action_pb2.ActionResult.RESULT_INVALID_ARGUMENT
180186

181187
@staticmethod
182188
def translate_from_rpc(rpc_enum_value):
@@ -209,6 +215,8 @@ def translate_from_rpc(rpc_enum_value):
209215
return ActionResult.Result.UNSUPPORTED
210216
if rpc_enum_value == action_pb2.ActionResult.RESULT_FAILED:
211217
return ActionResult.Result.FAILED
218+
if rpc_enum_value == action_pb2.ActionResult.RESULT_INVALID_ARGUMENT:
219+
return ActionResult.Result.INVALID_ARGUMENT
212220

213221
def __str__(self):
214222
return self.name
@@ -637,6 +645,8 @@ async def set_actuator(self, index, value):
637645
"""
638646
Send command to set the value of an actuator.
639647
648+
Note that the index of the actuator starts at 1 and that the value goes from -1 to 1.
649+
640650
Parameters
641651
----------
642652
index : int32_t

mavsdk/action_pb2.py

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mavsdk/action_pb2_grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ def Hold(self, request, context):
271271
def SetActuator(self, request, context):
272272
"""
273273
Send command to set the value of an actuator.
274+
275+
Note that the index of the actuator starts at 1 and that the value goes from -1 to 1.
274276
"""
275277
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
276278
context.set_details('Method not implemented!')

mavsdk/arm_authorizer_server.py

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
# -*- coding: utf-8 -*-
2+
# DO NOT EDIT! This file is auto-generated from
3+
# https://github.com/mavlink/MAVSDK-Python/tree/main/other/templates/py
4+
from ._base import AsyncBase
5+
from . import arm_authorizer_server_pb2, arm_authorizer_server_pb2_grpc
6+
from enum import Enum
7+
8+
9+
class RejectionReason(Enum):
10+
"""
11+
12+
13+
Values
14+
------
15+
GENERIC
16+
Not a specific reason
17+
18+
NONE
19+
Authorizer will send the error as string to GCS
20+
21+
INVALID_WAYPOINT
22+
At least one waypoint have a invalid value
23+
24+
TIMEOUT
25+
Timeout in the authorizer process(in case it depends on network)
26+
27+
AIRSPACE_IN_USE
28+
Airspace of the mission in use by another vehicle, second result parameter can have the waypoint id that caused it to be denied.
29+
30+
BAD_WEATHER
31+
Weather is not good to fly
32+
33+
"""
34+
35+
36+
GENERIC = 0
37+
NONE = 1
38+
INVALID_WAYPOINT = 2
39+
TIMEOUT = 3
40+
AIRSPACE_IN_USE = 4
41+
BAD_WEATHER = 5
42+
43+
def translate_to_rpc(self):
44+
if self == RejectionReason.GENERIC:
45+
return arm_authorizer_server_pb2.REJECTION_REASON_GENERIC
46+
if self == RejectionReason.NONE:
47+
return arm_authorizer_server_pb2.REJECTION_REASON_NONE
48+
if self == RejectionReason.INVALID_WAYPOINT:
49+
return arm_authorizer_server_pb2.REJECTION_REASON_INVALID_WAYPOINT
50+
if self == RejectionReason.TIMEOUT:
51+
return arm_authorizer_server_pb2.REJECTION_REASON_TIMEOUT
52+
if self == RejectionReason.AIRSPACE_IN_USE:
53+
return arm_authorizer_server_pb2.REJECTION_REASON_AIRSPACE_IN_USE
54+
if self == RejectionReason.BAD_WEATHER:
55+
return arm_authorizer_server_pb2.REJECTION_REASON_BAD_WEATHER
56+
57+
@staticmethod
58+
def translate_from_rpc(rpc_enum_value):
59+
""" Parses a gRPC response """
60+
if rpc_enum_value == arm_authorizer_server_pb2.REJECTION_REASON_GENERIC:
61+
return RejectionReason.GENERIC
62+
if rpc_enum_value == arm_authorizer_server_pb2.REJECTION_REASON_NONE:
63+
return RejectionReason.NONE
64+
if rpc_enum_value == arm_authorizer_server_pb2.REJECTION_REASON_INVALID_WAYPOINT:
65+
return RejectionReason.INVALID_WAYPOINT
66+
if rpc_enum_value == arm_authorizer_server_pb2.REJECTION_REASON_TIMEOUT:
67+
return RejectionReason.TIMEOUT
68+
if rpc_enum_value == arm_authorizer_server_pb2.REJECTION_REASON_AIRSPACE_IN_USE:
69+
return RejectionReason.AIRSPACE_IN_USE
70+
if rpc_enum_value == arm_authorizer_server_pb2.REJECTION_REASON_BAD_WEATHER:
71+
return RejectionReason.BAD_WEATHER
72+
73+
def __str__(self):
74+
return self.name
75+
76+
77+
class ArmAuthorizerServerResult:
78+
"""
79+
80+
81+
Parameters
82+
----------
83+
result : Result
84+
Result enum value
85+
86+
result_str : std::string
87+
Human-readable English string describing the result
88+
89+
"""
90+
91+
92+
93+
class Result(Enum):
94+
"""
95+
96+
97+
Values
98+
------
99+
UNKNOWN
100+
Unknown result
101+
102+
SUCCESS
103+
Command accepted
104+
105+
FAILED
106+
Command failed
107+
108+
"""
109+
110+
111+
UNKNOWN = 0
112+
SUCCESS = 1
113+
FAILED = 2
114+
115+
def translate_to_rpc(self):
116+
if self == ArmAuthorizerServerResult.Result.UNKNOWN:
117+
return arm_authorizer_server_pb2.ArmAuthorizerServerResult.RESULT_UNKNOWN
118+
if self == ArmAuthorizerServerResult.Result.SUCCESS:
119+
return arm_authorizer_server_pb2.ArmAuthorizerServerResult.RESULT_SUCCESS
120+
if self == ArmAuthorizerServerResult.Result.FAILED:
121+
return arm_authorizer_server_pb2.ArmAuthorizerServerResult.RESULT_FAILED
122+
123+
@staticmethod
124+
def translate_from_rpc(rpc_enum_value):
125+
""" Parses a gRPC response """
126+
if rpc_enum_value == arm_authorizer_server_pb2.ArmAuthorizerServerResult.RESULT_UNKNOWN:
127+
return ArmAuthorizerServerResult.Result.UNKNOWN
128+
if rpc_enum_value == arm_authorizer_server_pb2.ArmAuthorizerServerResult.RESULT_SUCCESS:
129+
return ArmAuthorizerServerResult.Result.SUCCESS
130+
if rpc_enum_value == arm_authorizer_server_pb2.ArmAuthorizerServerResult.RESULT_FAILED:
131+
return ArmAuthorizerServerResult.Result.FAILED
132+
133+
def __str__(self):
134+
return self.name
135+
136+
137+
def __init__(
138+
self,
139+
result,
140+
result_str):
141+
""" Initializes the ArmAuthorizerServerResult object """
142+
self.result = result
143+
self.result_str = result_str
144+
145+
def __eq__(self, to_compare):
146+
""" Checks if two ArmAuthorizerServerResult are the same """
147+
try:
148+
# Try to compare - this likely fails when it is compared to a non
149+
# ArmAuthorizerServerResult object
150+
return \
151+
(self.result == to_compare.result) and \
152+
(self.result_str == to_compare.result_str)
153+
154+
except AttributeError:
155+
return False
156+
157+
def __str__(self):
158+
""" ArmAuthorizerServerResult in string representation """
159+
struct_repr = ", ".join([
160+
"result: " + str(self.result),
161+
"result_str: " + str(self.result_str)
162+
])
163+
164+
return f"ArmAuthorizerServerResult: [{struct_repr}]"
165+
166+
@staticmethod
167+
def translate_from_rpc(rpcArmAuthorizerServerResult):
168+
""" Translates a gRPC struct to the SDK equivalent """
169+
return ArmAuthorizerServerResult(
170+
171+
ArmAuthorizerServerResult.Result.translate_from_rpc(rpcArmAuthorizerServerResult.result),
172+
173+
174+
rpcArmAuthorizerServerResult.result_str
175+
)
176+
177+
def translate_to_rpc(self, rpcArmAuthorizerServerResult):
178+
""" Translates this SDK object into its gRPC equivalent """
179+
180+
181+
182+
183+
rpcArmAuthorizerServerResult.result = self.result.translate_to_rpc()
184+
185+
186+
187+
188+
189+
rpcArmAuthorizerServerResult.result_str = self.result_str
190+
191+
192+
193+
194+
195+
196+
class ArmAuthorizerServerError(Exception):
197+
""" Raised when a ArmAuthorizerServerResult is a fail code """
198+
199+
def __init__(self, result, origin, *params):
200+
self._result = result
201+
self._origin = origin
202+
self._params = params
203+
204+
def __str__(self):
205+
return f"{self._result.result}: '{self._result.result_str}'; origin: {self._origin}; params: {self._params}"
206+
207+
208+
class ArmAuthorizerServer(AsyncBase):
209+
"""
210+
211+
212+
Generated by dcsdkgen - MAVSDK ArmAuthorizerServer API
213+
"""
214+
215+
# Plugin name
216+
name = "ArmAuthorizerServer"
217+
218+
def _setup_stub(self, channel):
219+
""" Setups the api stub """
220+
self._stub = arm_authorizer_server_pb2_grpc.ArmAuthorizerServerServiceStub(channel)
221+
222+
223+
def _extract_result(self, response):
224+
""" Returns the response status and description """
225+
return ArmAuthorizerServerResult.translate_from_rpc(response.arm_authorizer_server_result)
226+
227+
228+
async def arm_authorization(self):
229+
"""
230+
Subscribe to arm authorization request messages. Each request received should respond to using RespondArmAuthorization
231+
232+
Yields
233+
-------
234+
system_id : uint32_t
235+
vehicle system id
236+
237+
238+
"""
239+
240+
request = arm_authorizer_server_pb2.SubscribeArmAuthorizationRequest()
241+
arm_authorization_stream = self._stub.SubscribeArmAuthorization(request)
242+
243+
try:
244+
async for response in arm_authorization_stream:
245+
246+
247+
248+
yield response.system_id
249+
finally:
250+
arm_authorization_stream.cancel()
251+
252+
async def accept_arm_authorization(self, valid_time_s):
253+
"""
254+
Authorize arm for the specific time
255+
256+
Parameters
257+
----------
258+
valid_time_s : int32_t
259+
Time in seconds for which this authorization is valid
260+
261+
Raises
262+
------
263+
ArmAuthorizerServerError
264+
If the request fails. The error contains the reason for the failure.
265+
"""
266+
267+
request = arm_authorizer_server_pb2.AcceptArmAuthorizationRequest()
268+
request.valid_time_s = valid_time_s
269+
response = await self._stub.AcceptArmAuthorization(request)
270+
271+
272+
result = self._extract_result(response)
273+
274+
if result.result != ArmAuthorizerServerResult.Result.SUCCESS:
275+
raise ArmAuthorizerServerError(result, "accept_arm_authorization()", valid_time_s)
276+
277+
278+
async def reject_arm_authorization(self, temporarily, reason, extra_info):
279+
"""
280+
Reject arm authorization request
281+
282+
Parameters
283+
----------
284+
temporarily : bool
285+
True if the answer should be TEMPORARILY_REJECTED, false for DENIED
286+
287+
reason : RejectionReason
288+
Reason for the arm to be rejected
289+
290+
extra_info : int32_t
291+
Extra information specific to the rejection reason (see https://mavlink.io/en/services/arm_authorization.html)
292+
293+
Raises
294+
------
295+
ArmAuthorizerServerError
296+
If the request fails. The error contains the reason for the failure.
297+
"""
298+
299+
request = arm_authorizer_server_pb2.RejectArmAuthorizationRequest()
300+
request.temporarily = temporarily
301+
302+
request.reason = reason.translate_to_rpc()
303+
304+
305+
request.extra_info = extra_info
306+
response = await self._stub.RejectArmAuthorization(request)
307+
308+
309+
result = self._extract_result(response)
310+
311+
if result.result != ArmAuthorizerServerResult.Result.SUCCESS:
312+
raise ArmAuthorizerServerError(result, "reject_arm_authorization()", temporarily, reason, extra_info)
313+

0 commit comments

Comments
 (0)