cmvr-es/include/hardware/can/motor_protocol/motorprotocolmanager.h
2025-10-29 16:26:15 +08:00

50 lines
1.7 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
{
std::string node_id; //电机ID
std::string jointName; //关节名称
double limitQLb; //逆时针限位
double limitQUb; //顺时针限位
double limitQd; //加速度限制
};
public:
explicit MotorProtocolManager(const XmlNode &cfg,std::shared_ptr<device::CanSender<msgs::RobotDetail>> sender,
std::shared_ptr<device::MessageManager<msgs::RobotDetail>> manager);
~MotorProtocolManager() = default;
//根据协议类型获取协议实例对象
std::shared_ptr<AbstractMotorProtocol> getMotorProtocol(const std::string &protocolType);
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