Skip to main content

MavlinkClient

Inherits from: object No class docstring.

init

MavlinkClient.__init__(ground_control_station_ip: str, mavlink_port: str, vehicle_ip: str, communication_protocol: str, arm_enable: bool, dry_run: bool, checks_poststart: Optional[List[callable]] = None, checks_preflight: Optional[List[callable]] = None, checks_postarm: Optional[List[callable]] = None, messages_known: Optional[List[str]] = None, messages_required: Optional[List[str]] = None, offboard_control_mode_int: int = None)
Instantiates a Mavlink client for message passing and command sending with a drone, including optional preflight/poststart checks.
Arguments
ground_control_station_ip (str)
str
required
IP address of the ground control station
Port number for MAVLink connection
vehicle_ip (str)
str
required
IP address of the drone/vehicle
communication_protocol (str)
str
required
Communication protocol, e.g., ‘udp’ or ‘tcp’
arm_enable (bool)
bool
required
Whether arming is enabled
dry_run (bool)
bool
required
If True, bypasses arming exceptions
checks_poststart (Optional[List[callable]])
Optional[List[callable]]
A list of functions to run after the client has started.
checks_preflight (Optional[List[callable]])
Optional[List[callable]]
A list of functions to run before flight to validate system state.
checks_postarm (Optional[List[callable]])
Optional[List[callable]]
A list of functions to run immediately after arming to validate system state.
messages_known (Optional[List[str]])
Optional[List[str]]
List of MAVLink message types expected (default: None)
messages_required (Optional[List[str]])
Optional[List[str]]
List of MAVLink message types required before proceeding (default: None)
offboard_control_mode_int (int)
int
Custom offboard control mode value. (default: 6)

run_checks

MavlinkClient.run_checks(checks: List[callable])
Runs a list of check functions.
Arguments
checks (List[callable])
List[callable]
required
A list of functions that accept the client instance and return a boolean.

get_msg

MavlinkClient.get_msg(msg_type: str)
Thread-safe retrieval of a message from the internal dictionary.
Arguments
msg_type (str)
str
required
The name of the message type to retrieve.

update_setpoint

MavlinkClient.update_setpoint(controls, **kwargs)
Updates the current setpoint and control parameters.
Arguments
controls (List[str])
List[str]
required
List of control fields to update.
kwargs
Values for parameters (e.g., lat, lon, alt, vx, vy, yaw, etc.)

attempt_command

MavlinkClient.attempt_command(command_name: str, command_id: int, params: List[Any], confirmation: int = 0, max_attempts: int = 3, retry_delay: float = 1.0) -> bool
Attempts to execute a command with retry logic.
Arguments
command_name (str)
str
required
Command description for logging.
command_id (int)
int
required
MAVLink command ID.
params (List[Any])
List[Any]
required
List of 7 parameters for the command.
confirmation (int)
int
0 for initial transmission, 1-255 for confirmations.
max_attempts (int)
int
Maximum retry attempts.
retry_delay (float)
float
Delay between attempts.
Returns
bool
bool
True if the command is acknowledged successfully; False otherwise.

set_custom_msg_rates

MavlinkClient.set_custom_msg_rates(msg_id: int, interval_us: int)
Sets custom message publishing rates for a given MAVLink message.
Arguments
msg_id (int)
int
required
The MAVLink message ID.
interval_us (int)
int
required
The interval in microseconds between messages.
Returns
bool
True if successful, False otherwise.

request_msg

MavlinkClient.request_msg(msg_id: int)
Requests a specific MAVLink message from the drone.
Arguments
msg_id (int)
int
required
The MAVLink message ID.
Returns
bool
True if the request was successful, False otherwise.

reset_ned_origin

MavlinkClient.reset_ned_origin() -> bool
Resets the MAVLink NED origin using the current position.
Returns
bool
bool
True if the origin was reset successfully, False otherwise.

arm

MavlinkClient.arm()
Arms the drone (if permitted).
Returns
bool
True if the drone was successfully armed, False otherwise.

disarm

MavlinkClient.disarm()
Disarms the drone.
Returns
bool
True if disarm was successful, False otherwise.

set_offboard_control

MavlinkClient.set_offboard_control()
Sets the drone’s control mode to OFFBOARD, enabling external setpoint control.
Returns
bool
True if offboard control was successfully set, False otherwise.

start

MavlinkClient.start()
Starts the drone client by resetting NED origin, arming, and setting offboard control.

terminate

MavlinkClient.terminate()
Terminates the client and shuts down all threads.