步骤:
- 初始化飞控订阅
初始化飞控订阅模块
cpp
DjiFcSubscription_Init()
- 订阅主题
订阅主题函数
cpp
DjiFcSubscription_SubscribeTopic()

订阅四元数,可以使用回调函数,DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ表示订阅的频率。
cpp
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION, DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ,
DjiTest_FcSubscriptionReceiveQuaternionCallback);
订阅速度
cpp
djiStat = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY,
DJI_DATA_SUBSCRIPTION_TOPIC_1_HZ,
NULL);
- 获得订阅数据信息
cpp
djiStat =DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY,
(uint8_t *) &velocity,
sizeof(T_DjiFcSubscriptionVelocity),
×tamp);
Velocity:速度信息保存
cpp
typedef struct Vector3f{
dji_f32_t x; /*!< X-coordinate of the vector. */
dji_f32_t y; /*!< Y-coordinate of the vector. */
dji_f32_t z; /*!< Z-coordinate of the vector. */
} T_DjiVector3f;
typedef struct Velocity {
T_DjiVector3f data;
uint8_t health: 1;
uint8_t reserve: 7;
} T_DjiFcSubscriptionVelocity;
- 取消订阅
cpp
// 取消四元数订阅
djiStat = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION);
// 取消速度订阅
djiStat = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY);
// 取消GPS订阅
djiStat = DjiFcSubscription_UnSubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_GPS_POSITION);
这是单个取消订阅的函数。
只能针对某个特定的数据主题
适用于需要部分取消订阅的场景,而不是全部清空。
- 反初始化飞控订阅模块
cpp
djiStat = DjiFcSubscription_DeInit();
这是一个全局去初始化函数,作用是取消所有订阅的飞控数据,并释放 DjiFcSubscription 相关的资源。
一般在程序退出或者模块不再使用时调用。
它比单独取消某些主题的订阅更彻底,相当于一键清空所有数据流。
整个飞控订阅模块不再使用,直接调用 DjiFcSubscription_DeInit() 即可。