Skip to content

Commit 9ac7113

Browse files
authored
Merge pull request #171 from mavlink/pr-cpp-autogeneration
C++ auto-generation ripple effects
2 parents 70e62b9 + 678a443 commit 9ac7113

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+15432
-6019
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ script:
6767
- set -e
6868
- $PYTHON_BIN setup.py bdist_wheel
6969
- if [[ "${BUILD_TARGET}" = "linux" ]]; then
70-
auditwheel repair dist/*.whl;
70+
auditwheel repair --plat manylinux2010_x86_64 dist/*.whl;
7171
fi
7272
- if [[ "${BUILD_TARGET}" = "macos" ]]; then
7373
delocate-wheel -w wheelhouse -v dist/*.whl;

MAVSDK_SERVER_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.23.0
1+
v0.25.0

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ Run the following helper script. It will generate the Python wrappers for each p
7979
./other/tools/run_protoc.sh
8080
```
8181

82-
### Install the package locally
82+
### Build and install the package locally
8383

8484
After generating the wrapper you can install a development (editable) version of the package using:
8585

8686
```
87+
python3 setup.py build
8788
pip3 install -e .
8889
```
8990

examples/camera.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44

5-
from mavsdk import (CameraError, CameraMode)
5+
from mavsdk import (CameraError, Mode)
66
from mavsdk import System
77

88

@@ -17,11 +17,11 @@ async def run():
1717
break
1818

1919
asyncio.ensure_future(print_camera_mode(drone))
20-
asyncio.ensure_future(print_camera_status(drone))
20+
asyncio.ensure_future(print_status(drone))
2121

2222
print("Setting mode to 'PHOTO'")
2323
try:
24-
await drone.camera.set_mode(CameraMode.PHOTO)
24+
await drone.camera.set_mode(Mode.PHOTO)
2525
except CameraError as error:
2626
print(f"Setting mode failed with error code: {error._result.result}")
2727

@@ -34,7 +34,7 @@ async def run():
3434
print(f"Couldn't take photo: {error._result.result}")
3535

3636
# Shut down the running coroutines (here 'print_camera_mode()' and
37-
# 'print_camera_status()')
37+
# 'print_status()')
3838
await asyncio.get_event_loop().shutdown_asyncgens()
3939

4040

@@ -43,9 +43,9 @@ async def print_camera_mode(drone):
4343
print(f"Camera mode: {camera_mode}")
4444

4545

46-
async def print_camera_status(drone):
47-
async for camera_status in drone.camera.camera_status():
48-
print(camera_status)
46+
async def print_status(drone):
47+
async for status in drone.camera.status():
48+
print(status)
4949

5050

5151
if __name__ == "__main__":

examples/mission.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44

55
from mavsdk import System
6-
from mavsdk import (MissionItem)
6+
from mavsdk import (MissionItem, MissionPlan)
77

88

99
async def run():
@@ -51,10 +51,12 @@ async def run():
5151
float('nan'),
5252
float('nan')))
5353

54+
mission_plan = MissionPlan(mission_items)
55+
5456
await drone.mission.set_return_to_launch_after_mission(True)
5557

5658
print("-- Uploading mission")
57-
await drone.mission.upload_mission(mission_items)
59+
await drone.mission.upload_mission(mission_plan)
5860

5961
print("-- Arming")
6062
await drone.action.arm()
@@ -68,8 +70,8 @@ async def run():
6870
async def print_mission_progress(drone):
6971
async for mission_progress in drone.mission.mission_progress():
7072
print(f"Mission progress: "
71-
f"{mission_progress.current_item_index}/"
72-
f"{mission_progress.mission_count}")
73+
f"{mission_progress.current}/"
74+
f"{mission_progress.total}")
7375

7476

7577
async def observe_is_in_air(drone):

mavsdk/generated/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# -*- coding: utf-8 -*-
22

3-
from .camera import *
4-
from .param import *
5-
from .telemetry import *
63
from .action import *
7-
from .info import *
8-
from .gimbal import *
9-
from .geofence import *
10-
from .mocap import *
114
from .calibration import *
5+
from .geofence import *
6+
from .gimbal import *
7+
from .camera import *
128
from .core import *
9+
from .info import *
1310
from .mission import *
14-
from .shell import *
11+
from .mocap import *
1512
from .offboard import *
13+
from .param import *
14+
from .shell import *
15+
from .telemetry import *

mavsdk/generated/action.py

Lines changed: 125 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class Result(Enum):
2727
Values
2828
------
2929
UNKNOWN
30-
Unknown error
30+
Unknown result
3131
3232
SUCCESS
33-
Success: the action command was accepted by the vehicle
33+
Request was successful
3434
3535
NO_SYSTEM
3636
No system is connected
@@ -54,7 +54,7 @@ class Result(Enum):
5454
Request timed out
5555
5656
VTOL_TRANSITION_SUPPORT_UNKNOWN
57-
Hybrid/VTOL transition refused because VTOL support is unknown
57+
Hybrid/VTOL transition support is unknown
5858
5959
NO_VTOL_TRANSITION_SUPPORT
6060
Vehicle does not support hybrid/VTOL transitions
@@ -79,38 +79,58 @@ class Result(Enum):
7979
PARAMETER_ERROR = 11
8080

8181
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
96106

97107
@staticmethod
98108
def translate_from_rpc(rpc_enum_value):
99109
""" 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
114134

115135
def __str__(self):
116136
return self.name
@@ -257,7 +277,7 @@ async def takeoff(self):
257277
"""
258278
Send command to take off and hover.
259279
260-
This switches the drone into position control mode and commands
280+
This switches the drone into position control mode and commands
261281
it to take off and hover at the takeoff altitude.
262282
263283
Note that the vehicle must be armed before it can take off.
@@ -322,9 +342,33 @@ async def reboot(self):
322342
raise ActionError(result, "reboot()")
323343

324344

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+
325369
async def kill(self):
326370
"""
327-
Send command to kill the drone.
371+
Send command to kill the drone.
328372
329373
This will disarm a drone irrespective of whether it is landed or flying.
330374
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):
349393
"""
350394
Send command to return to the launch (takeoff) position and land.
351395
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
353397
generally means it will rise up to a certain altitude to clear any obstacles before heading
354398
back to the launch (takeoff) position and land there.
355399
@@ -369,7 +413,50 @@ async def return_to_launch(self):
369413
raise ActionError(result, "return_to_launch()")
370414

371415

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):
373460
"""
374461
Send command to transition the drone to fixedwing.
375462
@@ -383,14 +470,14 @@ async def transition_to_fixed_wing(self):
383470
If the request fails. The error contains the reason for the failure.
384471
"""
385472

386-
request = action_pb2.TransitionToFixedWingRequest()
387-
response = await self._stub.TransitionToFixedWing(request)
473+
request = action_pb2.TransitionToFixedwingRequest()
474+
response = await self._stub.TransitionToFixedwing(request)
388475

389476

390477
result = self._extract_result(response)
391478

392479
if result.result is not ActionResult.Result.SUCCESS:
393-
raise ActionError(result, "transition_to_fixed_wing()")
480+
raise ActionError(result, "transition_to_fixedwing()")
394481

395482

396483
async def transition_to_multicopter(self):

0 commit comments

Comments
 (0)