Arduino Mavlink
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
MavlinkController Class Reference

A simple MAVLink drone controller for Arduino/ESP32. More...

#include <MavlinkController.h>

Collaboration diagram for MavlinkController:
Collaboration graph
[legend]

Public Types

typedef bool(* MessageCallback) (MavlinkController &, mavlink_message_t &)
 Callback type for MAVLink message handling.
 

Public Member Functions

 MavlinkController (Stream *str=nullptr, ParameterStore *parameters=nullptr)
 Constructor with optional Stream and ParameterStore.
 
 MavlinkController (Stream &str)
 Constructor with Stream reference.
 
virtual ~MavlinkController ()
 Destructor.
 
virtual float getValue (uint16_t id)
 Get a parameter value by id.
 
virtual void setValue (uint16_t id, float value)
 Set a parameter value by id.
 
virtual void loop ()
 Main loop: processes MAVLink messages and telemetry.
 
virtual void reconnect (Stream *str)
 Assign a new Stream for MAVLink communication.
 
bool isArmed ()
 Returns true if the drone is armed.
 
void setMessageCallback (MessageCallback cb)
 Set the callback for custom MAVLink message handling.
 
bool setSystemId (int id)
 Defines the system ID for incoming MAVLink messages (1-255)
 
int getSystemId () const
 Get the current system ID.
 

Protected Member Functions

virtual size_t transmitMessage (mavlink_message_t *mvl_msg_ptr)
 Transmit a MAVLink message, returns bytes written or 0 on error.
 
void transmitAck (uint16_t command, bool accepted)
 trasmit a command acknowledgment message
 
virtual void handleManualControl (mavlink_message_t *mvl_msg_ptr)
 
virtual void handleParamRequestList (mavlink_message_t *mvl_msg_ptr)
 
virtual void handleCommandLong (mavlink_message_t *mvl_msg_ptr)
 
virtual void handleMissionRequestList (mavlink_message_t *mvl_msg_ptr)
 
virtual void processRequest ()
 
virtual void processHeartbeat ()
 
virtual void processStat ()
 
virtual void processStatSystem ()
 
virtual void processStatGPS ()
 
virtual void processStatRadioStatus ()
 

Protected Attributes

int mavlink_system_id
 
MessageCallback messageCallback = nullptr
 
Stream * stream = nullptr
 
ParameterStore * parameterStore = nullptr
 
bool releaseParameterStore = false
 
mavlink_message_t mvl_tx_message
 
mavlink_message_t mvl_rx_message
 
mavlink_status_t mvl_rx_status
 
const uint8_t mvl_compid = 1
 
const uint8_t mvl_sysid = 1
 
const uint8_t mvl_chan = MAVLINK_COMM_0
 
const uint32_t hb_interval = 1000
 
uint32_t t_last_hb = 0
 
const uint32_t sys_stat_interval = 100
 
uint32_t t_last_sys_stat = 0
 
int16_t sys_stat_count = 0
 
uint8_t mvl_armed = 0
 
uint8_t mvl_packet_received = 0
 
uint32_t timestamp = 0
 
bool camera_active = false
 

Static Protected Attributes

static constexpr size_t TX_BUFFER_SIZE = 512
 

Detailed Description

A simple MAVLink drone controller for Arduino/ESP32.

This class implements a minimal MAVLink drone interface, handling message reception, parameter storage, and basic telemetry/command processing. It is based on Dan Zimmerman's barebones_MAVLink example and provides hooks for custom parameter storage and logging.

Features:

Usage:

  1. Instantiate with a Stream and optional ParameterStore
  2. Call loop() regularly (e.g., in Arduino loop())
  3. Optionally set a message callback with setMessageCallback()
Note
This class is designed for embedded use and avoids blocking operations.

Member Typedef Documentation

◆ MessageCallback

typedef bool(* MessageCallback) (MavlinkController &, mavlink_message_t &)

Callback type for MAVLink message handling.

Constructor & Destructor Documentation

◆ MavlinkController() [1/2]

MavlinkController ( Stream *  str = nullptr,
ParameterStore *  parameters = nullptr 
)
inline

Constructor with optional Stream and ParameterStore.

◆ MavlinkController() [2/2]

MavlinkController ( Stream &  str)
inline

Constructor with Stream reference.

