In the official
Http://ardupilot.org/dev/docs/learning-ardupilot-the-example-sketches.html
In this tutorial, it should be seen that the terminal prints out a series of GPs values, but I am successful in compiling and burning after the terminal can not output any information. After reading the Ardupilot's underlying code in detail, I finally found the reason.
The original code (note in order to express the main problem of the code omitted):
/// -*-Tab-width:4; mode:c++; C-basic-offset:4; Indent-tabs-mode:nil-*- simple Hello World Sketch Andrew Tridgell September ( */ #include <ap_hal/ap_hal.h>const ap_hal::hal& HAL = Ap_hal::get_hal (); void Setup () {
Hal.console->println (" GPS AUTO Library Test "); Hal.console->println ("Hello world!"); Hal.scheduler ->delay (); }ap_hal_main ();
Post-Modification Code
#include <AP_HAL/AP_HAL.h>
Const ap_hal::hal& HAL = Ap_hal::get_hal ();
class gps_auto_test: public Span style= "color: #000000;" > ap_hal::hal::callbacks{ public : void Setup () {Hal.console println ( gps AUTO library test " ); void loop () {Hal.console->printl N ("Hello world!"); Hal.scheduler ->delay (); }}; Gps_auto_test Gat; // Register above functions in HAL board level Ap_hal_main_callbacks (&gat);
After Ap_hal_main_callbacks (&gat) is executed, the program automatically calls Gat.setup () and Gat.loop ().
Execution Result:
In fact Ap_hal_main_callbacks (&gat) and Ap_hal_main () Two macros are implemented in almost the same way, the latter will assemble the setup and loop into a class before using the former. I read the source code also did not find any problem, but really can not execute, so the best way is to package setup and loop into a class after the use of Ap_hal_main_callbacks (&gat) Form.
Note that the encapsulated class inherits the public Ap_hal::hal::callbacks class.
Pixhawk on Burn write Ardupilot tutorial routines after flight control does not work the workaround