update HardWareManager
This commit is contained in:
parent
53fb1f1d6d
commit
f9521a72e7
@ -94,5 +94,5 @@ target_link_libraries(cmvr_es PRIVATE
|
|||||||
cmvr_es::httpclient
|
cmvr_es::httpclient
|
||||||
cmvr_es::device::canbus
|
cmvr_es::device::canbus
|
||||||
cmvr_es::device::ti5motor
|
cmvr_es::device::ti5motor
|
||||||
cmvr_es::ctrl::controller
|
#cmvr_es::ctrl::controller
|
||||||
)
|
)
|
||||||
@ -5,39 +5,39 @@
|
|||||||
<HardwareManager>
|
<HardwareManager>
|
||||||
<CanManager>
|
<CanManager>
|
||||||
<CanGroup id="LeftArmCAN" channelId="0" enable="true">
|
<CanGroup id="LeftArmCAN" channelId="0" enable="true">
|
||||||
<MotorManager>
|
<MotorProtocolManager>
|
||||||
<Ti5Motor id="23" jointName="L_SHOULDER_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="23" jointName="L_SHOULDER_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="24" jointName="L_SHOULDER_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="24" jointName="L_SHOULDER_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="25" jointName="L_SHOULDER_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="25" jointName="L_SHOULDER_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="26" jointName="L_ELBOW_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="26" jointName="L_ELBOW_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="27" jointName="L_WRIST_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="27" jointName="L_WRIST_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="28" jointName="L_WRIST_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="28" jointName="L_WRIST_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="1" jointName="L_WRIST_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="1" jointName="L_WRIST_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
</MotorManager>
|
</MotorProtocolManager>
|
||||||
</CanGroup>
|
</CanGroup>
|
||||||
<CanGroup id="RightArmCAN" channelId="1" enable="true">
|
<CanGroup id="RightArmCAN" channelId="1" enable="true">
|
||||||
<MotorManager>
|
<MotorProtocolManager>
|
||||||
<Ti5Motor id="16" jointName="R_SHOULDER_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="16" jointName="R_SHOULDER_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="17" jointName="R_SHOULDER_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="17" jointName="R_SHOULDER_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="18" jointName="R_SHOULDER_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="18" jointName="R_SHOULDER_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="19" jointName="R_ELBOW_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="19" jointName="R_ELBOW_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="20" jointName="R_WRIST_P" limitQLb="-3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="20" jointName="R_WRIST_P" limitQLb="-3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="21" jointName="R_WRIST_Y" limitQLb="-1.102" limitQUb="1.02" limitQd="3.0"/>
|
<Ti5MotorProtocol id="21" jointName="R_WRIST_Y" limitQLb="-1.102" limitQUb="1.02" limitQd="3.0"/>
|
||||||
<Ti5Motor id="22" jointName="R_WRIST_R" limitQLb="-0.293" limitQUb="1.57079" limitQd="3.0"/>
|
<Ti5MotorProtocol id="22" jointName="R_WRIST_R" limitQLb="-0.293" limitQUb="1.57079" limitQd="3.0"/>
|
||||||
</MotorManager>
|
</MotorProtocolManager>
|
||||||
</CanGroup>
|
</CanGroup>
|
||||||
<CanGroup id="NeckCAN" channelId ="2" enable="true">
|
<CanGroup id="NeckCAN" channelId ="2" enable="true">
|
||||||
<MotorManager>
|
<MotorProtocolManager>
|
||||||
<Ti5Motor id="32" jointName="HEAD_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="32" jointName="HEAD_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="30" jointName="HEAD_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="30" jointName="HEAD_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="31" jointName="HEAD_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="31" jointName="HEAD_R" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
</MotorManager>
|
</MotorProtocolManager>
|
||||||
</CanGroup>
|
</CanGroup>
|
||||||
<CanGroup id = "WaistCAN" channelId ="3" enable="false">
|
<CanGroup id = "WaistCAN" channelId ="3" enable="false">
|
||||||
<MotorManager>
|
<MotorProtocolManager>
|
||||||
<Ti5Motor id="14" jointName="WAIST_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="14" jointName="WAIST_Y" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
<Ti5Motor id="15" jointName="WAIST_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
<Ti5MotorProtocol id="15" jointName="WAIST_P" limitQLb="3.14" limitQUb="3.14" limitQd="3.0"/>
|
||||||
</MotorManager>
|
</MotorProtocolManager>
|
||||||
</CanGroup>
|
</CanGroup>
|
||||||
</CanManager>
|
</CanManager>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#ifndef CMVR_ES_CAN_GROUP_H
|
#ifndef CMVR_ES_CAN_GROUP_H
|
||||||
#define CMVR_ES_CAN_GROUP_H
|
#define CMVR_ES_CAN_GROUP_H
|
||||||
|
|
||||||
#include "motormanager.h"
|
#include "motor_protocol/motorprotocolmanager.h"
|
||||||
namespace cmvr::device
|
namespace cmvr::device
|
||||||
{
|
{
|
||||||
class CanGroup
|
class CanGroup
|
||||||
@ -15,7 +15,11 @@ namespace cmvr::device
|
|||||||
~CanGroup() = default;
|
~CanGroup() = default;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::shared_ptr<MotorManager> motor_;
|
std::string id_;
|
||||||
|
unsigned int channelId_;
|
||||||
|
bool enable_;
|
||||||
|
std::shared_ptr<MotorProtocolManager> motor_protocol_manager;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,9 @@ namespace cmvr::device
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CanManager(const XmlNode &cfg);
|
explicit CanManager(const XmlNode &cfg);
|
||||||
~CanManager();
|
~CanManager() = default;
|
||||||
|
|
||||||
|
std::shared_ptr<CanGroup> getCanGroup(const std::string &canGroupID);
|
||||||
private:
|
private:
|
||||||
//CanGroup
|
//CanGroup
|
||||||
std::unordered_map<std::string,std::shared_ptr<CanGroup>> canGroups_;
|
std::unordered_map<std::string,std::shared_ptr<CanGroup>> canGroups_;
|
||||||
|
|||||||
@ -2,16 +2,16 @@
|
|||||||
// Created by linbo on 2025/10/22.
|
// Created by linbo on 2025/10/22.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CMVR_ES_ABSTRACTMOTOR_H
|
#ifndef CMVR_ES_ABSTRACTMOTORPROTOCOL_H
|
||||||
#define CMVR_ES_ABSTRACTMOTOR_H
|
#define CMVR_ES_ABSTRACTMOTORPROTOCOL_H
|
||||||
#include "rapidxml/xml_parser.h"
|
#include "rapidxml/xml_parser.h"
|
||||||
|
|
||||||
namespace cmvr::device
|
namespace cmvr::device
|
||||||
{
|
{
|
||||||
class AbstractMotor
|
class AbstractMotorProtocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AbstractMotor(const XmlNode &cfg)
|
explicit AbstractMotorProtocol(const XmlNode &cfg)
|
||||||
{
|
{
|
||||||
cfg_ = cfg;
|
cfg_ = cfg;
|
||||||
id_ = cfg.getAttrString("id");
|
id_ = cfg.getAttrString("id");
|
||||||
@ -20,7 +20,7 @@ namespace cmvr::device
|
|||||||
limitQUb_ = cfg.getAttrDefault("limitQUb_",(float)3.14);
|
limitQUb_ = cfg.getAttrDefault("limitQUb_",(float)3.14);
|
||||||
limitQd = cfg.getAttrDefault("limitQd",(float)3.0);
|
limitQd = cfg.getAttrDefault("limitQd",(float)3.0);
|
||||||
}
|
}
|
||||||
~AbstractMotor() = default;
|
~AbstractMotorProtocol() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XmlNode cfg_;
|
XmlNode cfg_;
|
||||||
@ -32,4 +32,4 @@ namespace cmvr::device
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //CMVR_ES_ABSTRACTMOTOR_H
|
#endif //CMVR_ES_ABSTRACTMOTORPROTOCOL_H
|
||||||
27
include/hardware/can/motor_protocol/motorprotocolmanager.h
Normal file
27
include/hardware/can/motor_protocol/motorprotocolmanager.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
namespace cmvr::device
|
||||||
|
{
|
||||||
|
class MotorProtocolManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit MotorProtocolManager(const XmlNode &cfg);
|
||||||
|
~MotorProtocolManager() = default;
|
||||||
|
|
||||||
|
std::shared_ptr<AbstractMotorProtocol> getMotorProtocol(const std::string &joint_name);
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<AbstractMotorProtocol>> motor_protocols_;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //CMVR_ES_MOTORPROTOCOLMANAGER_H
|
||||||
@ -6,12 +6,11 @@
|
|||||||
#define CMVR_ES_TI5MOTOR_H
|
#define CMVR_ES_TI5MOTOR_H
|
||||||
|
|
||||||
#include "rapidxml/xml_parser.h"
|
#include "rapidxml/xml_parser.h"
|
||||||
|
#include "abstractmotorprotocol.h"
|
||||||
namespace cmvr::device{
|
namespace cmvr::device{
|
||||||
class Ti5Motor
|
class Ti5MotorProtocol final : public AbstractMotorProtocol {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit Ti5Motor(const XmlNode &cfg);
|
explicit Ti5MotorProtocol(const XmlNode &cfg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by linbo on 2025/10/22.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef CMVR_ES_MOTORMANAGER_H
|
|
||||||
#define CMVR_ES_MOTORMANAGER_H
|
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <memory>
|
|
||||||
#include "abstractmotor.h"
|
|
||||||
|
|
||||||
namespace cmvr::device
|
|
||||||
{
|
|
||||||
class MotorManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit MotorManager(const XmlNode &cfg);
|
|
||||||
~MotorManager();
|
|
||||||
private:
|
|
||||||
std::unordered_map<int, std::shared_ptr<AbstractMotor>> m_motors;//以id区分电机?
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif //CMVR_ES_MOTORMANAGER_H
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by xtkuang on 2025/5/6.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef CMVR_ES_CAN_INTERFACE_H
|
|
||||||
#define CMVR_ES_CAN_INTERFACE_H
|
|
||||||
|
|
||||||
namespace cmvr {
|
|
||||||
|
|
||||||
class can_interface {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // cmvr
|
|
||||||
|
|
||||||
#endif //CMVR_ES_CAN_INTERFACE_H
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by linbo on 2025/9/24.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef CMVR_ES_IO_INTERFACE_H
|
|
||||||
#define CMVR_ES_IO_INTERFACE_H
|
|
||||||
|
|
||||||
|
|
||||||
class io_interface
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif //CMVR_ES_IO_INTERFACE_H
|
|
||||||
@ -4,11 +4,17 @@
|
|||||||
|
|
||||||
#ifndef CMVR_ES_SERIAL_MANAGER_H
|
#ifndef CMVR_ES_SERIAL_MANAGER_H
|
||||||
#define CMVR_ES_SERIAL_MANAGER_H
|
#define CMVR_ES_SERIAL_MANAGER_H
|
||||||
|
#include "rapidxml/xml_parser.h"
|
||||||
namespace cmvr::device
|
namespace cmvr::device
|
||||||
{
|
{
|
||||||
class serial_manager
|
class SerialManager
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
explicit SerialManager(const XmlNode &cfg);
|
||||||
|
~SerialManager() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
#include "rapidxml/xml_parser.h"
|
#include "rapidxml/xml_parser.h"
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include "hardware_factory.h"
|
||||||
|
#include "hardware/can/can_manager.h"
|
||||||
namespace cmvr::device
|
namespace cmvr::device
|
||||||
{
|
{
|
||||||
class HardWareManager
|
class HardWareManager
|
||||||
@ -20,14 +21,19 @@ namespace cmvr::device
|
|||||||
static HardWareManager& getInstance();
|
static HardWareManager& getInstance();
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
|
|
||||||
|
void initHardWare();
|
||||||
|
|
||||||
|
std::shared_ptr<CanGroup> getCanGroup(const std::string& canGroupID);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit HardWareManager(const XmlNode &cfg);
|
||||||
private:
|
private:
|
||||||
XmlNode cfg_;
|
XmlNode cfg_;
|
||||||
static std::once_flag init_flag_;
|
static std::once_flag init_flag_;
|
||||||
static std::shared_ptr<HardWareManager> instance_;
|
static std::shared_ptr<HardWareManager> instance_;
|
||||||
explicit HardWareManager(const XmlNode &cfg);
|
std::shared_ptr<HardwareFactory> hardware_factory_;
|
||||||
|
std::shared_ptr<CanManager> can_manager_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,4 +5,4 @@ add_subdirectory(devices)
|
|||||||
add_subdirectory(monitor)
|
add_subdirectory(monitor)
|
||||||
add_subdirectory(device_manager)
|
add_subdirectory(device_manager)
|
||||||
add_subdirectory(service)
|
add_subdirectory(service)
|
||||||
add_subdirectory(controller)
|
#add_subdirectory(controller)
|
||||||
@ -1,3 +1,4 @@
|
|||||||
#add_subdirectory(ti5_robot)
|
#add_subdirectory(ti5_robot)
|
||||||
add_subdirectory(humanoid_robot)
|
add_subdirectory(humanoid_robot)
|
||||||
#add_subdirectory(c701)
|
#add_subdirectory(c701)
|
||||||
|
add_subdirectory(controller)
|
||||||
6
src/devices/robot/controller/CMakeLists.txt
Normal file
6
src/devices/robot/controller/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
add_library(controller SHARED controller_manager.cpp)
|
||||||
|
|
||||||
|
target_include_directories(controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
add_library(cmvr_es::device::controller ALIAS controller)
|
||||||
21
src/devices/robot/controller/abstractcontroller.h
Normal file
21
src/devices/robot/controller/abstractcontroller.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by linbo on 2025/10/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef CMVR_ES_ABSTRACTCONTROLLER_H
|
||||||
|
#define CMVR_ES_ABSTRACTCONTROLLER_H
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include "rapidxml/xml_parser.h"
|
||||||
|
|
||||||
|
namespace cmvr::device
|
||||||
|
{
|
||||||
|
class AbstractController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit AbstractController();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //CMVR_ES_ABSTRACTCONTROLLER_H
|
||||||
8
src/devices/robot/controller/controller_manager.cpp
Normal file
8
src/devices/robot/controller/controller_manager.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// Created by linbo on 2025/10/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "controller_manager.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cmvr::device;
|
||||||
25
src/devices/robot/controller/controller_manager.h
Normal file
25
src/devices/robot/controller/controller_manager.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by linbo on 2025/10/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef CMVR_ES_CONTROLLER_MANAGER_H
|
||||||
|
#define CMVR_ES_CONTROLLER_MANAGER_H
|
||||||
|
|
||||||
|
#include "abstractcontroller.h"
|
||||||
|
|
||||||
|
namespace cmvr::device
|
||||||
|
{
|
||||||
|
class ControllerManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ControllerManager();
|
||||||
|
~ControllerManager() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //CMVR_ES_CONTROLLER_MANAGER_H
|
||||||
@ -1,15 +1,18 @@
|
|||||||
|
add_subdirectory(can)
|
||||||
|
add_subdirectory(serial)
|
||||||
|
|
||||||
add_library(hardware SHARED
|
add_library(hardware SHARED
|
||||||
can_interface.cpp
|
|
||||||
serial_interface.cpp
|
|
||||||
esp32_serial_port.cpp
|
esp32_serial_port.cpp
|
||||||
io_interface.cpp
|
serial_interface.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(hardware PUBLIC
|
target_include_directories(hardware PUBLIC
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(hardware PRIVATE
|
||||||
|
cmvr_es::can
|
||||||
|
cmvr_es::serial
|
||||||
|
)
|
||||||
add_library(cmvr_es::hardware ALIAS hardware)
|
add_library(cmvr_es::hardware ALIAS hardware)
|
||||||
|
|
||||||
add_subdirectory(can)
|
|
||||||
add_subdirectory(serial)
|
|
||||||
@ -1,14 +1,14 @@
|
|||||||
add_library(can
|
add_library(can
|
||||||
motormanager.cpp
|
|
||||||
can_group.cpp
|
can_group.cpp
|
||||||
can_manager.cpp
|
can_manager.cpp
|
||||||
ti5motor.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(can PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(can PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||||
|
add_subdirectory(motor_protocol)
|
||||||
|
|
||||||
target_link_libraries(can PRIVATE
|
target_link_libraries(can PRIVATE
|
||||||
protobuf::libprotobuf
|
protobuf::libprotobuf
|
||||||
|
cmvr_es::motor_protocol
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(cmvr_es::can ALIAS can)
|
add_library(cmvr_es::can ALIAS can)
|
||||||
@ -3,11 +3,23 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "hardware/can/can_group.h"
|
#include "hardware/can/can_group.h"
|
||||||
|
#include <glog/logging.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cmvr::device;
|
using namespace cmvr::device;
|
||||||
|
|
||||||
CanGroup::CanGroup(const XmlNode &cfg)
|
CanGroup::CanGroup(const XmlNode &cfg)
|
||||||
{
|
{
|
||||||
motor_ = std::make_shared<MotorManager>(cfg);
|
try {
|
||||||
|
id_ = cfg.getAttrString("id");
|
||||||
|
channelId_ = cfg.getAttrDefault("channelId",0);
|
||||||
|
enable_ = cfg.getAttrDefault("enable", false);
|
||||||
|
motor_protocol_manager = std::make_shared<MotorProtocolManager>(cfg);
|
||||||
}
|
}
|
||||||
|
catch (const exception &e) {
|
||||||
|
LOG(FATAL) << "[CanGroup] (CanGroup): CanGroup initialization failed: " << e.what();
|
||||||
|
throw std::runtime_error("[CanGroup] (CanGroup): CanGroup create failed" + string(e.what()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,19 +3,34 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "hardware/can/can_manager.h"
|
#include "hardware/can/can_manager.h"
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cmvr::device;
|
using namespace cmvr::device;
|
||||||
|
|
||||||
CanManager::CanManager(const XmlNode& cfg)
|
CanManager::CanManager(const XmlNode& cfg)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
for (auto &node: cfg.getChildren()){
|
for (auto &node: cfg.getChildren()){
|
||||||
if (node.getNodeName() == "CanGroup")
|
if (node.getNodeName() == "CanGroup")
|
||||||
{
|
{
|
||||||
string id = node.getAttrString("id");
|
string id = node.getAttrString("id");
|
||||||
|
if (canGroups_.count(id))
|
||||||
|
throw runtime_error("[CanManager](CanManager): duplicate CanGroup id:" + id);
|
||||||
canGroups_[id] = std::make_shared<CanGroup>(cfg);
|
canGroups_[id] = std::make_shared<CanGroup>(cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (const exception &e) {
|
||||||
|
LOG(FATAL) << "[CanManager] (CanManager): CanManager initialization failed: " << e.what();
|
||||||
|
throw std::runtime_error("[CanManager] (DeviceManager): CanManager create failed" + string(e.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<CanGroup> CanManager::getCanGroup(const std::string &canGroupID)
|
||||||
|
{
|
||||||
|
if (canGroups_.count(canGroupID))
|
||||||
|
return canGroups_[canGroupID];
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
12
src/hardware/can/motor_protocol/CMakeLists.txt
Normal file
12
src/hardware/can/motor_protocol/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
add_library(motor_protocol
|
||||||
|
motorprotocolmanager.cpp
|
||||||
|
ti5motorprotocol.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(motor_protocol PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
|
target_link_libraries(motor_protocol PRIVATE
|
||||||
|
protobuf::libprotobuf
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(cmvr_es::motor_protocol ALIAS motor_protocol)
|
||||||
41
src/hardware/can/motor_protocol/motorprotocolmanager.cpp
Normal file
41
src/hardware/can/motor_protocol/motorprotocolmanager.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// Created by linbo on 2025/10/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "hardware/can/motor_protocol/motorprotocolmanager.h"
|
||||||
|
#include "hardware/can/motor_protocol/ti5motorprotocol.h"
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cmvr::device;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MotorProtocolManager::MotorProtocolManager(const XmlNode &cfg)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
for (auto &node: cfg.getChildren()){
|
||||||
|
if (node.getNodeName() == "Ti5MotorProtocol")
|
||||||
|
{
|
||||||
|
std::string id = node.getAttrString("id");
|
||||||
|
std::string joint_name = node.getAttrString("joint_name");
|
||||||
|
if (motor_protocols_.count(joint_name))
|
||||||
|
throw runtime_error("[MotorProtocolManager] (MotorProtocolManager): duplicate motorProtocol joint name:" + joint_name);
|
||||||
|
|
||||||
|
motor_protocols_[joint_name] = std::make_shared<Ti5MotorProtocol>(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const exception &e) {
|
||||||
|
LOG(FATAL) << "[MotorProtocolManager] (MotorProtocolManager): MotorProtocolManager initialization failed: " << e.what();
|
||||||
|
throw std::runtime_error("[MotorProtocolManager] (MotorProtocolManager): MotorProtocolManager create failed" + string(e.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<AbstractMotorProtocol> MotorProtocolManager::getMotorProtocol(const std::string &joint_name)
|
||||||
|
{
|
||||||
|
if (motor_protocols_.count(joint_name))
|
||||||
|
return motor_protocols_[joint_name];
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
11
src/hardware/can/motor_protocol/ti5motorprotocol.cpp
Normal file
11
src/hardware/can/motor_protocol/ti5motorprotocol.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by linbo on 2025/10/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "hardware/can/motor_protocol/ti5motorprotocol.h"
|
||||||
|
using namespace cmvr::device;
|
||||||
|
|
||||||
|
Ti5MotorProtocol::Ti5MotorProtocol(const XmlNode &cfg):AbstractMotorProtocol(cfg)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,23 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by linbo on 2025/10/22.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "hardware/can/motormanager.h"
|
|
||||||
#include "hardware/can/ti5motor.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace cmvr::device;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MotorManager::MotorManager(const XmlNode &cfg)
|
|
||||||
{
|
|
||||||
for (auto &node: cfg.getChildren()){
|
|
||||||
if (node.getNodeName() == "Ti5Motor")
|
|
||||||
{
|
|
||||||
string id = node.getAttrString("id");
|
|
||||||
|
|
||||||
std::make_shared<Ti5Motor>(cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by linbo on 2025/10/22.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "hardware/can/ti5motor.h"
|
|
||||||
using namespace cmvr::device;
|
|
||||||
|
|
||||||
Ti5Motor::Ti5Motor(const XmlNode &cfg)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by xtkuang on 2025/5/6.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "../../include/hardware/can_interface.h"
|
|
||||||
|
|
||||||
namespace cmvr {
|
|
||||||
} // cmvr
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by linbo on 2025/9/24.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "../../include/hardware/io_interface.h"
|
|
||||||
@ -3,3 +3,11 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "hardware/serial/serial_manager.h"
|
#include "hardware/serial/serial_manager.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cmvr::device;
|
||||||
|
|
||||||
|
SerialManager::SerialManager(const XmlNode &cfg)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,5 +23,5 @@ std::shared_ptr<HardwareType> HardwareFactory::create(const XmlNode& cfg) {
|
|||||||
|
|
||||||
|
|
||||||
std::shared_ptr<CanManager> HardwareFactory::create_can_(const XmlNode& cfg) {
|
std::shared_ptr<CanManager> HardwareFactory::create_can_(const XmlNode& cfg) {
|
||||||
return nullptr;
|
return std::make_shared<CanManager>(cfg);
|
||||||
}
|
}
|
||||||
@ -10,6 +10,12 @@ std::shared_ptr<HardWareManager> HardWareManager::instance_ = nullptr;
|
|||||||
HardWareManager::HardWareManager(const XmlNode& cfg) {
|
HardWareManager::HardWareManager(const XmlNode& cfg) {
|
||||||
try {
|
try {
|
||||||
cfg_ = cfg;
|
cfg_ = cfg;
|
||||||
|
|
||||||
|
hardware_factory_ = std::make_shared<HardwareFactory>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
initHardWare();
|
||||||
}
|
}
|
||||||
catch (const exception &e) {
|
catch (const exception &e) {
|
||||||
LOG(FATAL) << "[HardWareManager] (HardWareManager): Device manager initialization failed: " << e.what();
|
LOG(FATAL) << "[HardWareManager] (HardWareManager): Device manager initialization failed: " << e.what();
|
||||||
@ -34,3 +40,25 @@ HardWareManager& HardWareManager::getInstance() {
|
|||||||
void HardWareManager::destroyInstance() {
|
void HardWareManager::destroyInstance() {
|
||||||
instance_.reset();
|
instance_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HardWareManager::initHardWare()
|
||||||
|
{
|
||||||
|
//解析xml节点
|
||||||
|
try{
|
||||||
|
auto can_node = cfg_.getChild("CanManager");
|
||||||
|
can_manager_ = hardware_factory_->create<CanManager>(can_node);
|
||||||
|
}
|
||||||
|
catch (const exception& e) {
|
||||||
|
LOG(ERROR) << e.what();
|
||||||
|
throw runtime_error(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查can和串口的可用性
|
||||||
|
}
|
||||||
|
std::shared_ptr<CanGroup> HardWareManager::getCanGroup(const std::string& canGroupID)
|
||||||
|
{
|
||||||
|
auto canGroup = can_manager_->getCanGroup(canGroupID);
|
||||||
|
if (canGroup == nullptr)
|
||||||
|
throw runtime_error("can't find canGroup, canGroupID:" + canGroupID);
|
||||||
|
return canGroup;
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ target_link_libraries(service PRIVATE
|
|||||||
gRPC::grpc++
|
gRPC::grpc++
|
||||||
protobuf::libprotobuf
|
protobuf::libprotobuf
|
||||||
cmvr_es::device_manager
|
cmvr_es::device_manager
|
||||||
cmvr_es::ctrl::controller
|
#cmvr_es::ctrl::controller
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(cmvr_es::service ALIAS service)
|
add_library(cmvr_es::service ALIAS service)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "../../../include/service/grpc_service/grpc_hlc_service.h"
|
#include "service/grpc_service/grpc_hlc_service.h"
|
||||||
#include <google/protobuf/util/time_util.h>
|
#include <google/protobuf/util/time_util.h>
|
||||||
#include "robot/humanoid_robot/humanoid_robot.h"
|
#include "robot/humanoid_robot/humanoid_robot.h"
|
||||||
#include "controller/touch_controller.h"
|
#include "controller/touch_controller.h"
|
||||||
@ -25,7 +25,7 @@ grpc::Status gRPCHlcServiceImpl::touch(grpc::ServerContext *context, const cmvr:
|
|||||||
auto cam = dmgr_.getDevice<AbstractCamera>("cam4");
|
auto cam = dmgr_.getDevice<AbstractCamera>("cam4");
|
||||||
auto hand = dmgr_.getDevice<AbstractDexHand>("hand1");
|
auto hand = dmgr_.getDevice<AbstractDexHand>("hand1");
|
||||||
ctrl::TouchController touch_controller(robot,hand,cam);;
|
ctrl::TouchController touch_controller(robot,hand,cam);;
|
||||||
touch_controller.touch(request->u(),request->v(),request->max_force());
|
// touch_controller.touch(request->u(),request->v(),request->max_force());
|
||||||
response->mutable_header()->set_success(true);
|
response->mutable_header()->set_success(true);
|
||||||
response->mutable_header()->set_error_message("");
|
response->mutable_header()->set_error_message("");
|
||||||
}catch (const std::exception& e) {
|
}catch (const std::exception& e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user