为了方便大家深入了解飞控工作原理与编程,ArduPilot 提供了许多示例,位于 /Library 文件中,本文将以串口为例,为大家展示如何利用这些示例进一步深入开发 APM 飞控。
官方文档内容,方便大家对照查阅:https://ardupilot.org/dev/docs/learning-ardupilot-the-example-sketches.html
1,首先进入源码主目录,如何了解目前有哪里示例可以使用呢 ?通过如下指令:
./waf list | grep 'examples'
系统将会列出可以使用的示例,随着版本的更新,示例将会越来越多。
2,我们将以 UART_test 为例,演示整个调试流程, 找到示例源码 UART_test.cpp,位于
/ardupilot/libraries/AP_HAL/examples/UART_test/UART_test.cpp
打开源代码,可以看到内容是重复输出代码编号
void loop(void)
{
test_uart(hal.uartA, "uartA");
test_uart(hal.uartB, "uartB");
test_uart(hal.uartC, "uartC");
test_uart(hal.uartD, "uartD");
test_uart(hal.uartE, "uartE");
// also do a raw printf() on some platforms, which prints to the
// debug console
#if HAL_OS_POSIX_IO
::printf("Hello on debug console at %.3f seconds\n", (double)(AP_HAL::millis() * 0.001f));
#endif
hal.scheduler->delay(1000);
}
3,尝试修改程序,然后编译程序并且下载
3.1,回到源码主目录
3.2,配置硬件,一般不变化不用重新配置,使用指令 ./waf configure --board px4-v2
root@ubuntu:/home/saffron/lrr/ardupilot# ./waf configure --board px4-v2
Setting top to : /home/saffron/lrr/ardupilot
Setting out to : /home/saffron/lrr/ardupilot/build
Autoconfiguration : enabled
Setting board to : px4-v2
Checking for program 'arm-none-eabi-ar' : /opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-ar
Using toolchain : arm-none-eabi
Checking for 'g++' (C++ compiler) : /usr/lib/ccache/arm-none-eabi-g++
Checking for 'gcc' (C compiler) : /usr/l