64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#ifndef CMVR_ES_DEXHAND_FACTORY_H
|
|
#define CMVR_ES_DEXHAND_FACTORY_H
|
|
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
#include "cmvr/config/dexhand_config/dexhand_config.pb.h"
|
|
#include "common/base/logging/logger.h"
|
|
#include "devices/dexhand/abstract_dexhand.h"
|
|
#include "devices/dexhand/px_6ax_gen3/include/px_6ax_gen3.h"
|
|
#include "devices/dexhand/rh56dftp_dexhand/include/rh56dftp_dexhand.h"
|
|
|
|
namespace cmvr::device {
|
|
|
|
class DexHandFactory {
|
|
public:
|
|
static std::shared_ptr<AbstractDexHand> create(const config::DexHandDeviceConfig& cfg)
|
|
{
|
|
if (cfg.id().empty()) {
|
|
const std::string error = "[DexHandFactory]: DexHand id is empty";
|
|
CMVR_LOG(ERROR) << error;
|
|
return nullptr;
|
|
}
|
|
|
|
switch (cfg.backend_case()) {
|
|
case config::DexHandDeviceConfig::kRh56Dftp:
|
|
return std::make_shared<RH56DFTPDexhand>(
|
|
backendWithId_(cfg.id(), cfg.rh56dftp()));
|
|
|
|
case config::DexHandDeviceConfig::kPx6AxGen3:
|
|
return std::make_shared<PX6AXGen3>(
|
|
backendWithId_(cfg.id(), cfg.px_6ax_gen3()));
|
|
|
|
case config::DexHandDeviceConfig::BACKEND_NOT_SET:
|
|
default:
|
|
{
|
|
const std::string error =
|
|
"[DexHandFactory]: DexHand backend is not configured: " + cfg.id();
|
|
CMVR_LOG(ERROR) << error;
|
|
return nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
template <typename BackendConfig>
|
|
static BackendConfig backendWithId_(const std::string& id, const BackendConfig& source)
|
|
{
|
|
if (!source.id().empty() && source.id() != id) {
|
|
const std::string error = "[DexHandFactory]: DexHand id does not match backend id: " + id;
|
|
CMVR_LOG(ERROR) << error;
|
|
return BackendConfig{};
|
|
}
|
|
BackendConfig backend = source;
|
|
backend.set_id(id);
|
|
return backend;
|
|
}
|
|
};
|
|
|
|
} // namespace cmvr::device
|
|
|
|
#endif // CMVR_ES_DEXHAND_FACTORY_H
|