From f9521a72e75d62f9d1b9122087a018f885138215 Mon Sep 17 00:00:00 2001 From: linbo <1034003879@qq.com> Date: Fri, 24 Oct 2025 09:51:14 +0800 Subject: [PATCH] update HardWareManager --- CMakeLists.txt | 2 +- config/dev_config.xml | 54 +++++++++---------- include/hardware/can/can_group.h | 8 ++- include/hardware/can/can_manager.h | 4 +- .../abstractmotorprotocol.h} | 12 ++--- .../can/motor_protocol/motorprotocolmanager.h | 27 ++++++++++ .../ti5motorprotocol.h} | 7 ++- include/hardware/can/motormanager.h | 25 --------- include/hardware/can_interface.h | 16 ------ include/hardware/io_interface.h | 14 ----- include/hardware/serial/serial_manager.h | 10 +++- include/hardware_manager/hardware_manager.h | 12 +++-- src/CMakeLists.txt | 2 +- src/devices/robot/CMakeLists.txt | 3 +- src/devices/robot/controller/CMakeLists.txt | 6 +++ .../robot/controller/abstractcontroller.h | 21 ++++++++ .../robot/controller/controller_manager.cpp | 8 +++ .../robot/controller/controller_manager.h | 25 +++++++++ src/hardware/CMakeLists.txt | 13 +++-- src/hardware/can/CMakeLists.txt | 4 +- src/hardware/can/can_group.cpp | 18 +++++-- src/hardware/can/can_manager.cpp | 29 +++++++--- .../can/motor_protocol/CMakeLists.txt | 12 +++++ .../motor_protocol/motorprotocolmanager.cpp | 41 ++++++++++++++ .../can/motor_protocol/ti5motorprotocol.cpp | 11 ++++ src/hardware/can/motormanager.cpp | 23 -------- src/hardware/can/ti5motor.cpp | 11 ---- src/hardware/can_interface.cpp | 8 --- src/hardware/io_interface.cpp | 5 -- src/hardware/serial/serial_manager.cpp | 8 +++ src/hardware_manager/hardware_factory.cpp | 2 +- src/hardware_manager/hardware_manager.cpp | 28 ++++++++++ src/service/grpc_service/CMakeLists.txt | 2 +- src/service/grpc_service/grpc_hlc_service.cpp | 4 +- 34 files changed, 304 insertions(+), 171 deletions(-) rename include/hardware/can/{abstractmotor.h => motor_protocol/abstractmotorprotocol.h} (71%) create mode 100644 include/hardware/can/motor_protocol/motorprotocolmanager.h rename include/hardware/can/{ti5motor.h => motor_protocol/ti5motorprotocol.h} (58%) delete mode 100644 include/hardware/can/motormanager.h delete mode 100644 include/hardware/can_interface.h delete mode 100644 include/hardware/io_interface.h create mode 100644 src/devices/robot/controller/CMakeLists.txt create mode 100644 src/devices/robot/controller/abstractcontroller.h create mode 100644 src/devices/robot/controller/controller_manager.cpp create mode 100644 src/devices/robot/controller/controller_manager.h create mode 100644 src/hardware/can/motor_protocol/CMakeLists.txt create mode 100644 src/hardware/can/motor_protocol/motorprotocolmanager.cpp create mode 100644 src/hardware/can/motor_protocol/ti5motorprotocol.cpp delete mode 100644 src/hardware/can/motormanager.cpp delete mode 100644 src/hardware/can/ti5motor.cpp delete mode 100644 src/hardware/can_interface.cpp delete mode 100644 src/hardware/io_interface.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 01021bbf..aa276be7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,5 +94,5 @@ target_link_libraries(cmvr_es PRIVATE cmvr_es::httpclient cmvr_es::device::canbus cmvr_es::device::ti5motor - cmvr_es::ctrl::controller + #cmvr_es::ctrl::controller ) \ No newline at end of file diff --git a/config/dev_config.xml b/config/dev_config.xml index 857fc924..ef6d3d81 100644 --- a/config/dev_config.xml +++ b/config/dev_config.xml @@ -5,39 +5,39 @@ - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - + + + + + - - - - + + + + diff --git a/include/hardware/can/can_group.h b/include/hardware/can/can_group.h index 9ade42ba..9afef933 100644 --- a/include/hardware/can/can_group.h +++ b/include/hardware/can/can_group.h @@ -5,7 +5,7 @@ #ifndef CMVR_ES_CAN_GROUP_H #define CMVR_ES_CAN_GROUP_H -#include "motormanager.h" +#include "motor_protocol/motorprotocolmanager.h" namespace cmvr::device { class CanGroup @@ -15,7 +15,11 @@ namespace cmvr::device ~CanGroup() = default; private: - std::shared_ptr motor_; + std::string id_; + unsigned int channelId_; + bool enable_; + std::shared_ptr motor_protocol_manager; + }; } diff --git a/include/hardware/can/can_manager.h b/include/hardware/can/can_manager.h index dbe07005..424fdf8e 100644 --- a/include/hardware/can/can_manager.h +++ b/include/hardware/can/can_manager.h @@ -16,7 +16,9 @@ namespace cmvr::device public: explicit CanManager(const XmlNode &cfg); - ~CanManager(); + ~CanManager() = default; + + std::shared_ptr getCanGroup(const std::string &canGroupID); private: //CanGroup std::unordered_map> canGroups_; diff --git a/include/hardware/can/abstractmotor.h b/include/hardware/can/motor_protocol/abstractmotorprotocol.h similarity index 71% rename from include/hardware/can/abstractmotor.h rename to include/hardware/can/motor_protocol/abstractmotorprotocol.h index a7ccd875..0c4c19a0 100644 --- a/include/hardware/can/abstractmotor.h +++ b/include/hardware/can/motor_protocol/abstractmotorprotocol.h @@ -2,16 +2,16 @@ // Created by linbo on 2025/10/22. // -#ifndef CMVR_ES_ABSTRACTMOTOR_H -#define CMVR_ES_ABSTRACTMOTOR_H +#ifndef CMVR_ES_ABSTRACTMOTORPROTOCOL_H +#define CMVR_ES_ABSTRACTMOTORPROTOCOL_H #include "rapidxml/xml_parser.h" namespace cmvr::device { - class AbstractMotor + class AbstractMotorProtocol { public: - explicit AbstractMotor(const XmlNode &cfg) + explicit AbstractMotorProtocol(const XmlNode &cfg) { cfg_ = cfg; id_ = cfg.getAttrString("id"); @@ -20,7 +20,7 @@ namespace cmvr::device limitQUb_ = cfg.getAttrDefault("limitQUb_",(float)3.14); limitQd = cfg.getAttrDefault("limitQd",(float)3.0); } - ~AbstractMotor() = default; + ~AbstractMotorProtocol() = default; private: XmlNode cfg_; @@ -32,4 +32,4 @@ namespace cmvr::device }; } -#endif //CMVR_ES_ABSTRACTMOTOR_H \ No newline at end of file +#endif //CMVR_ES_ABSTRACTMOTORPROTOCOL_H \ No newline at end of file diff --git a/include/hardware/can/motor_protocol/motorprotocolmanager.h b/include/hardware/can/motor_protocol/motorprotocolmanager.h new file mode 100644 index 00000000..c5de6437 --- /dev/null +++ b/include/hardware/can/motor_protocol/motorprotocolmanager.h @@ -0,0 +1,27 @@ +// +// Created by linbo on 2025/10/22. +// + +#ifndef CMVR_ES_MOTORPROTOCOLMANAGER_H +#define CMVR_ES_MOTORPROTOCOLMANAGER_H + +#include +#include +#include "abstractmotorprotocol.h" + +namespace cmvr::device +{ + class MotorProtocolManager + { + public: + explicit MotorProtocolManager(const XmlNode &cfg); + ~MotorProtocolManager() = default; + + std::shared_ptr getMotorProtocol(const std::string &joint_name); + private: + std::unordered_map> motor_protocols_; + }; +} + + +#endif //CMVR_ES_MOTORPROTOCOLMANAGER_H \ No newline at end of file diff --git a/include/hardware/can/ti5motor.h b/include/hardware/can/motor_protocol/ti5motorprotocol.h similarity index 58% rename from include/hardware/can/ti5motor.h rename to include/hardware/can/motor_protocol/ti5motorprotocol.h index 758f34a0..19bc164b 100644 --- a/include/hardware/can/ti5motor.h +++ b/include/hardware/can/motor_protocol/ti5motorprotocol.h @@ -6,12 +6,11 @@ #define CMVR_ES_TI5MOTOR_H #include "rapidxml/xml_parser.h" - +#include "abstractmotorprotocol.h" namespace cmvr::device{ - class Ti5Motor - { + class Ti5MotorProtocol final : public AbstractMotorProtocol { public: - explicit Ti5Motor(const XmlNode &cfg); + explicit Ti5MotorProtocol(const XmlNode &cfg); private: diff --git a/include/hardware/can/motormanager.h b/include/hardware/can/motormanager.h deleted file mode 100644 index 9387e249..00000000 --- a/include/hardware/can/motormanager.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// Created by linbo on 2025/10/22. -// - -#ifndef CMVR_ES_MOTORMANAGER_H -#define CMVR_ES_MOTORMANAGER_H - -#include -#include -#include "abstractmotor.h" - -namespace cmvr::device -{ - class MotorManager - { - public: - explicit MotorManager(const XmlNode &cfg); - ~MotorManager(); - private: - std::unordered_map> m_motors;//以id区分电机? - }; -} - - -#endif //CMVR_ES_MOTORMANAGER_H \ No newline at end of file diff --git a/include/hardware/can_interface.h b/include/hardware/can_interface.h deleted file mode 100644 index 4cc13e1b..00000000 --- a/include/hardware/can_interface.h +++ /dev/null @@ -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 diff --git a/include/hardware/io_interface.h b/include/hardware/io_interface.h deleted file mode 100644 index 4f04daf5..00000000 --- a/include/hardware/io_interface.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/include/hardware/serial/serial_manager.h b/include/hardware/serial/serial_manager.h index 350fdeaa..08fea033 100644 --- a/include/hardware/serial/serial_manager.h +++ b/include/hardware/serial/serial_manager.h @@ -4,11 +4,17 @@ #ifndef CMVR_ES_SERIAL_MANAGER_H #define CMVR_ES_SERIAL_MANAGER_H - +#include "rapidxml/xml_parser.h" namespace cmvr::device { - class serial_manager + class SerialManager { + public: + explicit SerialManager(const XmlNode &cfg); + ~SerialManager() = default; + + private: + }; } diff --git a/include/hardware_manager/hardware_manager.h b/include/hardware_manager/hardware_manager.h index cd0dd35a..be5d159e 100644 --- a/include/hardware_manager/hardware_manager.h +++ b/include/hardware_manager/hardware_manager.h @@ -7,7 +7,8 @@ #include "rapidxml/xml_parser.h" #include #include - +#include "hardware_factory.h" +#include "hardware/can/can_manager.h" namespace cmvr::device { class HardWareManager @@ -20,14 +21,19 @@ namespace cmvr::device static HardWareManager& getInstance(); static void destroyInstance(); + void initHardWare(); + + std::shared_ptr getCanGroup(const std::string& canGroupID); - + private: + explicit HardWareManager(const XmlNode &cfg); private: XmlNode cfg_; static std::once_flag init_flag_; static std::shared_ptr instance_; - explicit HardWareManager(const XmlNode &cfg); + std::shared_ptr hardware_factory_; + std::shared_ptr can_manager_; }; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02c783a9..350e8269 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,4 +5,4 @@ add_subdirectory(devices) add_subdirectory(monitor) add_subdirectory(device_manager) add_subdirectory(service) -add_subdirectory(controller) \ No newline at end of file +#add_subdirectory(controller) \ No newline at end of file diff --git a/src/devices/robot/CMakeLists.txt b/src/devices/robot/CMakeLists.txt index 599ad24f..3280264f 100644 --- a/src/devices/robot/CMakeLists.txt +++ b/src/devices/robot/CMakeLists.txt @@ -1,3 +1,4 @@ #add_subdirectory(ti5_robot) add_subdirectory(humanoid_robot) -#add_subdirectory(c701) \ No newline at end of file +#add_subdirectory(c701) +add_subdirectory(controller) \ No newline at end of file diff --git a/src/devices/robot/controller/CMakeLists.txt b/src/devices/robot/controller/CMakeLists.txt new file mode 100644 index 00000000..e084d2d0 --- /dev/null +++ b/src/devices/robot/controller/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/src/devices/robot/controller/abstractcontroller.h b/src/devices/robot/controller/abstractcontroller.h new file mode 100644 index 00000000..d22f69dd --- /dev/null +++ b/src/devices/robot/controller/abstractcontroller.h @@ -0,0 +1,21 @@ +// +// Created by linbo on 2025/10/23. +// + +#ifndef CMVR_ES_ABSTRACTCONTROLLER_H +#define CMVR_ES_ABSTRACTCONTROLLER_H + +#include + +#include "rapidxml/xml_parser.h" + +namespace cmvr::device +{ + class AbstractController + { + public: + explicit AbstractController(); + }; +} + +#endif //CMVR_ES_ABSTRACTCONTROLLER_H \ No newline at end of file diff --git a/src/devices/robot/controller/controller_manager.cpp b/src/devices/robot/controller/controller_manager.cpp new file mode 100644 index 00000000..98846855 --- /dev/null +++ b/src/devices/robot/controller/controller_manager.cpp @@ -0,0 +1,8 @@ +// +// Created by linbo on 2025/10/23. +// + +#include "controller_manager.h" + +using namespace std; +using namespace cmvr::device; \ No newline at end of file diff --git a/src/devices/robot/controller/controller_manager.h b/src/devices/robot/controller/controller_manager.h new file mode 100644 index 00000000..eae4319c --- /dev/null +++ b/src/devices/robot/controller/controller_manager.h @@ -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 \ No newline at end of file diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt index 3bf1e5e2..1a5cde23 100644 --- a/src/hardware/CMakeLists.txt +++ b/src/hardware/CMakeLists.txt @@ -1,15 +1,18 @@ +add_subdirectory(can) +add_subdirectory(serial) + add_library(hardware SHARED - can_interface.cpp - serial_interface.cpp esp32_serial_port.cpp - io_interface.cpp + serial_interface.cpp ) target_include_directories(hardware PUBLIC ${PROJECT_SOURCE_DIR}/include ) +target_link_libraries(hardware PRIVATE + cmvr_es::can + cmvr_es::serial +) add_library(cmvr_es::hardware ALIAS hardware) -add_subdirectory(can) -add_subdirectory(serial) \ No newline at end of file diff --git a/src/hardware/can/CMakeLists.txt b/src/hardware/can/CMakeLists.txt index 85ecc50d..73132d56 100644 --- a/src/hardware/can/CMakeLists.txt +++ b/src/hardware/can/CMakeLists.txt @@ -1,14 +1,14 @@ add_library(can - motormanager.cpp can_group.cpp can_manager.cpp - ti5motor.cpp ) target_include_directories(can PUBLIC ${PROJECT_SOURCE_DIR}/include) +add_subdirectory(motor_protocol) target_link_libraries(can PRIVATE protobuf::libprotobuf + cmvr_es::motor_protocol ) add_library(cmvr_es::can ALIAS can) \ No newline at end of file diff --git a/src/hardware/can/can_group.cpp b/src/hardware/can/can_group.cpp index 9c6793af..b80c48a4 100644 --- a/src/hardware/can/can_group.cpp +++ b/src/hardware/can/can_group.cpp @@ -3,11 +3,23 @@ // #include "hardware/can/can_group.h" - +#include using namespace std; using namespace cmvr::device; CanGroup::CanGroup(const XmlNode &cfg) { - motor_ = std::make_shared(cfg); -} \ No newline at end of file + try { + id_ = cfg.getAttrString("id"); + channelId_ = cfg.getAttrDefault("channelId",0); + enable_ = cfg.getAttrDefault("enable", false); + motor_protocol_manager = std::make_shared(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())); + } + +} + + diff --git a/src/hardware/can/can_manager.cpp b/src/hardware/can/can_manager.cpp index 2a0cef6e..8a22318e 100644 --- a/src/hardware/can/can_manager.cpp +++ b/src/hardware/can/can_manager.cpp @@ -3,19 +3,34 @@ // #include "hardware/can/can_manager.h" +#include using namespace std; using namespace cmvr::device; CanManager::CanManager(const XmlNode& cfg) { - for (auto &node: cfg.getChildren()){ - if (node.getNodeName() == "CanGroup") - { - string id = node.getAttrString("id"); - - - canGroups_[id] = std::make_shared(cfg); + try + { + for (auto &node: cfg.getChildren()){ + if (node.getNodeName() == "CanGroup") + { + string id = node.getAttrString("id"); + if (canGroups_.count(id)) + throw runtime_error("[CanManager](CanManager): duplicate CanGroup id:" + id); + canGroups_[id] = std::make_shared(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 CanManager::getCanGroup(const std::string &canGroupID) +{ + if (canGroups_.count(canGroupID)) + return canGroups_[canGroupID]; + return nullptr; +} \ No newline at end of file diff --git a/src/hardware/can/motor_protocol/CMakeLists.txt b/src/hardware/can/motor_protocol/CMakeLists.txt new file mode 100644 index 00000000..c0ba3efe --- /dev/null +++ b/src/hardware/can/motor_protocol/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/src/hardware/can/motor_protocol/motorprotocolmanager.cpp b/src/hardware/can/motor_protocol/motorprotocolmanager.cpp new file mode 100644 index 00000000..6bc306e5 --- /dev/null +++ b/src/hardware/can/motor_protocol/motorprotocolmanager.cpp @@ -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 + +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(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 MotorProtocolManager::getMotorProtocol(const std::string &joint_name) +{ + if (motor_protocols_.count(joint_name)) + return motor_protocols_[joint_name]; + return nullptr; +} diff --git a/src/hardware/can/motor_protocol/ti5motorprotocol.cpp b/src/hardware/can/motor_protocol/ti5motorprotocol.cpp new file mode 100644 index 00000000..e2d78849 --- /dev/null +++ b/src/hardware/can/motor_protocol/ti5motorprotocol.cpp @@ -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) +{ + +} \ No newline at end of file diff --git a/src/hardware/can/motormanager.cpp b/src/hardware/can/motormanager.cpp deleted file mode 100644 index d678155f..00000000 --- a/src/hardware/can/motormanager.cpp +++ /dev/null @@ -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(cfg); - } - } -} diff --git a/src/hardware/can/ti5motor.cpp b/src/hardware/can/ti5motor.cpp deleted file mode 100644 index 1789796d..00000000 --- a/src/hardware/can/ti5motor.cpp +++ /dev/null @@ -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) -{ - -} \ No newline at end of file diff --git a/src/hardware/can_interface.cpp b/src/hardware/can_interface.cpp deleted file mode 100644 index 846228e8..00000000 --- a/src/hardware/can_interface.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// -// Created by xtkuang on 2025/5/6. -// - -#include "../../include/hardware/can_interface.h" - -namespace cmvr { -} // cmvr \ No newline at end of file diff --git a/src/hardware/io_interface.cpp b/src/hardware/io_interface.cpp deleted file mode 100644 index 3360857b..00000000 --- a/src/hardware/io_interface.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by linbo on 2025/9/24. -// - -#include "../../include/hardware/io_interface.h" diff --git a/src/hardware/serial/serial_manager.cpp b/src/hardware/serial/serial_manager.cpp index 81d19e6a..0cd140de 100644 --- a/src/hardware/serial/serial_manager.cpp +++ b/src/hardware/serial/serial_manager.cpp @@ -3,3 +3,11 @@ // #include "hardware/serial/serial_manager.h" + +using namespace std; +using namespace cmvr::device; + +SerialManager::SerialManager(const XmlNode &cfg) +{ + +} \ No newline at end of file diff --git a/src/hardware_manager/hardware_factory.cpp b/src/hardware_manager/hardware_factory.cpp index b3f3d7cb..8de2ce16 100644 --- a/src/hardware_manager/hardware_factory.cpp +++ b/src/hardware_manager/hardware_factory.cpp @@ -23,5 +23,5 @@ std::shared_ptr HardwareFactory::create(const XmlNode& cfg) { std::shared_ptr HardwareFactory::create_can_(const XmlNode& cfg) { - return nullptr; + return std::make_shared(cfg); } \ No newline at end of file diff --git a/src/hardware_manager/hardware_manager.cpp b/src/hardware_manager/hardware_manager.cpp index b83a6eb8..4ae47dbd 100644 --- a/src/hardware_manager/hardware_manager.cpp +++ b/src/hardware_manager/hardware_manager.cpp @@ -10,6 +10,12 @@ std::shared_ptr HardWareManager::instance_ = nullptr; HardWareManager::HardWareManager(const XmlNode& cfg) { try { cfg_ = cfg; + + hardware_factory_ = std::make_shared(); + + + + initHardWare(); } catch (const exception &e) { LOG(FATAL) << "[HardWareManager] (HardWareManager): Device manager initialization failed: " << e.what(); @@ -33,4 +39,26 @@ HardWareManager& HardWareManager::getInstance() { void HardWareManager::destroyInstance() { instance_.reset(); +} + +void HardWareManager::initHardWare() +{ + //解析xml节点 + try{ + auto can_node = cfg_.getChild("CanManager"); + can_manager_ = hardware_factory_->create(can_node); + } + catch (const exception& e) { + LOG(ERROR) << e.what(); + throw runtime_error(e.what()); + } + + //检查can和串口的可用性 +} +std::shared_ptr 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; } \ No newline at end of file diff --git a/src/service/grpc_service/CMakeLists.txt b/src/service/grpc_service/CMakeLists.txt index 88edc48d..c0449d14 100644 --- a/src/service/grpc_service/CMakeLists.txt +++ b/src/service/grpc_service/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(service PRIVATE gRPC::grpc++ protobuf::libprotobuf cmvr_es::device_manager - cmvr_es::ctrl::controller + #cmvr_es::ctrl::controller ) add_library(cmvr_es::service ALIAS service) diff --git a/src/service/grpc_service/grpc_hlc_service.cpp b/src/service/grpc_service/grpc_hlc_service.cpp index 10c83b38..cc8dd780 100644 --- a/src/service/grpc_service/grpc_hlc_service.cpp +++ b/src/service/grpc_service/grpc_hlc_service.cpp @@ -3,7 +3,7 @@ // -#include "../../../include/service/grpc_service/grpc_hlc_service.h" +#include "service/grpc_service/grpc_hlc_service.h" #include #include "robot/humanoid_robot/humanoid_robot.h" #include "controller/touch_controller.h" @@ -25,7 +25,7 @@ grpc::Status gRPCHlcServiceImpl::touch(grpc::ServerContext *context, const cmvr: auto cam = dmgr_.getDevice("cam4"); auto hand = dmgr_.getDevice("hand1"); 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_error_message(""); }catch (const std::exception& e) {