Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def is_active(self):
"""
Check if offboard control is active.
True means that the vehicle is in offboard mode and we are actively sending
setpoints.
Returns
-------
is_active : bool
True if offboard is active
"""
request = offboard_pb2.IsActiveRequest()
response = await self._stub.IsActive(request)
return response.is_active
async def set_velocity_ned(self, velocity_ned_yaw):
"""
Set the velocity in NED coordinates and yaw.
Parameters
----------
velocity_ned_yaw : VelocityNedYaw
Velocity and yaw
"""
request = offboard_pb2.SetVelocityNedRequest()
velocity_ned_yaw.translate_to_rpc(request.velocity_ned_yaw)
response = await self._stub.SetVelocityNed(request)
async def set_velocity_body(self, velocity_body_yawspeed):
"""
Set the velocity in body coordinates and yaw angular rate.
Parameters
----------
velocity_body_yawspeed : VelocityBodyYawspeed
Velocity and yaw angular rate
"""
request = offboard_pb2.SetVelocityBodyRequest()
velocity_body_yawspeed.translate_to_rpc(request.velocity_body_yawspeed)
response = await self._stub.SetVelocityBody(request)
async def set_attitude(self, attitude):
"""
Set the attitude in terms of roll, pitch and yaw in degrees with thrust.
Parameters
----------
attitude : Attitude
Attitude roll, pitch and yaw along with thrust
"""
request = offboard_pb2.SetAttitudeRequest()
attitude.translate_to_rpc(request.attitude)
response = await self._stub.SetAttitude(request)
async def start(self):
"""
Start offboard control.
Raises
------
OffboardError
If the request fails. The error contains the reason for the failure.
"""
request = offboard_pb2.StartRequest()
response = await self._stub.Start(request)
result = self._extract_result(response)
if result.result is not OffboardResult.Result.SUCCESS:
raise OffboardError(result, "start()")
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.Start = channel.unary_unary(
'/mavsdk.rpc.offboard.OffboardService/Start',
request_serializer=offboard__pb2.StartRequest.SerializeToString,
response_deserializer=offboard__pb2.StartResponse.FromString,
)
self.Stop = channel.unary_unary(
'/mavsdk.rpc.offboard.OffboardService/Stop',
request_serializer=offboard__pb2.StopRequest.SerializeToString,
response_deserializer=offboard__pb2.StopResponse.FromString,
)
self.IsActive = channel.unary_unary(
'/mavsdk.rpc.offboard.OffboardService/IsActive',
request_serializer=offboard__pb2.IsActiveRequest.SerializeToString,
response_deserializer=offboard__pb2.IsActiveResponse.FromString,
)
self.SetAttitude = channel.unary_unary(
'/mavsdk.rpc.offboard.OffboardService/SetAttitude',
request_serializer=offboard__pb2.SetAttitudeRequest.SerializeToString,
response_deserializer=offboard__pb2.SetAttitudeResponse.FromString,
async def set_actuator_control(self, actuator_control):
"""
Set direct actuator control values to groups #0 and #1.
First 8 controls will go to control group 0, the following 8 controls to control group 1 (if
actuator_control.num_controls more than 8).
Parameters
----------
actuator_control : ActuatorControl
Actuator control values
"""
request = offboard_pb2.SetActuatorControlRequest()
actuator_control.translate_to_rpc(request.actuator_control)
response = await self._stub.SetActuatorControl(request)
async def set_attitude_rate(self, attitude_rate):
"""
Set the attitude rate in terms of pitch, roll and yaw angular rate along with thrust.
Parameters
----------
attitude_rate : AttitudeRate
Attitude rate roll, pitch and yaw angular rate along with thrust
"""
request = offboard_pb2.SetAttitudeRateRequest()
attitude_rate.translate_to_rpc(request.attitude_rate)
response = await self._stub.SetAttitudeRate(request)
async def stop(self):
"""
Stop offboard control.
The vehicle will be put into Hold mode: https://docs.px4.io/en/flight_modes/hold.html
Raises
------
OffboardError
If the request fails. The error contains the reason for the failure.
"""
request = offboard_pb2.StopRequest()
response = await self._stub.Stop(request)
result = self._extract_result(response)
if result.result is not OffboardResult.Result.SUCCESS:
raise OffboardError(result, "stop()")