> ## Documentation Index
> Fetch the complete documentation index at: https://scaledfoundations-rebrand.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MavlinkClient

## \_\_init\_\_

<ResponseField
  name="MavlinkClient.__init__(
ground_control_station_ip: str = &#x22;192.168.8.10&#x22;,
mavlink_port: str = &#x22;14550&#x22;,
vehicle_ip: str = &#x22;192.168.8.1&#x22;,
communication_protocol: str = &#x22;udp&#x22;,
camera_streams: Optional[Dict[str, Dict[str, Any]]] = None,
arm_enable: bool = False,
dry_run: bool = False,
log_level: str = &#x22;INFO&#x22;,
known_messages: List[str] = None,
)"
>
  Instantiates a Mavlink client to handle message passing and command sending to/from a mavlink drone.
  Additionally sets up video stream manager for handling RTSP streams from the drone.

  <ResponseField name="Arguments">
    <ParamField query="ground_control_station_ip" type="str">
      IP address of the ground control station (default: '192.168.8.10')
    </ParamField>

    <ParamField query="mavlink_port" type="str">
      port number for mavlink connection (default: '14550')
    </ParamField>

    <ParamField query="vehicle_ip" type="str">
      IP address of the vehicle (default: '192.168.8.1')
    </ParamField>

    <ParamField query="communication_protocol" type="str">
      communication protocol to use, one of ('udp'|'tcp') (default: 'udp')
    </ParamField>

    <ParamField query="camera_streams" type="Optional[Dict[str, Dict[str, Any]]]">
      Dictionary of dictionaries containing the
    </ParamField>

    <ParamField query="arm_enable" type="bool">
      whether to enable arming the drone (default: False)
    </ParamField>

    <ParamField query="dry_run" type="bool">
      whether to run in dry run mode which bypasses arming exceptions (default: False)
    </ParamField>

    <ParamField query="log_level" type="str">
      logging level to be displayed to the user, one of ('DEBUG'|'INFO'|'WARNING'|'ERROR'),
    </ParamField>

    <ParamField query="known_messages" type="List[str]">
      list of expected message types to handle without warning (default: None)
    </ParamField>
  </ResponseField>
</ResponseField>

<RequestExample>
  ```python Example
  client = MavlinkClient(
      ground_control_station_ip="192.168.8.10",
      mavlink_port="14550",
      vehicle_ip="192.168.8.1",
      camera_streams={
          "hires_front_small": {"port": 8900, "path": "/live"},
      },
      arm_enable=False,
      dry_run=False,
      log_level="INFO",
      known_messages=["HEARTBEAT", "LOCAL_POSITION_NED", "COMMAND_ACK"],
  )
  ```
</RequestExample>

## get\_msg

<ResponseField name="MavlinkClient.get_msg(msg_type: str)">
  Thread-safe method to get a message from msg\_dict.

  <ResponseField name="Arguments">
    <ParamField query="msg_type" type="str">
      name of the message type to be retrieved.
    </ParamField>
  </ResponseField>

  <ResponseField name="Returns">
    <ResponseField name="msg" type="msg">
      returns message if found, else `None`
    </ResponseField>
  </ResponseField>
</ResponseField>

## update\_setpoint

<ResponseField name="MavlinkClient.update_setpoint(controls, **kwargs)">
  Update the current setpoint of the drone as well as the currently active set of controls.

  <ResponseField name="Arguments">
    <ParamField query="controls" type="List[str]">
      controls
    </ParamField>
  </ResponseField>
</ResponseField>

## attempt\_command

<ResponseField
  name="MavlinkClient.attempt_command(
