Lazy loaded image
AP系列04-
Words 418Read Time 2 min
2025-7-16
type
Post
date
Aug 13, 2024
slug
ap_series_library_examples
category
🛩️ APM源码分析
icon
password
 
💡
官方推荐解析范例做为探索源码第一步,通过阅读、编译和运行范例,可以理解源码API接口和约定。本节简介如何使用。

使用范例 - 烧录Pixhawk

  • ./waf list|grep 'examples' 可查询到提供的范例
  • 上传到硬件上,可以通过 console 查看输出(对于Pixhawk ,是连接的USB)
ttyACM1 是console
ttyACM1 是console
消息也可以输出到 mavproxy(适用于linux系统)
 

使用范例 - SITL模拟

 

理解样例代码

The hal reference

使用AP_HAL功能,需要声明一个hal引用(实际声明在AP_HAL_XXX 库中),以访问 AP_HAL::HAL 对象提供的硬件相关接口,包括打印信息到控制台,休眠和I2C/SPI总线通讯。
  • hal.console->printf() to print strings
  • AP_HAL::millis() and AP_HAL::micros() to get the time since boot
  • hal.scheduler->delay() and hal.scheduler->delay_microseconds() to sleep for a short time
  • hal.gpio->pinMode(), hal.gpio->read() and hal.gpio->write() for accessing GPIO pins
  • I2C access via hal.i2c
  • SPI access via hal.spi

The setup() and loop() functions

setup() :调用一次,初始化库
loop():连续运行,完成实际工作

The AP_HAL_MAIN() macro

AP_HAL_MAIN(); 通过宏添加main函数
 
上一篇
Data Structure and Algorithm
下一篇
用面试拷问嵌入式技术栈

Comments
Loading...