Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions GSRL/Device/inc/dvc_motor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,16 @@ using MotorDM2325 = MotorDM4310;
* @note 反馈帧: 反馈ID = 0x300 + 电机ID, 数据段为大端字节序
* @note 控制电流为标幺值,含义参见达妙力位混控模式中的 i_des 说明
*/
class MotorDMmulti : public Motor
class MotorDMmulti : public MotorGM6020
{
protected:
uint8_t m_dmMotorID; // 达妙电机ID [1,8]
uint16_t m_encoderHistory[2]; // 0:当前值 1:上一次值
int16_t m_currentRPMSpeed; // 电机速度, 单位RPM(已除以100后的真实值)
uint8_t m_errorState; // 反馈帧D[7]错误状态字节, 具体含义详见达妙错误状态说明书
uint8_t m_mergedData[8]; // getMergedControlData 输出缓冲区
uint8_t m_errorState; // 反馈帧D[7]错误状态字节, 具体含义详见达妙错误状态说明书

public:
MotorDMmulti(uint8_t dmMotorID, Controller *controller, uint16_t encoderOffset = 0);
uint8_t getDmMotorID() const;
uint8_t getErrorState() const;
const uint8_t *getMergedControlData(MotorDMmulti &otherMotor);
// getMergedControlData 继承自 MotorGM6020,控制ID不同的电机间调用会被ID守卫拦截

protected:
bool decodeCanRxMessage(const can_rx_message_t &rxMessage) override;
Expand Down
39 changes: 7 additions & 32 deletions GSRL/Device/src/dvc_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,16 +713,13 @@ void MotorDM4310::setMotorZeroPosition()
* | 控制ID | 0x3FE | 0x4FE |
*/
MotorDMmulti::MotorDMmulti(uint8_t dmMotorID, Controller *controller, uint16_t encoderOffset)
: Motor(dmMotorID <= 4 ? 0x3FE : 0x4FE,
0x300u + dmMotorID,
controller,
encoderOffset),
m_dmMotorID(dmMotorID),
m_currentRPMSpeed(0),
: MotorGM6020(dmMotorID, controller, encoderOffset),
m_errorState(0)
{
m_encoderHistory[0] = 0;
m_encoderHistory[1] = 0;
// 调用GM6020构造函数后修正为达妙一控四固件的发送和接收ID
m_motorControlMessageID = dmMotorID <= 4 ? 0x3FE : 0x4FE;
m_motorFeedbackMessageID = 0x300u + dmMotorID;
m_motorControlHeader.StdId = m_motorControlMessageID;
}

/**
Expand All @@ -732,7 +729,7 @@ MotorDMmulti::MotorDMmulti(uint8_t dmMotorID, Controller *controller, uint16_t e
void MotorDMmulti::convertControllerOutputToMotorControlData()
{
int16_t giveControlValue = (int16_t)m_controllerOutput; // 控制电流标幺值
uint8_t offset = (uint8_t)(((m_dmMotorID - 1) & 0x3) * 2);
uint8_t offset = (uint8_t)(((m_djiMotorID - 1) & 0x3) * 2);
m_motorControlData[offset] = (uint8_t)(giveControlValue & 0xFF); // 低 8 位
m_motorControlData[offset + 1] = (uint8_t)((giveControlValue >> 8) & 0xFF); // 高 8 位
}
Expand Down Expand Up @@ -769,7 +766,7 @@ bool MotorDMmulti::decodeCanRxMessage(const can_rx_message_t &rxMessage)
*/
uint8_t MotorDMmulti::getDmMotorID() const
{
return m_dmMotorID;
return m_djiMotorID;
}

/**
Expand All @@ -781,28 +778,6 @@ uint8_t MotorDMmulti::getErrorState() const
return m_errorState;
}

/**
* @brief 合并两个同控制ID的一控四固件达妙电机CAN控制数据, 同时触发双方掉线检测
* @param otherMotor 另一个同控制ID的达妙一控四电机
* @return const uint8_t* 合并后的8字节CAN控制数据
* @note 返回的指针指向内部静态缓冲区, 下次调用会覆盖
*/
const uint8_t *MotorDMmulti::getMergedControlData(MotorDMmulti &otherMotor)
{
const uint8_t *selfData = this->getMotorControlData();
const uint8_t *otherData = otherMotor.getMotorControlData();

if (m_motorControlMessageID != otherMotor.m_motorControlMessageID) {
return selfData;
}

memcpy(m_mergedData, selfData, 8);
uint8_t offset = (uint8_t)(((otherMotor.m_dmMotorID - 1) & 0x3) * 2);
m_mergedData[offset] = otherData[offset];
m_mergedData[offset + 1] = otherData[offset + 1];
return m_mergedData;
}

/******************************************************************************
* 瓴控MG系列电机类实现
******************************************************************************/
Expand Down
Loading