command_name: str,
command_id: int,
params: List[Any],
confirmation: int = 0,
max_attempts: int = 3,
retry_delay: float = 1.0,
)"
>
  Attempt to perform a given command with name and id. Includes retry logic with delays.

  <ResponseField name="Arguments">
    <ParamField query="command_name" type="str">
      arbitrary command name for logging/display
    </ParamField>

    <ParamField query="command_id" type="int">
      Mavlink ID of the command to be attempted
    </ParamField>

    <ParamField query="confirmation" type="int">
      whether this is first transmission of command (0, default), or a confirmation (1-255)
    </ParamField>

    <ParamField query="max_attempts" type="int">
      maximum number of attempts to send the command (default=3)
    </ParamField>

    <ParamField query="retry_delay" type="float">
      delay in seconds between attempts (default=1.0)
    </ParamField>
  </ResponseField>

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether command was successfully completed
    </ResponseField>
  </ResponseField>
</ResponseField>

## set\_custom\_msg\_rates

<ResponseField name="MavlinkClient.set_custom_msg_rates(msg_id: int, interval_us: int)">
  Set custom message publishing rates for a given message ID.

  <ResponseField name="Arguments">
    <ParamField query="msg_id" type="int">
      mavlink message ID to set custom rate for
    </ParamField>

    <ParamField query="interval_us" type="int">
      interval in microseconds to publish message
    </ParamField>
  </ResponseField>
</ResponseField>

## request\_msg

<ResponseField name="MavlinkClient.request_msg(msg_id: int)">
  Request a specific message from the drone.

  <ResponseField name="Arguments">
    <ParamField query="msg_id" type="int">
      mavlink message ID to request
    </ParamField>
  </ResponseField>

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether command was successful
    </ResponseField>
  </ResponseField>
</ResponseField>

## reset\_ned\_origin

<ResponseField name="MavlinkClient.reset_ned_origin()">
  Saves current position as the arming waypoint and resets mavlink origin.

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether mavlink origin reset was successful
    </ResponseField>
  </ResponseField>
</ResponseField>

## check\_props\_spinning

<ResponseField name="MavlinkClient.check_props_spinning(pwm_min_threshold: float = 1100)">
  Check if props are spinning by requesting and monitoring servo outputs.
  NOTE: this is the *commanded* PWM value, not the *actual* RPM.

  <ResponseField name="Arguments">
    <ParamField query="pwm_min_threshold" type="float">
      minimum PWM threshold for prop spinning
    </ParamField>
  </ResponseField>

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether all props are spinning above threshold
    </ResponseField>
  </ResponseField>
</ResponseField>

## arm

<ResponseField name="MavlinkClient.arm()">
  Arm the drone if enabled.

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether drone was successfully armed
    </ResponseField>
  </ResponseField>
</ResponseField>

## disarm

<ResponseField name="MavlinkClient.disarm()">
  Disarm the drone.

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether drone was successfully disarmed
    </ResponseField>
  </ResponseField>
</ResponseField>

## set\_offboard\_control

<ResponseField name="MavlinkClient.set_offboard_control()">
  Sets drone control mode to `OFFBOARD`. This enables us to send position, velocity, or acceleration setpoints to the drone.
  NOTE: Drone may reject offboard mode if certain conditions are not met (recent setpoint message received, armed, etc.)

  <ResponseField name="Returns">
    <ResponseField name="bool" type="bool">
      whether offboard control mode was successfully set
    </ResponseField>
  </ResponseField>
</ResponseField>

## start

<ResponseField name="MavlinkClient.start()">
  Start the drone by resetting NED origin, arming the drone, and setting offboard control mode.
</ResponseField>

## terminate

<ResponseField name="MavlinkClient.terminate()">
  Terminate the drone client and shut down all threads.
</ResponseField>

## get\_single\_frame

<ResponseField name="MavlinkClient.get_single_frame(camera_name: str)">
  Get a single frame from the named video stream.

  <ResponseField name="Arguments">
    <ParamField query="camera_name" type="str">
      name of the camera stream to capture frame from
    </ParamField>
  </ResponseField>

  <ResponseField name="Returns">
    <ResponseField name="np.ndarray" type="np.ndarray">
      frame as numpy array if successful, else `None`
    </ResponseField>
  </ResponseField>
</ResponseField>
