cmvr-es/include/hardware/can/motor_protocol/motorprotocolmanager.h

51 lines
1.8 KiB
C
Raw Normal View History

2025-10-24 09:51:14 +08:00
//
// 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"
2025-10-29 16:26:15 +08:00
#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"
2025-10-24 09:51:14 +08:00
2025-10-24 10:51:49 +08:00
namespace cmvr::hardware
2025-10-24 09:51:14 +08:00
{
class MotorProtocolManager
{
public:
2025-10-29 16:26:15 +08:00
struct MotorInfo
{
2025-11-06 15:58:32 +08:00
uint8_t node_id; //电机ID
2025-10-29 16:26:15 +08:00
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);
2025-10-24 09:51:14 +08:00
~MotorProtocolManager() = default;
2025-11-06 15:58:32 +08:00
uint8_t getNodeId(const std::string& joint_name);
2025-10-29 16:26:15 +08:00
//根据协议类型获取协议实例对象
std::shared_ptr<AbstractMotorProtocol> getMotorProtocol(const std::string &protocolType);
2025-10-24 09:51:14 +08:00
private:
2025-10-29 16:26:15 +08:00
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};
//协议类型,协议实例对象
2025-10-24 09:51:14 +08:00
std::unordered_map<std::string, std::shared_ptr<AbstractMotorProtocol>> motor_protocols_;
2025-10-29 16:26:15 +08:00
//协议类型,电机参数
std::unordered_map<std::string, std::vector<MotorInfo>> motors_;
2025-10-24 09:51:14 +08:00
};
}
#endif //CMVR_ES_MOTORPROTOCOLMANAGER_H