Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to MAVSDK v2.1.0 #649

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,21 @@ jobs:
echo $?
git tag --list

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install prerequisites
run: |
python3 -m pip install -r requirements.txt
python3 -m pip install twine wheel
python3 -m pip install --user delocate
python -m pip install -r requirements.txt
python -m pip install twine wheel
python -m pip install --user delocate

- name: Create wheel
run: |
python3 setup.py bdist_wheel
export PATH="$(python3 -m site --user-base)/bin:$PATH"
python setup.py bdist_wheel
export PATH="$(python -m site --user-base)/bin:$PATH"
echo "PATH: $PATH"
delocate-wheel -w wheelhouse -v dist/*.whl
ls wheelhouse/*any.whl | sed -e 'p;s/any/macosx_10_9_x86_64/' | xargs -n2 mv
Expand Down Expand Up @@ -195,9 +200,9 @@ jobs:
git tag --list

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.10
python-version: 3.11
architecture: ${{ matrix.arch }}

- name: Install prerequisites
Expand Down
2 changes: 1 addition & 1 deletion MAVSDK_SERVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.17
v2.1.0
8 changes: 8 additions & 0 deletions mavsdk/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class Result(Enum):
UNSUPPORTED
Action not supported

FAILED
Action failed

"""


Expand All @@ -143,6 +146,7 @@ class Result(Enum):
NO_VTOL_TRANSITION_SUPPORT = 10
PARAMETER_ERROR = 11
UNSUPPORTED = 12
FAILED = 13

def translate_to_rpc(self):
if self == ActionResult.Result.UNKNOWN:
Expand Down Expand Up @@ -171,6 +175,8 @@ def translate_to_rpc(self):
return action_pb2.ActionResult.RESULT_PARAMETER_ERROR
if self == ActionResult.Result.UNSUPPORTED:
return action_pb2.ActionResult.RESULT_UNSUPPORTED
if self == ActionResult.Result.FAILED:
return action_pb2.ActionResult.RESULT_FAILED

@staticmethod
def translate_from_rpc(rpc_enum_value):
Expand Down Expand Up @@ -201,6 +207,8 @@ def translate_from_rpc(rpc_enum_value):
return ActionResult.Result.PARAMETER_ERROR
if rpc_enum_value == action_pb2.ActionResult.RESULT_UNSUPPORTED:
return ActionResult.Result.UNSUPPORTED
if rpc_enum_value == action_pb2.ActionResult.RESULT_FAILED:
return ActionResult.Result.FAILED

def __str__(self):
return self.name
Expand Down
14 changes: 7 additions & 7 deletions mavsdk/action_pb2.py

Large diffs are not rendered by default.

60 changes: 54 additions & 6 deletions mavsdk/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class Result(Enum):
NO_SYSTEM
No system connected

PROTOCOL_UNSUPPORTED
Definition file protocol not supported

"""


Expand All @@ -147,6 +150,7 @@ class Result(Enum):
TIMEOUT = 6
WRONG_ARGUMENT = 7
NO_SYSTEM = 8
PROTOCOL_UNSUPPORTED = 9

def translate_to_rpc(self):
if self == CameraResult.Result.UNKNOWN:
Expand All @@ -167,6 +171,8 @@ def translate_to_rpc(self):
return camera_pb2.CameraResult.RESULT_WRONG_ARGUMENT
if self == CameraResult.Result.NO_SYSTEM:
return camera_pb2.CameraResult.RESULT_NO_SYSTEM
if self == CameraResult.Result.PROTOCOL_UNSUPPORTED:
return camera_pb2.CameraResult.RESULT_PROTOCOL_UNSUPPORTED

@staticmethod
def translate_from_rpc(rpc_enum_value):
Expand All @@ -189,6 +195,8 @@ def translate_from_rpc(rpc_enum_value):
return CameraResult.Result.WRONG_ARGUMENT
if rpc_enum_value == camera_pb2.CameraResult.RESULT_NO_SYSTEM:
return CameraResult.Result.NO_SYSTEM
if rpc_enum_value == camera_pb2.CameraResult.RESULT_PROTOCOL_UNSUPPORTED:
return CameraResult.Result.PROTOCOL_UNSUPPORTED

def __str__(self):
return self.name
Expand Down Expand Up @@ -1978,44 +1986,56 @@ async def stop_video(self):
raise CameraError(result, "stop_video()")


async def start_video_streaming(self):
async def start_video_streaming(self, stream_id):
"""
Start video streaming.

Parameters
----------
stream_id : int32_t
video stream id

Raises
------
CameraError
If the request fails. The error contains the reason for the failure.
"""

request = camera_pb2.StartVideoStreamingRequest()
request.stream_id = stream_id
response = await self._stub.StartVideoStreaming(request)


result = self._extract_result(response)

if result.result != CameraResult.Result.SUCCESS:
raise CameraError(result, "start_video_streaming()")
raise CameraError(result, "start_video_streaming()", stream_id)


async def stop_video_streaming(self):
async def stop_video_streaming(self, stream_id):
"""
Stop current video streaming.

Parameters
----------
stream_id : int32_t
video stream id

Raises
------
CameraError
If the request fails. The error contains the reason for the failure.
"""

request = camera_pb2.StopVideoStreamingRequest()
request.stream_id = stream_id
response = await self._stub.StopVideoStreaming(request)


result = self._extract_result(response)

if result.result != CameraResult.Result.SUCCESS:
raise CameraError(result, "stop_video_streaming()")
raise CameraError(result, "stop_video_streaming()", stream_id)


async def set_mode(self, mode):
Expand Down Expand Up @@ -2330,26 +2350,32 @@ async def get_setting(self, setting):
return Setting.translate_from_rpc(response.setting)


async def format_storage(self):
async def format_storage(self, storage_id):
"""
Format storage (e.g. SD card) in camera.

This will delete all content of the camera storage!

Parameters
----------
storage_id : int32_t
Storage identify to be format

Raises
------
CameraError
If the request fails. The error contains the reason for the failure.
"""

request = camera_pb2.FormatStorageRequest()
request.storage_id = storage_id
response = await self._stub.FormatStorage(request)


result = self._extract_result(response)

if result.result != CameraResult.Result.SUCCESS:
raise CameraError(result, "format_storage()")
raise CameraError(result, "format_storage()", storage_id)


async def select_camera(self, camera_id):
Expand Down Expand Up @@ -2378,4 +2404,26 @@ async def select_camera(self, camera_id):

if result.result != CameraResult.Result.SUCCESS:
raise CameraError(result, "select_camera()", camera_id)


async def reset_settings(self):
"""
Reset all settings in camera.

This will reset all camera settings to default value

Raises
------
CameraError
If the request fails. The error contains the reason for the failure.
"""

request = camera_pb2.ResetSettingsRequest()
response = await self._stub.ResetSettings(request)


result = self._extract_result(response)

if result.result != CameraResult.Result.SUCCESS:
raise CameraError(result, "reset_settings()")

220 changes: 120 additions & 100 deletions mavsdk/camera_pb2.py

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions mavsdk/camera_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def __init__(self, channel):
request_serializer=camera_dot_camera__pb2.SelectCameraRequest.SerializeToString,
response_deserializer=camera_dot_camera__pb2.SelectCameraResponse.FromString,
)
self.ResetSettings = channel.unary_unary(
'/mavsdk.rpc.camera.CameraService/ResetSettings',
request_serializer=camera_dot_camera__pb2.ResetSettingsRequest.SerializeToString,
response_deserializer=camera_dot_camera__pb2.ResetSettingsResponse.FromString,
)


class CameraServiceServicer(object):
Expand Down Expand Up @@ -316,6 +321,16 @@ def SelectCamera(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def ResetSettings(self, request, context):
"""
Reset all settings in camera.

This will reset all camera settings to default value
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_CameraServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand Down Expand Up @@ -424,6 +439,11 @@ def add_CameraServiceServicer_to_server(servicer, server):
request_deserializer=camera_dot_camera__pb2.SelectCameraRequest.FromString,
response_serializer=camera_dot_camera__pb2.SelectCameraResponse.SerializeToString,
),
'ResetSettings': grpc.unary_unary_rpc_method_handler(
servicer.ResetSettings,
request_deserializer=camera_dot_camera__pb2.ResetSettingsRequest.FromString,
response_serializer=camera_dot_camera__pb2.ResetSettingsResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'mavsdk.rpc.camera.CameraService', rpc_method_handlers)
Expand Down Expand Up @@ -798,3 +818,20 @@ def SelectCamera(request,
camera_dot_camera__pb2.SelectCameraResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def ResetSettings(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/mavsdk.rpc.camera.CameraService/ResetSettings',
camera_dot_camera__pb2.ResetSettingsRequest.SerializeToString,
camera_dot_camera__pb2.ResetSettingsResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
Loading