cmvr-es/include/hardware/can/motor_protocol/motorprotocolmanager.h
2025-11-06 17:27:37 +08:00

54 lines
1.9 KiB
C++

//
// Created by linbo on 2025/10/22.
//
#ifndef CMVR_ES_MOTORPROTOCOLMANAGER_H
#define CMVR_ES_MOTORPROTOCOLMANAGER_H
#include <unordered_map>
#include <memory>
#include "abstractmotorprotocol.h"
#include "devices/abstract_canbus.h"
#include "canbus/can_comm/can_sender.h"
#include "canbus/can_comm/can_receiver.h"
#include "canbus/can_comm/message_manager.h"
#include "cmvr/msgs/robot_detail.pb.h"
namespace cmvr::hardware
{
class MotorProtocolManager
{
public:
struct MotorInfo
{
uint8_t node_id; //电机ID
std::string jointName; //关节名称
double limitQLb; //逆时针限位
double limitQUb; //顺时针限位
double limitQd; //加速度限制
std::shared_ptr<AbstractMotorProtocol> motorProtocol;
};
public:
explicit MotorProtocolManager(const XmlNode &cfg,std::shared_ptr<device::CanSender<msgs::RobotDetail>> sender,
std::shared_ptr<device::MessageManager<msgs::RobotDetail>> manager);
~MotorProtocolManager() = default;
uint8_t getNodeId(const std::string& joint_name);
//根据协议类型获取协议实例对象
std::shared_ptr<AbstractMotorProtocol> getMotorProtocol(const std::string &protocolType);
const MotorInfo& getMotorInfo(const std::string& joint_name);
private:
std::shared_ptr<device::CanSender<msgs::RobotDetail> > can_sender_{nullptr};
std::shared_ptr<device::MessageManager<msgs::RobotDetail> > message_manager_{nullptr};
std::shared_ptr<AbstractMotorProtocol> ti5Protocol_{nullptr};
//协议类型,协议实例对象
std::unordered_map<std::string, std::shared_ptr<AbstractMotorProtocol>> motor_protocols_;
//协议类型,电机参数
std::unordered_map<std::string, std::vector<MotorInfo>> motors_;
};
}
#endif //CMVR_ES_MOTORPROTOCOLMANAGER_H