0
0
Drone Programmingprogramming~10 mins

MAVLink message structure in Drone Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - MAVLink message structure
Start: Prepare message
Add Header: Start sign, length, seq, sysid, compid, msgid
Add Payload: Data fields
Calculate CRC
Append CRC to message
Send complete MAVLink message
This flow shows how a MAVLink message is built step-by-step from header to payload to checksum before sending.
Execution Sample
Drone Programming
header = [0xFE, 2, 1, 1, 1, 24]
payload = [100, 200]
crc = calculate_crc(header + payload)
message = header + payload + crc
send(message)
Builds a MAVLink message with header, payload, calculates CRC, then sends it.
Execution Table
StepActionData AddedMessage StateNotes
1Start message preparationNone[]Empty message buffer
2Add header fields[0xFE, 2, 1, 1, 1, 24][0xFE, 2, 1, 1, 1, 24]Header includes start sign, length, seq, sysid, compid, msgid
3Add payload data[100, 200][0xFE, 2, 1, 1, 1, 24, 100, 200]Payload contains message-specific data
4Calculate CRCCRC bytes[0xFE, 2, 1, 1, 1, 24, 100, 200, crc1, crc2]CRC ensures message integrity
5Append CRC to message[crc1, crc2][0xFE, 2, 1, 1, 1, 24, 100, 200, crc1, crc2]CRC appended to message
6Send messageFull message[0xFE, 2, 1, 1, 1, 24, 100, 200, crc1, crc2]Message sent over communication link
7EndNoneMessage sentProcess complete
💡 Message fully constructed and sent; process ends.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
header[][0xFE, 2, 1, 1, 1, 24][0xFE, 2, 1, 1, 1, 24][0xFE, 2, 1, 1, 1, 24][0xFE, 2, 1, 1, 1, 24][0xFE, 2, 1, 1, 1, 24]
payload[][][100, 200][100, 200][100, 200][100, 200]
crcNoneNoneNone[crc1, crc2][crc1, crc2][crc1, crc2]
message[][0xFE, 2, 1, 1, 1, 24][0xFE, 2, 1, 1, 1, 24, 100, 200][0xFE, 2, 1, 1, 1, 24, 100, 200][0xFE, 2, 1, 1, 1, 24, 100, 200, crc1, crc2][0xFE, 2, 1, 1, 1, 24, 100, 200, crc1, crc2]
Key Moments - 3 Insights
Why do we add a CRC at the end of the MAVLink message?
The CRC is added to check if the message was received correctly without errors, as shown in step 4 of the execution_table.
What does the header part of the MAVLink message contain?
The header contains fixed fields like start sign, length, sequence number, system ID, component ID, and message ID, as seen in step 2 of the execution_table.
Why do we add the payload after the header and before the CRC?
Payload holds the actual data for the message and must be between header and CRC to be included in the CRC calculation, as shown in steps 3 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what does the message state include?
AOnly the header fields
BHeader fields plus CRC
CHeader fields plus payload data
DOnly the payload data
💡 Hint
Check the 'Message State' column at step 3 in the execution_table.
At which step is the CRC calculated and added to the message?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Look for the step mentioning 'Calculate CRC' in the execution_table.
If the payload length changes, which part of the message must also be updated?
ALength field in header
BSequence number
CStart sign in header
DCRC only
💡 Hint
Refer to the header fields in step 2 and how length relates to payload size.
Concept Snapshot
MAVLink message structure:
- Header: start sign, length, seq, sysid, compid, msgid
- Payload: message data
- CRC: checksum for error detection
Build message by adding header, payload, then CRC
Send complete message over link
Full Transcript
This visual execution shows how a MAVLink message is built step-by-step. First, the message preparation starts with an empty buffer. Then the header fields are added, including start sign, length, sequence number, system ID, component ID, and message ID. Next, the payload data is appended, which contains the actual message information. After that, the CRC checksum is calculated over the header and payload to ensure message integrity and appended to the message. Finally, the complete message is sent over the communication link. Variables like header, payload, crc, and message change their values as the message is constructed. Key points include the purpose of the CRC for error checking, the contents of the header, and the order of adding payload before CRC. The quizzes test understanding of message state at each step, when CRC is added, and how payload length affects the header length field.