◆ ~MavlinkController()

virtual ~MavlinkController ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ getSystemId()

int getSystemId ( ) const
inline

Get the current system ID.

◆ getValue()

virtual float getValue ( uint16_t  id)
inlinevirtual

Get a parameter value by id.

◆ handleCommandLong()

virtual void handleCommandLong ( mavlink_message_t *  mvl_msg_ptr)
inlineprotectedvirtual

◆ handleManualControl()

virtual void handleManualControl ( mavlink_message_t *  mvl_msg_ptr)
inlineprotectedvirtual

◆ handleMissionRequestList()

virtual void handleMissionRequestList ( mavlink_message_t *  mvl_msg_ptr)
inlineprotectedvirtual

◆ handleParamRequestList()

virtual void handleParamRequestList ( mavlink_message_t *  mvl_msg_ptr)
inlineprotectedvirtual

◆ isArmed()

bool isArmed ( )
inline

Returns true if the drone is armed.

◆ loop()

virtual void loop ( )
inlinevirtual

Main loop: processes MAVLink messages and telemetry.

◆ processHeartbeat()

virtual void processHeartbeat ( )
inlineprotectedvirtual

◆ processRequest()

virtual void processRequest ( )
inlineprotectedvirtual

◆ processStat()

virtual void processStat ( )
inlineprotectedvirtual

◆ processStatGPS()

virtual void processStatGPS ( )
inlineprotectedvirtual

◆ processStatRadioStatus()

virtual void processStatRadioStatus ( )
inlineprotectedvirtual

◆ processStatSystem()

virtual void processStatSystem ( )
inlineprotectedvirtual

◆ reconnect()

virtual void reconnect ( Stream *  str)
inlinevirtual

Assign a new Stream for MAVLink communication.

◆ setMessageCallback()

void setMessageCallback ( MessageCallback  cb)
inline

Set the callback for custom MAVLink message handling.

◆ setSystemId()

bool setSystemId ( int  id)
inline

Defines the system ID for incoming MAVLink messages (1-255)

◆ setValue()

virtual void setValue ( uint16_t  id,
float  value 
)
inlinevirtual

Set a parameter value by id.

◆ transmitAck()

void transmitAck ( uint16_t  command,
bool  accepted 
)
inlineprotected

trasmit a command acknowledgment message

◆ transmitMessage()

virtual size_t transmitMessage ( mavlink_message_t *  mvl_msg_ptr)
inlineprotectedvirtual

Transmit a MAVLink message, returns bytes written or 0 on error.

Member Data Documentation

◆ camera_active

bool camera_active = false
protected

◆ hb_interval

const uint32_t hb_interval = 1000
protected

◆ mavlink_system_id

int mavlink_system_id
protected
Initial value:
=
#define MAVLINK_SYSTEM_ID
Definition: MavlinkConfig.h:40

◆ messageCallback

MessageCallback messageCallback = nullptr
protected

◆ mvl_armed

uint8_t mvl_armed = 0
protected

◆ mvl_chan

const uint8_t mvl_chan = MAVLINK_COMM_0
protected

◆ mvl_compid

const uint8_t mvl_compid = 1
protected

◆ mvl_packet_received

uint8_t mvl_packet_received = 0
protected

◆ mvl_rx_message

mavlink_message_t mvl_rx_message
protected

◆ mvl_rx_status

mavlink_status_t mvl_rx_status
protected

◆ mvl_sysid

const uint8_t mvl_sysid = 1
protected

◆ mvl_tx_message

mavlink_message_t mvl_tx_message
protected

◆ parameterStore

ParameterStore* parameterStore = nullptr
protected

◆ releaseParameterStore

bool releaseParameterStore = false
protected

◆ stream

Stream* stream = nullptr
protected

◆ sys_stat_count

int16_t sys_stat_count = 0
protected

◆ sys_stat_interval

const uint32_t sys_stat_interval = 100
protected

◆ t_last_hb

uint32_t t_last_hb = 0
protected

◆ t_last_sys_stat

uint32_t t_last_sys_stat = 0
protected

◆ timestamp

uint32_t timestamp = 0
protected

◆ TX_BUFFER_SIZE

constexpr size_t TX_BUFFER_SIZE = 512
staticconstexprprotected

The documentation for this class was generated from the following file: