74 lines
3.1 KiB
C++
74 lines
3.1 KiB
C++
//
|
|
// Created by lgv on 2025/8/1.
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
#include <cstdint>
|
|
#include "cmvr/msgs/canopen.pb.h"
|
|
#include "cmvr/msgs/motor.pb.h"
|
|
|
|
namespace cmvr {
|
|
namespace device {
|
|
class MotorProtocolInterface {
|
|
public:
|
|
enum class CommProto : uint8_t {
|
|
CANOPEN = 1,
|
|
ETHERCAT = 2,
|
|
CUSTOM = 3
|
|
};
|
|
virtual ~MotorProtocolInterface() = default;
|
|
|
|
/**
|
|
* @brief 用于初始化与通讯协议相关的设置
|
|
* @param node_id 电机Id
|
|
* @return
|
|
*/
|
|
virtual bool initNode(uint8_t node_id) = 0;
|
|
|
|
virtual bool setMode(uint8_t node_id,msgs::RunMode mode ) = 0;
|
|
virtual msgs::RunMode getMode(uint8_t node_id) = 0;
|
|
virtual void setLimitQdd(uint8_t node_id, double u_qdd,double l_qdd) = 0;
|
|
virtual void setLimitQd(uint8_t node_id,double qd) = 0;
|
|
virtual void setLimitQ(uint8_t node_id, double ub, double lb) = 0;
|
|
virtual bool calibrateZeroQ(uint8_t node_id) = 0;
|
|
virtual bool reachedTargetQ(uint8_t node_id) = 0;
|
|
// target_q: rad, max_qd: rad/s, max_qdd: rad/s^2.
|
|
// Profile Position 写入目标位置和轮廓速度/加速度,并触发一次新目标。
|
|
virtual bool commandProfilePosition(uint8_t node_id,
|
|
double target_q,
|
|
double max_qd,
|
|
double max_qdd) = 0;
|
|
// target_qd: rad/s, max_qdd: rad/s^2.
|
|
// Profile Velocity 写入目标速度和轮廓加速度。
|
|
virtual bool commandProfileVelocity(uint8_t node_id,
|
|
double target_qd,
|
|
double max_qdd) = 0;
|
|
// target_q: rad, target_qd: rad/s.
|
|
// Cyclic Position 周期写入目标位置和目标速度。
|
|
virtual bool commandCyclicPosition(uint8_t node_id,
|
|
double target_q,
|
|
double target_qd) = 0;
|
|
// target_qd: rad/s.
|
|
// Cyclic Velocity 周期写入目标速度。
|
|
virtual bool commandCyclicVelocity(uint8_t node_id,
|
|
double target_qd) = 0;
|
|
// target_tau: N*m.
|
|
virtual bool commandCyclicTorque(uint8_t node_id, double target_tau) = 0;
|
|
virtual void setMotorConversion(uint8_t node_id,
|
|
double encoder_counts_per_rev,
|
|
double gear_ratio) = 0;
|
|
virtual bool torqueOn(uint8_t node_id) = 0;
|
|
virtual bool torqueOff(uint8_t node_id) = 0;
|
|
virtual bool brakeRelease(uint8_t node_id) = 0;
|
|
virtual bool quickStop(uint8_t node_id) = 0;
|
|
|
|
virtual double getQ(uint8_t node_id) = 0;
|
|
virtual double getQd(uint8_t node_id) = 0;
|
|
CommProto comm_proto{CommProto::CANOPEN};
|
|
protected:
|
|
};
|
|
}
|
|
}
|