payloadcomputerdroneprojekt.communications package#

Submodules#

payloadcomputerdroneprojekt.communications.comm_class module#

class payloadcomputerdroneprojekt.communications.comm_class.Communications(address: str, config: Dict[str, Any] | None = None)[source]#

Bases: object

Handles communication with the drone, including connection, arming, movement, telemetry, and image transfer.

This class abstracts the MAVSDK API and provides high-level methods for controlling and monitoring the drone, as well as sending data to a ground station.

async await_arm(**kwargs)#
async await_disarm(**kwargs)#
async check_health() bool[source]#

Check if the drone’s global position is OK (GPS ready).

Returns:

True if global position is OK, False otherwise.

Return type:

bool

async connect() bool[source]#

Establish a connection to the drone and set telemetry data rates.

Returns:

True if connection is established, False otherwise.

Return type:

bool

This method initializes the MAVSDK System, connects to the specified address, and waits until the connection is confirmed. It also sets telemetry data rates.

async get_position_lat_lon_alt() List[float][source]#

Get the drone’s global position and attitude.

Returns:

[latitude_deg, longitude_deg, relative_altitude_m, roll, pitch, yaw]

Return type:

list[float]

If GPS is not ready, returns zeros.

async get_position_xyz() List[float][source]#

Get the drone’s local position and attitude.

Returns:

[x, y, z, roll, pitch, yaw] in meters and degrees.

Return type:

list[float]

If GPS is not ready, returns zeros.

async get_relative_height() float[source]#

Get the drone’s height above the ground.

Returns:

Relative altitude in meters.

Return type:

float

async is_flying() bool[source]#

Check if the drone is currently flying (in air).

Returns:

True if the drone is in air, False otherwise.

Return type:

bool

async land(**kwargs)#
async landed() bool[source]#

Check if the drone is currently flying (in air).

Returns:

True if the drone is in air, False otherwise.

Return type:

bool

async mov_by_vel(**kwargs)#
async mov_by_xy(**kwargs)#
async mov_by_xyz(**kwargs)#
async mov_by_xyz_old(**kwargs)#
async mov_to_lat_lon_alt(**kwargs)#
async mov_to_xyz(**kwargs)#
async mov_with_vel(**kwargs)#
async send_status(status: str) None[source]#

Send a status text message to the ground station.

Parameters:

status (str) – Status message to send.

This method uses the MAVSDK server utility to send a status text.

async set_data_rates() None[source]#

Set telemetry data rates for attitude, position, and in-air status.

This method configures the frequency at which telemetry data is received.

async start(**kwargs)#
async wait_for_health() None[source]#

Wait until both the home position and global position are OK.

This method blocks until the drone’s telemetry reports both positions as ready.

payloadcomputerdroneprojekt.communications.helper module#

payloadcomputerdroneprojekt.communications.helper.abs_vel(vec: List[float]) float[source]#

Calculates the magnitude of a velocity vector.

Parameters:

vec (list) – Velocity vector [vx, vy, vz].

Returns:

Magnitude of velocity.

Return type:

float

async payloadcomputerdroneprojekt.communications.helper.get_data(func: AsyncGenerator[T, None]) T | None[source]#

Asynchronously retrieves the first result from an async generator.

Parameters:

func (async generator) – Asynchronous generator function.

Returns:

First result from the generator.

payloadcomputerdroneprojekt.communications.helper.get_pos_vec(state: PositionVelocityNed) List[float][source]#

Extracts the position vector from a PositionVelocityNed object.

Parameters:

state (PositionVelocityNed) – MAVSDK PositionVelocityNed object.

Returns:

Position as [north, east, down] in meters.

Return type:

list

payloadcomputerdroneprojekt.communications.helper.get_vel_vec(state: PositionVelocityNed) List[float][source]#

Extracts the velocity vector from a PositionVelocityNed object.

Parameters:

state (PositionVelocityNed) – MAVSDK PositionVelocityNed object.

Returns:

Velocity as [north, east, down] in m/s.

Return type:

list

payloadcomputerdroneprojekt.communications.helper.pythagoras(pos_a: List[float], pos_b: List[float]) float[source]#

Calculates the Euclidean distance between two position vectors.

Parameters:
  • pos_a (list) – First position vector [x, y, z].

  • pos_b (list) – Second position vector [x, y, z].

Returns:

Euclidean distance.

Return type:

float

payloadcomputerdroneprojekt.communications.helper.reached_pos(target: List[float], error: float = 0.5, error_vel: float = 0.1) Callable[[PositionVelocityNed], bool][source]#

Returns a function that checks if a drone has reached a target position and is below a velocity threshold.

Parameters:
  • target (list) – Target position as [north, east, down] in meters.

  • error (float, optional) – Allowed position error in meters.

  • error_vel (float, optional) – Allowed velocity error in m/s.

Returns:

Function that takes PositionVelocityNed and returns True if target is reached.

Return type:

function

payloadcomputerdroneprojekt.communications.helper.rotation_matrix_yaw(rot: float) ndarray[source]#

Creates a 3x3 rotation matrix for a yaw (Z-axis) rotation.

Parameters:

rot (float) – Yaw rotation in degrees.

Returns:

3x3 rotation matrix.

Return type:

numpy.ndarray

payloadcomputerdroneprojekt.communications.helper.save_execute(msg: str)[source]#

Decorator to wrap a function and catch exceptions, printing a message if an error occurs. Works for both sync and async functions.

async payloadcomputerdroneprojekt.communications.helper.wait_for(func: AsyncGenerator[T, None], b: Callable[[T], bool]) T | None[source]#

Asynchronously waits for a condition to be met in an async generator.

Parameters:
  • func (async generator) – Asynchronous generator function.

  • b (function) – Condition function that takes a result and returns True if condition is met.

Returns:

First result for which the condition is True.

Module contents#