MAVLink Control
Main application with the "linear" sequences.
Uses main standard input/output C header files, strings, as well as <interface.h>
and <commands.h>
defined headers.
int main(void){
autopilot_intialize();
#ifdef STM32F4
// initialize LIS3DSH accelerometer
lis3dsh_init();
#endif
serial_start();
while (1) {
commands();
}
return 0;
}
1. autopilot_intialize()
MAVLink Control calls the autopilot_intialise()
function first which is defined in interface.cpp
. This function defines the necessary variables for the offboard control status, armed/disarmed status, and especially the target system, autopilot and companion IDs :
system_id = 1;
autopilot_id = 1;
companion_id = 0;
2. lis3dsh_init()
If we aren't running on a nix system, (e.g the #ifdef STM32F4
is true, which is defined in the corresponding Makefile), we initialize the LIS3DSH accelerometer for the STM32F4-discovery board.
Note : It's crucial that the USART and SPI configurations are initialized earlier in the program.
lis3dsh_init()
calls spi_setup(), which configures the necessary GPIO, clocks, USART and SPI.
More on this in the separate chapter "LIS3DSH" which explains the functionnality of each method.
3. serial_start()
This function is defined in serial_port_stm32.cpp
and serial_port_pc.cpp
, depending on the hardware, it either starts and opens the necessary port on the nix system to communicate with the Pixhawk through USB/RS-232 Converter (FTDI Cable) or initialize the required USART, interrupts, and timer to achieve the same functionnality on the STM32F4-disovery board.
4. commands()
Commands () is simply a very basic scheduler in a while (1)
loop that calls the needed function from commands.cpp
. This scheduler enters the needed command then read a message structure(read_messages()
), lock in the initial postion with autopilot_start()
, writes a void message (autopilot_write_helper()
) and then enters a switch and executes each command in a sequential fation.
void commands(void){
operation(10);
// operation_extended(10);
// square_operation(7);
// circle_operation(5);
// automatic_takeoff(10);
// flight_control_sequence(10);
}
The switch command will depend on a Program_counter variable that, depending on configuartion, might either quit the program, or get stuck into an infinite loop, reading MAVLink messages.