...
📝 1. Overview
Initially, the focus is on basic functionality: sending drone state data to the ground station at regular intervals and establishing two-way communication between TM and the ground station (Mission Planner).
🎯 2. Goals
Achieve transmission of GLOBAL_POSITION_INT & ATTITUDE MAVLink messages from the drone to the ground control station to be displayed on (Mission Planner) via RFD 900 radio.
Thread 1 (translateToMavlinkThread)
Code Block | ||
---|---|---|
| ||
/**
* @brief This thread is responsible for taking the bytes from the GSC.DMAReceiveBuffer and
* converting them to Mavlink messages/triggering the callbacks associated with each mavlink
* message.
*/
void translateToMavlinkThread()
{
while (true)
{
MT.bytesToMavlinkMsg(GSC.DMAReceiveBuffer);
vTaskDelay(pdMS_TO_TICKS(10)); // Adjust the delay as necessary
}
} |
Thread 2 (mavlinkToBytesThread)
Code Block | ||
---|---|---|
| ||
/**
* @brief This thread is responsible for taking data from other managers and converting
* them to mavlink bytes, then putting them into GSC.lowPriorityTransmitBuffer.
*/
void mavlinkToBytesThread()
{
while (true)
{
// START: fill GSC.lowPriorityTransmitBuffer with data to transmit
// END: fill GSC.lowPriorityTransmitBuffer with data to transmit
vTaskDelay(pdMS_TO_TICKS(10)); // Adjust the delay as necessary
}
} |
DMA
Code Block | ||
---|---|---|
| ||
void GroundStationComms::sendToGroundStation(CircularBuffer &transmissionBuffer)
{
// Send the bytes in transmissionBuffer to the ground station via RFD900
}
void GroundStationComms::receiveFromGroundStationISR()
{
// if GSC.DMAReceiveBuffer has enough space for the new data add it
//otherwise discard the data
//end of ISR
} |
Timer Based Interrupt
Code Block | ||
---|---|---|
| ||
void TimerInterrupt::registerTimerInterrupt(int timeIntervalMs, void (*function)())
{
// execute the function every timeIntervalMs using a timer interrupt on the STM32
function();
} |
Timer Interrupt 1 (Low priority transmission)
Code Block | ||
---|---|---|
| ||
/**
* @brief This interrupt service routine is called every 500ms. It is responsible for
* sending non routine data to the ground station. Such as arm disarmed message status,
* fufilling data requests from the ground station etc. This is the lowest priority data
* in the GSC.lowPriorityTransmitBuffer.
*/
void TimerISR500ms()
{
// transmit low priority the data via GSC.sendToGroundStation(); function
GSC.sendToGroundStation(GSC.lowPriorityTransmitBuffer);
} |
Timer Interrupt 2 (High priority transmission)
...
language | cpp |
---|
...
🛠️ 3. Class Definitions
📡 GroundStationComms
Description
Handles communication between the ground station and drone using RFD 900 or equivalent modules, utilizing circular buffers for MAVLink message management.
Properties
DMAReceiveBuffer
: CircularBuffer - Stores incoming data.lowPriorityTransmitBuffer
: CircularBuffer - For low-priority data dispatch.highPriorityTransmitBuffer
: CircularBuffer - For high-priority routine data dispatch.
Methods
sendToGroundStation(CircularBuffer &transmissionBuffer)
: Sends data to the ground station.receiveFromGroundStationISR()
: ISR for incoming data, discards ifDMAReceiveBuffer
is full.
Additional Notes
Flexible design compatible with various communication protocols and setups.
⏲️ TimerInterrupt
Description
Facilitates STD32 timer interrupts for periodic callbacks, essential for consistent data dispatch to the ground station.
Method Signature
void registerTimerInterrupt(int timeIntervalMs, void (*function)())
Parameters
timeIntervalMs
: The timer interval in milliseconds.function
: The callback function.
Implementation Details
Example of function execution; real application requires STM32 timer setup.
🔄 MavlinkTranslator
Description
Translates MAVLink messages between byte streams and the drone/ground station.
Methods
bytesToMavlinkMsg(CircularBuffer &rxFromGroundByteQueue)
: Decodes incoming bytes to MAVLink messages.rxFromGroundByteQueue
: Buffer for incoming ground station bytes.
addMavlinkMsgToByteQueue(mavlink_message_t &msg, CircularBuffer &txToGroundByteQueue)
: Encodes MAVLink messages for transmission.msg
: The MAVLink message.txToGroundByteQueue
: Buffer for outgoing bytes to the ground station.
Additional Notes
Crucial for continuous and intermittent data handling via encoding and decoding.
🔗 CircularBuffer
Description
Manages byte streams as MAVLink messages within TM components, using a circular queue for effective data buffering.
Properties
MAVLinkByte
:unsigned char
- Data type for queue storage, subject to change based on MAVLink byte requirements.
Methods
remainingMemory()
: Indicates available queue bytes.Returns:
int
- Available memory.
dequeue()
: Retrieves the next byte from the queue.Returns:
MAVLinkByte
- The dequeued byte.
enqueue(MAVLinkByte byte)
: Adds a byte to the queue.Parameters:
byte
:MAVLinkByte
- Byte to add.
Additional Notes
A fundamental class for data integrity and memory efficiency in processing or waiting for transmission.
🚀 Main Class Definition: System Initialization and Task Management
Instances
GroundStationComms GSC: Oversees ground station comms.
MavlinkTranslator MT: MAVLink message and byte stream translator.
TimerInterrupt TI: Timer-based task manager.
🌐 Function: init
Description
Sets up timer interrupts and FreeRTOS tasks for MAVLink communication and translation.
Components
Timer Interrupts: Configured for 500ms and 1000ms operation intervals.
FreeRTOS Tasks:
translateToMavlinkThread
: ProcessesGSC.DMAReceiveBuffer
bytes into MAVLink messages.mavlinkToBytesThread
: Loads MAVLink bytes intoGSC.lowPriorityTransmitBuffer
.
Scheduler: Engages the FreeRTOS scheduler for task oversight.
🔄 Tasks and ISRs
translateToMavlinkThread & mavlinkToBytesThread: Converts between MAVLink messages and byte streams for drone-ground station communication.
TimerISR500ms & TimerISR1000ms: Ensures regular data dispatch from both
GSC.lowPriorityTransmitBuffer
andGSC.highPriorityTransmitBuffer
.
⚙️ 5. Integration Points
Details subsystem interactions within the project and with external entities, focusing on integration mechanisms and their objectives.
PREVIOUS:
TM Will:
Drone to Ground Station Communication via RFD 900 Radio
RX
Receive raw MAVLink bytes from the ground station.
TX
Transmit raw MAVLink bytes from the ground station.
Encode & Decode Raw MAVLink Data
Encode
Into Mavlink bytes to send to Mission Planner transmitted via RFD 900
Decode
Decode raw Mavlink bytes received from Mission Planner, received via RFD 900.
Ingest Drone State Data (Lat, Lng, Velocity, Pitch, etc) via C++ references
Should these references be passed at TM instantiation?
Is there a finite list of drone state data TM will be ingesting?
Sample rate?
TM will communicate with other managers via [UNDEFINED COMMUNICATION MEDIUM]: Maybe for TM, this should go in M3?
ROS LCM?
Byte Streams?
MQTT Style?
TM will have an input/output testing strategy
?