Table of Contents > QUARC > User's Guide > Communications
Mavlink Communications
The Mavlink communications blockset may be found under the QUARC Targets/Communications/Mavlink library in the Simulink Library Browser. This blockset includes a set of blocks designed to interface with Mavlink-based auto-pilot systems. These blocks are designed to be used with non-blocking I/O and are typically used with a serial port connection to the auto-pilot, or TCP/IP or UDP.
Note that most auto-pilots only support a subset of the Mavlink messages. |
The Mavlink protocol is a sophisticated, extensible, protocol. Yet the Mavlink blocks support communications with just a few simple blocks. These blocks support not only the standard Mavlink messages, but can also support customized Mavlink messages. The set of messages supported by the blocks is determined by the Mavlink Initialize block, which must be included in any Simulink model using Mavlink.
The Mavlink Initialize block is used to configure the other Mavlink blocks and includes a number of important parameters. For example, it determines whether the QUARC model will act as a client or a server. When acting as a client, the Mavlink blocks typically communicate with a single flight controller. When acting as a server, they can communicate with more than one flight controller at the same time. Whether the Mavlink blocks are used as a client or server, they maintain a persistent connection with the flight controller(s). If the connection is lost, they will attempt to reestablish the connection.
The Mavlink Initialize block also determines the underlying communication protocol used for Mavlink. Mavlink is typically used with either a serial link to the flight controller from a main processor or with TCP/IP or UDP. QUARC supports any underlying communication protocol using its standard URI paradigm for communications. For instance, to use Mavlink over a serial link, a URI such as serial://localhost:1?baud=115200,word=8,parity=none,stop=1 would be used for a 115200 baud, 8N1 serial connection. Similarly, for a TCP/IP client connection, a URI such as tcpip://mydrone:14550 might be used.
Not only does the Mavlink Initialize block determine the communications paradigm used, but it also determines the Mavlink messages supported by the other blocks. In most cases, the standard messages will be sufficient, but in some cases, additional Mavlink messages may be needed. QUARC's Mavlink block set supports custom Mavlink messages.
The way QUARC supports Mavlink messages is through Mavlink message definition files. Mavlink messages are all defined by a standard set of XML files called Mavlink message definition files. QUARC is capable of parsing these message definition files and automatically reconfiguring itself to support all the Mavlink messages found in a message definition file. Message definition files can include other message definition files so that Mavlink messages can be added or altered to the standard set.
Message definition files define the fields within a Mavlink packet and their data types. The Mavlink blocks in QUARC can change the packets used to communicate with a flight controller as well as the data types and number of inputs or outputs of the blocks, all based on the message definition file provided to the Mavlink Initialize block. Thus, QUARC provides a very powerful and extensible mechanism for supporting Mavlink communications.
QUARC provides a standard message definition file called which defines the Mavlink messages that should be common across all Mavlink-based flight controllers. This file is the default, but can be changed on the Messages pane of the Mavlink Initialize block.
One other concept that should be understood when working with Mavlink is the notion of system and component identifiers. A system identifier identifies different systems, which basically means different flight controllers or ground stations. The system identifier used for a ground station is typically 255, so this is the identifier assigned to the Mavlink Initialize block by default. Hence, the QUARC model is generally assumed to act like a ground station controlling a drone, for example. However, the system identifier assigned to the Mavlink Initialize block may be changed.
Component identifiers are used to identify different components running on the same drone. Components are typically numbered from zero, so the default component identifier for the Mavlink Initialize block is zero.
For a more detailed description of the options, refer to the Mavlink Initialize block help page.
Messages are sent and received using the Mavlink Send and Mavlink Receive blocks.
The Mavlink Send block sends a message to components on target systems. It can send a message to more than one target system at the same time. The message to send is selected from a drop-down list. The contents of this list will vary depending on the message definition file selected in the Mavlink Initialize block. When a message is selected, the inputs to the block will change to reflect the fields required for that Mavlink message. For detailed information on each input, a convenient Inputs pane is provided that outlines the data type of each input and provides a brief description to better understand the purpose of the input. This information is all extracted automatically from the message definition files.
Some Mavlink message use enumerations as data types for fields in the message. The Mavlink Enumeration block may be used to output a Mavlink enumeration value to set a field in a Mavlink message being sent.
The Mavlink Receive block receives a message from a component on a target system. It should be noted that the Mavlink protocol is not a command-request protocol. It is not necessary to send a command in order to receive data from the flight controller. Flight controllers often send packets unsolicited to the ground station, such as a heartbeat message to indicate their presence and the health of the connection. Hence, the Mavlink Receive block does not request data from the target system. It will only receive the message if the target system is already sending the message, either unsoliticed, or as the result of a previous Mavlink Send operation.
The message to receive is selected from a drop-down list. The contents of this list will vary depending on the message definition file selected in the Mavlink Initialize block. When a message is selected, the outputs to the block will change to reflect the fields in the selected Mavlink message. For detailed information on each output, a convenient Outputs pane is provided that outlines the data type of each output and provides a brief description to better understand the purpose of the output. This information is all extracted automatically from the message definition file.
The list of Mavlink blocks is enumerated below:
Establishes a connection with one or more drones. |
|
Outputs the value of a Mavlink enumeration constant. |
|
Receives a Mavlink packet from one or more drones. |
|
Sends a Mavlink packet to one or more drones. |
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.