-
Notifications
You must be signed in to change notification settings - Fork 14
重构大疆电机和达妙电机的控制数据合并方法,修复掉线检测失效问题 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -533,26 +533,25 @@ uint8_t MotorGM6020::getDjiMotorID() const | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @brief 大疆电机加法运算符重载,用于合并CAN控制数据 | ||||||
| * @brief 合并两个同控制ID的大疆电机CAN控制数据, 同时触发双方掉线检测 | ||||||
| * @param otherMotor 另一个同控制ID的大疆电机 | ||||||
| * @return const uint8_t* 合并后的8字节CAN控制数据 | ||||||
| * @note 返回的指针指向内部静态缓冲区, 下次调用会覆盖 | ||||||
| */ | ||||||
| MotorGM6020 MotorGM6020::operator+(const MotorGM6020 &otherMotor) const | ||||||
| const uint8_t *MotorGM6020::getMergedControlData(MotorGM6020 &otherMotor) | ||||||
| { | ||||||
| const uint8_t *selfData = this->getMotorControlData(); | ||||||
| const uint8_t *otherData = otherMotor.getMotorControlData(); | ||||||
|
|
||||||
| if (m_motorControlMessageID != otherMotor.m_motorControlMessageID) { | ||||||
| return *this; | ||||||
| return selfData; | ||||||
| } | ||||||
|
|
||||||
| MotorGM6020 combineMotor = *this; | ||||||
| if (otherMotor.m_djiMotorID < 5) { | ||||||
| uint8_t offset = otherMotor.m_djiMotorID * 2 - 2; | ||||||
| combineMotor.m_motorControlData[offset] = otherMotor.m_motorControlData[offset]; | ||||||
| combineMotor.m_motorControlData[offset + 1] = otherMotor.m_motorControlData[offset + 1]; | ||||||
| } else { | ||||||
| uint8_t offset = otherMotor.m_djiMotorID * 2 - 10; | ||||||
| combineMotor.m_motorControlData[offset] = otherMotor.m_motorControlData[offset]; | ||||||
| combineMotor.m_motorControlData[offset + 1] = otherMotor.m_motorControlData[offset + 1]; | ||||||
| } | ||||||
| return combineMotor; | ||||||
| memcpy(m_mergedData, selfData, 8); | ||||||
| uint8_t offset = (uint8_t)(((otherMotor.m_djiMotorID - 1) & 0x3) * 2); | ||||||
| m_mergedData[offset] = otherData[offset]; | ||||||
|
Comment on lines
+550
to
+552
|
||||||
| m_mergedData[offset + 1] = otherData[offset + 1]; | ||||||
| return m_mergedData; | ||||||
|
Comment on lines
+541
to
+554
|
||||||
| } | ||||||
|
|
||||||
| /****************************************************************************** | ||||||
|
|
@@ -783,20 +782,25 @@ uint8_t MotorDMmulti::getErrorState() const | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @brief 达妙一控四电机加法运算符重载, 用于合并同控制ID下多个电机的CAN控制数据 | ||||||
| * @brief 合并两个同控制ID的一控四固件达妙电机CAN控制数据, 同时触发双方掉线检测 | ||||||
| * @param otherMotor 另一个同控制ID的达妙一控四电机 | ||||||
| * @return const uint8_t* 合并后的8字节CAN控制数据 | ||||||
| * @note 返回的指针指向内部静态缓冲区, 下次调用会覆盖 | ||||||
|
||||||
| * @note 返回的指针指向内部静态缓冲区, 下次调用会覆盖 | |
| * @note 返回的指针指向当前对象的内部成员缓冲区, 仅当前对象的下次调用会覆盖 |
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同样地,这里新增使用 memcpy,建议显式包含 <cstring>/<string.h>,避免依赖其他头文件的传递包含导致后续编译脆弱。
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
与上面的 GM6020 同理:该实现每次都从 this->getMotorControlData() 重新拷贝整帧,再覆盖另一个电机的 2 字节,因此无法通过多次调用累积合并 3~4 个电机(会丢失此前已合并的电机数据)。考虑到该类语义是一控四,建议提供可累积/可合并多个电机的接口,或至少在注释中明确该方法仅合并两台电机且不支持链式累积。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释里写“返回的指针指向内部静态缓冲区”,但这里返回的是对象成员
m_mergedData(每个对象一份),并非 static 缓冲区。建议将说明改为“内部成员缓冲区/对象内缓冲区”,并明确仅同一对象的下次调用会覆盖。