ArduPilot开源飞控之AP_Mount_Backend_Serial
- 1. 源由
- 2. 框架设计
- 2.1 类定义
- 2.2 构造函数
- 2.3 init 方法
- 2.4 受保护成员
- 3. 重要方法
- 4. 总结
- 5. 参考资料
1. 源由
AP_Mount_Backend_Serial
是AP_Mount_Backend基于串口的通信的一个扩展模版。
2. 框架设计
- 继承自
AP_Mount_Backend
- 添加了与串行通信相关的功能
2.1 类定义
class AP_Mount_Backend_Serial : public AP_Mount_Backend
{// 类成员和方法在这里定义
};
- 这行声明了一个新的类
AP_Mount_Backend_Serial
,它继承自基类AP_Mount_Backend
。
2.2 构造函数
public:// 构造函数AP_Mount_Backend_Serial(class AP_Mount &frontend, class AP_Mount_Params ¶ms, uint8_t instance, uint8_t serial_instance) :AP_Mount_Backend(frontend, params, instance),_serial_instance(serial_instance){}
- 构造函数被定义为
public
,意味着可以从类外部访问。 - 构造函数接受四个参数:
AP_Mount &frontend
:一个指向AP_Mount
对象的引用。AP_Mount_Params ¶ms
:一个指向AP_Mount_Params
对象的引用。uint8_t instance
:一个无符号 8 位整数,表示实例编号。uint8_t serial_instance
:一个无符号 8 位整数,表示串行实例编号。
- 构造函数使用初始化列表将基类
AP_Mount_Backend
初始化为frontend
、params
和instance
参数。 _serial_instance
成员变量使用serial_instance
参数进行初始化。
2.3 init 方法
void init() override;
- 这是一个
public
方法,名为init
,它覆盖了基类中的一个虚方法。 init
方法用于执行此实例所需的任何初始化操作。代码片段未提供此方法的实际实现。
2.4 受保护成员
protected:// 内部变量AP_HAL::UARTDriver *_uart; // 与云台连接的 UARTuint8_t _serial_instance; // 该实例的串行实例编号bool _initialised; // 如果 UART 已经初始化,则为 true
protected
部分包含内部成员变量,可以被这个类和派生类访问。AP_HAL::UARTDriver *_uart
:一个指向AP_HAL
命名空间中UARTDriver
对象的指针,表示与云台的 UART 连接。uint8_t _serial_instance
:一个无符号 8 位整数,存储该对象的串行实例编号。bool _initialised
:一个布尔变量,指示 UART 是否已经初始化。
3. 重要方法
AP_Mount_Backend_Serial::init
初始函数,设置了串行实例,并调用基础类AP_Mount_Backend::init
。
// Default init function for every mount
void AP_Mount_Backend_Serial::init()
{const AP_SerialManager& serial_manager = AP::serialmanager();// search for serial port. hild classes should check that uart is not nullptr_uart = serial_manager.find_serial(AP_SerialManager::SerialProtocol_Gimbal, _serial_instance);if (_uart == nullptr) {return;}// initialised successfully if uart is found_initialised = true;// call the parent class initAP_Mount_Backend::init();
}
4. 总结
整个基础类的集成关系,这里梳理一遍:
AP_Mount_Backend├──> AP_Mount_Alexmos├──> AP_Mount_Gremsy├──> AP_Mount_Scripting├──> AP_Mount_Servo├──> AP_Mount_SoloGimbal├──> AP_Mount_SToRM32├──> AP_Mount_Xacti└──> AP_Mount_Backend_Serial├──> AP_Mount_SToRM32_serial├──> AP_Mount_Siyi├──> AP_Mount_Viewpro└──> AP_Mount_Topotek
通过上面的梳理,整个云台设备业务逻辑是通过AP_Mount
来整合,包括摄像头、测距仪、摄像头跟随。
5. 参考资料
【1】ArduPilot开源飞控系统之简单介绍
【2】ArduPilot之开源代码Task介绍
【3】ArduPilot飞控启动&运行过程简介
【4】ArduPilot之开源代码Library&Sketches设计
【5】ArduPilot之开源代码Sensor Drivers设计
【6】ArduPilot开源飞控之AP_Mount
【7】ArduPilot开源飞控之AP_Mount_Backend