add skill_config.hpp
This commit is contained in:
161
src/brain/include/brain/skill_config.hpp
Normal file
161
src/brain/include/brain/skill_config.hpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#pragma once
|
||||
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
|
||||
#include "interfaces/action/arm_space_control.hpp"
|
||||
#include "interfaces/action/hand_control.hpp"
|
||||
#include "interfaces/action/leg_control.hpp"
|
||||
#include "interfaces/action/vision_grasp_object.hpp"
|
||||
#include "interfaces/srv/vision_object_recognition.hpp"
|
||||
#include "interfaces/action/arm.hpp"
|
||||
#include "interfaces/action/slam_mode.hpp"
|
||||
#include "interfaces/srv/map_save.hpp"
|
||||
#include "interfaces/srv/map_load.hpp"
|
||||
#include "nav2_msgs/action/navigate_to_pose.hpp"
|
||||
#include "interfaces/action/camera_take_photo.hpp"
|
||||
#include "interfaces/action/waist_control.hpp"
|
||||
|
||||
using interfaces::action::ArmSpaceControl;
|
||||
using interfaces::action::Arm;
|
||||
using interfaces::action::HandControl;
|
||||
using interfaces::action::LegControl;
|
||||
using interfaces::action::SlamMode;
|
||||
using nav2_msgs::action::NavigateToPose;
|
||||
using interfaces::srv::MapSave;
|
||||
using interfaces::srv::MapLoad;
|
||||
using interfaces::action::VisionGraspObject;
|
||||
using interfaces::srv::VisionObjectRecognition;
|
||||
using interfaces::action::CameraTakePhoto;
|
||||
using interfaces::action::WaistControl;
|
||||
|
||||
namespace brain
|
||||
{
|
||||
|
||||
template<typename ActionT>
|
||||
struct SkillActionTrait;
|
||||
|
||||
/**
|
||||
* @brief Tuple listing of all supported skill action types for dispatcher iteration.
|
||||
*/
|
||||
using SkillActionTypes = std::tuple<
|
||||
// ArmSpaceControl,
|
||||
Arm,
|
||||
HandControl,
|
||||
LegControl,
|
||||
// VisionGraspObject,
|
||||
// SlamMode,
|
||||
// NavigateToPose,
|
||||
CameraTakePhoto,
|
||||
WaistControl
|
||||
>;
|
||||
|
||||
template<typename ServiceT>
|
||||
struct SkillServiceTrait;
|
||||
|
||||
using SkillServiceTypes = std::tuple<
|
||||
// MapSave,
|
||||
// MapLoad,
|
||||
// VisionObjectRecognition
|
||||
>;
|
||||
|
||||
/**
|
||||
* @brief Primary template (unspecialized) for skill action trait extraction.
|
||||
* Specializations must define: skill_name (constexpr const char*), success(result), message(result).
|
||||
*/
|
||||
template<typename ActionT>
|
||||
struct SkillActionTrait; // intentionally undefined primary template
|
||||
|
||||
template<>
|
||||
struct SkillActionTrait<ArmSpaceControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "ArmSpaceControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const ArmSpaceControl::Result & r) {return r.success;}
|
||||
static std::string message(const ArmSpaceControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<Arm>
|
||||
{
|
||||
static constexpr const char * skill_name = "Arm";
|
||||
static constexpr const char * default_topic = "ArmAction";
|
||||
static bool success(const Arm::Result & r) {return (r.result == 0)? true:false;}
|
||||
static std::string message(const Arm::Result & r) {(void)r;return "completed";}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<HandControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "HandControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const HandControl::Result & r) {return r.success;}
|
||||
static std::string message(const HandControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<CameraTakePhoto>
|
||||
{
|
||||
static constexpr const char * skill_name = "CameraTakePhoto";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const CameraTakePhoto::Result & r) {return r.success;}
|
||||
static std::string message(const CameraTakePhoto::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<WaistControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "WaistControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const WaistControl::Result & r) {return r.success;}
|
||||
static std::string message(const WaistControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<LegControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "LegControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const LegControl::Result & r) {return r.success;}
|
||||
static std::string message(const LegControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<VisionGraspObject>
|
||||
{
|
||||
static constexpr const char * skill_name = "VisionGraspObject";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const VisionGraspObject::Result & r) {return r.success;}
|
||||
static std::string message(const VisionGraspObject::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<SlamMode>
|
||||
{
|
||||
static constexpr const char * skill_name = "SlamMode";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const SlamMode::Result & r) {return r.success;}
|
||||
static std::string message(const SlamMode::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<nav2_msgs::action::NavigateToPose>
|
||||
{
|
||||
static constexpr const char * skill_name = "NavigateToPose";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const nav2_msgs::action::NavigateToPose::Result & r) {(void)r;return true;}
|
||||
static std::string message(const nav2_msgs::action::NavigateToPose::Result & r) {(void)r;return "completed";}
|
||||
};
|
||||
|
||||
// Service trait specializations for service registrar name extraction
|
||||
template<>
|
||||
struct SkillServiceTrait<MapSave>
|
||||
{
|
||||
static constexpr const char * skill_name = "MapSave";
|
||||
static constexpr const char * default_topic = "";
|
||||
};
|
||||
template<>
|
||||
struct SkillServiceTrait<MapLoad>
|
||||
{
|
||||
static constexpr const char * skill_name = "MapLoad";
|
||||
static constexpr const char * default_topic = "";
|
||||
};
|
||||
template<>
|
||||
struct SkillServiceTrait<VisionObjectRecognition>
|
||||
{
|
||||
static constexpr const char * skill_name = "VisionObjectRecognition";
|
||||
static constexpr const char * default_topic = "";
|
||||
};
|
||||
|
||||
} // namespace brain
|
||||
@@ -14,62 +14,10 @@
|
||||
#include "brain/action_registry.hpp"
|
||||
#include "brain/bt_registry.hpp"
|
||||
|
||||
#include "interfaces/action/arm_space_control.hpp"
|
||||
#include "interfaces/action/hand_control.hpp"
|
||||
#include "interfaces/action/leg_control.hpp"
|
||||
#include "interfaces/action/vision_grasp_object.hpp"
|
||||
#include "interfaces/srv/vision_object_recognition.hpp"
|
||||
#include "interfaces/action/arm.hpp"
|
||||
#include "interfaces/action/slam_mode.hpp"
|
||||
#include "interfaces/srv/map_save.hpp"
|
||||
#include "interfaces/srv/map_load.hpp"
|
||||
#include "nav2_msgs/action/navigate_to_pose.hpp"
|
||||
#include "interfaces/action/camera_take_photo.hpp"
|
||||
#include "interfaces/action/waist_control.hpp"
|
||||
|
||||
using interfaces::action::ArmSpaceControl;
|
||||
using interfaces::action::Arm;
|
||||
using interfaces::action::HandControl;
|
||||
using interfaces::action::LegControl;
|
||||
using interfaces::action::SlamMode;
|
||||
using nav2_msgs::action::NavigateToPose;
|
||||
using interfaces::srv::MapSave;
|
||||
using interfaces::srv::MapLoad;
|
||||
using interfaces::action::VisionGraspObject;
|
||||
using interfaces::srv::VisionObjectRecognition;
|
||||
using interfaces::action::CameraTakePhoto;
|
||||
using interfaces::action::WaistControl;
|
||||
#include "brain/skill_config.hpp"
|
||||
|
||||
namespace brain
|
||||
{
|
||||
|
||||
template<typename ActionT>
|
||||
struct SkillActionTrait;
|
||||
|
||||
/**
|
||||
* @brief Tuple listing of all supported skill action types for dispatcher iteration.
|
||||
*/
|
||||
using SkillActionTypes = std::tuple<
|
||||
// ArmSpaceControl,
|
||||
Arm,
|
||||
HandControl,
|
||||
LegControl,
|
||||
// VisionGraspObject,
|
||||
// SlamMode,
|
||||
// NavigateToPose,
|
||||
CameraTakePhoto,
|
||||
WaistControl
|
||||
>;
|
||||
|
||||
template<typename ServiceT>
|
||||
struct SkillServiceTrait;
|
||||
|
||||
using SkillServiceTypes = std::tuple<
|
||||
// MapSave,
|
||||
// MapLoad,
|
||||
// VisionObjectRecognition
|
||||
>;
|
||||
|
||||
/**
|
||||
* @brief Specification of a skill as parsed from YAML.
|
||||
*
|
||||
@@ -138,7 +86,7 @@ private:
|
||||
ActionClientRegistry * action_clients_ {nullptr};
|
||||
BTRegistry * bt_ {nullptr};
|
||||
std::unordered_map<std::string, SkillSpec> skills_;
|
||||
std::vector<rclcpp::ClientBase::SharedPtr> service_clients_; // 保存 service client 生命周期
|
||||
std::vector<rclcpp::ClientBase::SharedPtr> service_clients_;
|
||||
std::unordered_map<std::string, rclcpp::ClientBase::SharedPtr> service_client_map_; // skill name -> client
|
||||
std::unordered_map<std::string, std::function<void(const std::string &, const std::string &)>>
|
||||
action_override_registrars_;
|
||||
@@ -436,105 +384,4 @@ bool dispatch_skill_action(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Primary template (unspecialized) for skill action trait extraction.
|
||||
* Specializations must define: skill_name (constexpr const char*), success(result), message(result).
|
||||
*/
|
||||
template<typename ActionT>
|
||||
struct SkillActionTrait; // intentionally undefined primary template
|
||||
|
||||
template<>
|
||||
struct SkillActionTrait<ArmSpaceControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "ArmSpaceControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const ArmSpaceControl::Result & r) {return r.success;}
|
||||
static std::string message(const ArmSpaceControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<Arm>
|
||||
{
|
||||
static constexpr const char * skill_name = "Arm";
|
||||
static constexpr const char * default_topic = "ArmAction";
|
||||
static bool success(const Arm::Result & r) {return (r.result == 0)? true:false;}
|
||||
static std::string message(const Arm::Result & r) {(void)r;return "completed";}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<HandControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "HandControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const HandControl::Result & r) {return r.success;}
|
||||
static std::string message(const HandControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<CameraTakePhoto>
|
||||
{
|
||||
static constexpr const char * skill_name = "CameraTakePhoto";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const CameraTakePhoto::Result & r) {return r.success;}
|
||||
static std::string message(const CameraTakePhoto::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<WaistControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "WaistControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const WaistControl::Result & r) {return r.success;}
|
||||
static std::string message(const WaistControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<LegControl>
|
||||
{
|
||||
static constexpr const char * skill_name = "LegControl";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const LegControl::Result & r) {return r.success;}
|
||||
static std::string message(const LegControl::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<VisionGraspObject>
|
||||
{
|
||||
static constexpr const char * skill_name = "VisionGraspObject";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const VisionGraspObject::Result & r) {return r.success;}
|
||||
static std::string message(const VisionGraspObject::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<SlamMode>
|
||||
{
|
||||
static constexpr const char * skill_name = "SlamMode";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const SlamMode::Result & r) {return r.success;}
|
||||
static std::string message(const SlamMode::Result & r) {return r.message;}
|
||||
};
|
||||
template<>
|
||||
struct SkillActionTrait<nav2_msgs::action::NavigateToPose>
|
||||
{
|
||||
static constexpr const char * skill_name = "NavigateToPose";
|
||||
static constexpr const char * default_topic = "";
|
||||
static bool success(const nav2_msgs::action::NavigateToPose::Result & r) {(void)r;return true;}
|
||||
static std::string message(const nav2_msgs::action::NavigateToPose::Result & r) {(void)r;return "completed";}
|
||||
};
|
||||
|
||||
// Service trait specializations for service registrar name extraction
|
||||
template<>
|
||||
struct SkillServiceTrait<MapSave>
|
||||
{
|
||||
static constexpr const char * skill_name = "MapSave";
|
||||
static constexpr const char * default_topic = "";
|
||||
};
|
||||
template<>
|
||||
struct SkillServiceTrait<MapLoad>
|
||||
{
|
||||
static constexpr const char * skill_name = "MapLoad";
|
||||
static constexpr const char * default_topic = "";
|
||||
};
|
||||
template<>
|
||||
struct SkillServiceTrait<VisionObjectRecognition>
|
||||
{
|
||||
static constexpr const char * skill_name = "VisionObjectRecognition";
|
||||
static constexpr const char * default_topic = "";
|
||||
};
|
||||
|
||||
|
||||
} // namespace brain
|
||||
|
||||
Reference in New Issue
Block a user