support topic configuration
This commit is contained in:
@@ -447,6 +447,7 @@ 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;}
|
||||
};
|
||||
@@ -454,6 +455,7 @@ 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";}
|
||||
};
|
||||
@@ -461,6 +463,7 @@ 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;}
|
||||
};
|
||||
@@ -468,6 +471,7 @@ 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;}
|
||||
};
|
||||
@@ -475,6 +479,7 @@ 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;}
|
||||
};
|
||||
@@ -482,6 +487,7 @@ 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;}
|
||||
};
|
||||
@@ -489,6 +495,7 @@ 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;}
|
||||
};
|
||||
@@ -496,6 +503,7 @@ 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;}
|
||||
};
|
||||
@@ -503,6 +511,7 @@ 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";}
|
||||
};
|
||||
@@ -512,16 +521,19 @@ 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 = "";
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -202,6 +202,41 @@ static const std::unordered_map<std::string, ServiceRegistrar> & get_service_reg
|
||||
return kMap;
|
||||
}
|
||||
|
||||
// Build maps of default topics for actions and services (name -> default topic string).
|
||||
template<typename TupleT, std::size_t... I>
|
||||
static std::unordered_map<std::string, std::string> build_action_default_topics(std::index_sequence<I...>) {
|
||||
std::unordered_map<std::string, std::string> m;
|
||||
(void)std::array<int, sizeof...(I)>{{(m.emplace(
|
||||
std::string(SkillActionTrait<std::tuple_element_t<I, TupleT>>::skill_name),
|
||||
std::string(SkillActionTrait<std::tuple_element_t<I, TupleT>>::default_topic)), 0)...}};
|
||||
return m;
|
||||
}
|
||||
|
||||
static const std::unordered_map<std::string, std::string> & get_action_default_topics()
|
||||
{
|
||||
using TupleT = SkillActionTypes;
|
||||
constexpr std::size_t N = std::tuple_size<TupleT>::value;
|
||||
static const std::unordered_map<std::string, std::string> kMap = build_action_default_topics<TupleT>(std::make_index_sequence<N>{});
|
||||
return kMap;
|
||||
}
|
||||
|
||||
template<typename TupleT, std::size_t... I>
|
||||
static std::unordered_map<std::string, std::string> build_service_default_topics(std::index_sequence<I...>) {
|
||||
std::unordered_map<std::string, std::string> m;
|
||||
(void)std::array<int, sizeof...(I)>{{(m.emplace(
|
||||
std::string(SkillServiceTrait<std::tuple_element_t<I, TupleT>>::skill_name),
|
||||
std::string(SkillServiceTrait<std::tuple_element_t<I, TupleT>>::default_topic)), 0)...}};
|
||||
return m;
|
||||
}
|
||||
|
||||
static const std::unordered_map<std::string, std::string> & get_service_default_topics()
|
||||
{
|
||||
using TupleT = SkillServiceTypes;
|
||||
constexpr std::size_t N = std::tuple_size<TupleT>::value;
|
||||
static const std::unordered_map<std::string, std::string> kMap = build_service_default_topics<TupleT>(std::make_index_sequence<N>{});
|
||||
return kMap;
|
||||
}
|
||||
|
||||
// Utility: join map keys for diagnostics
|
||||
template<typename T>
|
||||
static std::string join_keys(const std::unordered_map<std::string, T> & m)
|
||||
@@ -265,19 +300,30 @@ void SkillManager::register_interfaces_(const SkillSpec & s)
|
||||
const std::string base_snake = to_snake_case(parsed->base);
|
||||
|
||||
auto resolve_topic_name = [&](const std::string & kind_suffix) {
|
||||
// Arm 动作默认话题使用 "ArmAction",其余沿用 prefix + base_snake
|
||||
const bool is_arm_action = (parsed->base == "Arm" && kind_suffix == "action");
|
||||
const std::string default_topic = is_arm_action ? std::string("ArmAction") : join_topic(prefix_value, base_snake);
|
||||
// Compute the prior default (prefix + base_snake), but allow per-trait default topic when provided.
|
||||
const std::string prefix_default = join_topic(prefix_value, base_snake);
|
||||
const auto & action_defaults = get_action_default_topics();
|
||||
const auto & service_defaults = get_service_default_topics();
|
||||
std::string trait_default;
|
||||
if (kind_suffix == "action") {
|
||||
auto it = action_defaults.find(parsed->base);
|
||||
if (it != action_defaults.end()) { trait_default = it->second; }
|
||||
} else {
|
||||
auto it = service_defaults.find(parsed->base);
|
||||
if (it != service_defaults.end()) { trait_default = it->second; }
|
||||
}
|
||||
const bool has_trait_default = !trait_default.empty();
|
||||
const std::string computed_default = has_trait_default ? trait_default : prefix_default;
|
||||
const std::string param_name = base_snake + "." + kind_suffix + "_name";
|
||||
std::string topic_override;
|
||||
if (node_->get_parameter(param_name, topic_override)) {
|
||||
if (topic_override.empty()) {
|
||||
topic_override = default_topic;
|
||||
}
|
||||
// If user explicitly sets an empty parameter, fall back to computed_default.
|
||||
if (topic_override.empty()) { topic_override = computed_default; }
|
||||
return topic_override;
|
||||
}
|
||||
node_->declare_parameter<std::string>(param_name, default_topic);
|
||||
return default_topic;
|
||||
// Declare with computed default so it appears in parameter list; keep existing semantics.
|
||||
node_->declare_parameter<std::string>(param_name, computed_default);
|
||||
return computed_default;
|
||||
};
|
||||
|
||||
if (parsed->kind == "action") {
|
||||
|
||||
Reference in New Issue
Block a user