2025-08-22 16:57:29 +08:00
|
|
|
//
|
|
|
|
|
// Created by xtkuang on 2025/5/13.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "device_manager/device_factory.h"
|
|
|
|
|
#include "biohead/biohead_esp32/biohead_esp32.h"
|
|
|
|
|
#include "camera/uvc_camera/uvc_camera.h"
|
|
|
|
|
#include "camera/mechmind/mechmind_camera.h"
|
|
|
|
|
#include "speaker/ffmpeg_speaker/ffmpeg_speaker.h"
|
|
|
|
|
#include "microphone/ffmpeg_microphone/ffmpeg_microphone.h"
|
|
|
|
|
#include "camera/realsense_camera/realsense_camera.h"
|
|
|
|
|
#include "dexhand/rh56dftp_dexhand/rh56dftp_dexhand.h"
|
|
|
|
|
#include "robot/humanoid_robot/humanoid_robot.h"
|
|
|
|
|
//#include "robot/ti5_robot/ti5_robot.h"
|
2025-11-10 16:54:06 +08:00
|
|
|
#include "data_center/include/motors_info.h"
|
2025-08-22 16:57:29 +08:00
|
|
|
using namespace std;
|
|
|
|
|
using namespace cmvr::device;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template std::shared_ptr<AbstractAGV> DeviceFactory::create<AbstractAGV>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractBattery> DeviceFactory::create<AbstractBattery>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractCamera> DeviceFactory::create<AbstractCamera>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractDexHand> DeviceFactory::create<AbstractDexHand>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractGripper> DeviceFactory::create<AbstractGripper>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractMicrophone> DeviceFactory::create<AbstractMicrophone>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractRobot> DeviceFactory::create<AbstractRobot>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractSpeaker> DeviceFactory::create<AbstractSpeaker>(const XmlNode&);
|
|
|
|
|
template std::shared_ptr<AbstractBiohead> DeviceFactory::create<AbstractBiohead>(const XmlNode&);
|
|
|
|
|
|
|
|
|
|
template <typename DeviceType>
|
|
|
|
|
std::shared_ptr<DeviceType> DeviceFactory::create(const XmlNode& cfg) {
|
|
|
|
|
if constexpr (std::is_same_v<DeviceType, AbstractAGV>) {
|
|
|
|
|
return create_agv_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractBattery>) {
|
|
|
|
|
return create_battery_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractCamera>) {
|
|
|
|
|
return create_camera_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractDexHand>) {
|
|
|
|
|
return create_dexhand_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractGripper>) {
|
|
|
|
|
return create_gripper_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractMicrophone>) {
|
|
|
|
|
return create_mic_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractRobot>) {
|
|
|
|
|
return create_robot_(cfg);
|
|
|
|
|
} else if constexpr (std::is_same_v<DeviceType, AbstractSpeaker>) {
|
|
|
|
|
return create_speaker_(cfg);
|
|
|
|
|
}else if constexpr (std::is_same_v<DeviceType, AbstractBiohead>){
|
|
|
|
|
return create_biohead_(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type";
|
|
|
|
|
throw runtime_error("[DeviceFactory]: Unsupported device type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractAGV> DeviceFactory::create_agv_(const XmlNode& cfg) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractBattery> DeviceFactory::create_battery_(const XmlNode& cfg) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractCamera> DeviceFactory::create_camera_(const XmlNode& cfg) {
|
|
|
|
|
try {
|
|
|
|
|
if (cfg.getNodeName() == "UVCCamera") {
|
|
|
|
|
return std::make_shared<UVCCamera>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else if (cfg.getNodeName() == "MechMind") {
|
|
|
|
|
return std::make_shared<MechmindCamera>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else if (cfg.getNodeName() == "RealsenseCamera") {
|
|
|
|
|
return std::make_shared<RealsenseCamera>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const exception &e) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractDexHand> DeviceFactory::create_dexhand_(const XmlNode& cfg) {
|
|
|
|
|
try {
|
|
|
|
|
if (cfg.getNodeName() == "RH56DFTP") {
|
|
|
|
|
return std::make_shared<RH56DFTPDexhand>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const exception &e) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractGripper> DeviceFactory::create_gripper_(const XmlNode& cfg) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractMicrophone> DeviceFactory::create_mic_(const XmlNode& cfg) {
|
|
|
|
|
try {
|
|
|
|
|
if (cfg.getNodeName() == "ffmpegMicPhone") {
|
|
|
|
|
return std::make_shared<ffmpegMicroPhone>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const exception &e) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractRobot> DeviceFactory::create_robot_(const XmlNode& cfg) {
|
|
|
|
|
try {
|
|
|
|
|
if (cfg.getNodeName() == "Humanoid") {
|
2025-11-10 16:54:06 +08:00
|
|
|
auto motos_info = MotorsInfo::getInstance();
|
|
|
|
|
motos_info->init(cfg);
|
2025-08-22 16:57:29 +08:00
|
|
|
return std::make_shared<HumanoidRobot<14>>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const exception &e) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractBiohead>DeviceFactory::create_biohead_(const XmlNode& cfg) {
|
|
|
|
|
try {
|
|
|
|
|
if (cfg.getNodeName() == "esp32") {
|
|
|
|
|
return std::make_shared<BioHeadRobot>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const exception &e) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<AbstractSpeaker> DeviceFactory::create_speaker_(const XmlNode& cfg) {
|
|
|
|
|
try {
|
|
|
|
|
if (cfg.getNodeName() == "ffmpegSpeaker") {
|
|
|
|
|
return std::make_shared<ffmpegSpeaker>(cfg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const exception &e) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|