22 switch (val.get_type()) {
23 case rclcpp::PARAMETER_BOOL:
24 return BT::GetAnyFromStringFunctor<bool>()(BT::toStr(val.get<
bool>()));
25 case rclcpp::PARAMETER_INTEGER:
26 return BT::GetAnyFromStringFunctor<int64_t>()(BT::toStr(val.get<int64_t>()));
27 case rclcpp::PARAMETER_DOUBLE:
28 return BT::GetAnyFromStringFunctor<double>()(BT::toStr(val.get<
double>()));
29 case rclcpp::PARAMETER_STRING:
30 return BT::GetAnyFromStringFunctor<std::string>()(BT::toStr(val.get<std::string>()));
31 case rclcpp::PARAMETER_BYTE_ARRAY:
32 return BT::GetAnyFromStringFunctor<std::vector<uint8_t>>()(BT::toStr(val.get<std::vector<uint8_t>>()));
33 case rclcpp::PARAMETER_BOOL_ARRAY:
34 return BT::GetAnyFromStringFunctor<std::vector<bool>>()(BT::toStr(val.get<std::vector<bool>>()));
35 case rclcpp::PARAMETER_INTEGER_ARRAY:
36 return BT::GetAnyFromStringFunctor<std::vector<int64_t>>()(BT::toStr(val.get<std::vector<int64_t>>()));
37 case rclcpp::PARAMETER_DOUBLE_ARRAY:
38 return BT::GetAnyFromStringFunctor<std::vector<double>>()(BT::toStr(val.get<std::vector<double>>()));
39 case rclcpp::PARAMETER_STRING_ARRAY:
40 return BT::GetAnyFromStringFunctor<std::vector<std::string>>()(BT::toStr(val.get<std::vector<std::string>>()));
46 return nonstd::make_unexpected(
47 "Conversion of rclcpp::ParameterValue with type '" + rclcpp::to_string(val.get_type()) +
48 "' to BT::Any is undefined.");
55 case rclcpp::ParameterType::PARAMETER_NOT_SET:
65 if (any.isType<std::vector<std::string>>())
73 error =
"Cannot infer parameter type.";
75 case rclcpp::PARAMETER_BOOL: {
76 const auto casted = any.tryCast<
bool>();
77 if (casted)
return rclcpp::ParameterValue(casted.value());
78 error = casted.error();
81 case rclcpp::PARAMETER_INTEGER: {
82 const auto casted = any.tryCast<int64_t>();
83 if (casted)
return rclcpp::ParameterValue(casted.value());
84 error = casted.error();
87 case rclcpp::PARAMETER_DOUBLE: {
88 const auto casted = any.tryCast<
double>();
89 if (casted)
return rclcpp::ParameterValue(casted.value());
90 error = casted.error();
93 case rclcpp::PARAMETER_STRING: {
94 const auto casted = any.tryCast<std::string>();
95 if (casted)
return rclcpp::ParameterValue(casted.value());
96 error = casted.error();
99 case rclcpp::PARAMETER_BYTE_ARRAY: {
100 const auto casted = any.tryCast<std::vector<uint8_t>>();
101 if (casted)
return rclcpp::ParameterValue(casted.value());
102 error = casted.error();
105 case rclcpp::PARAMETER_BOOL_ARRAY: {
106 const auto casted = any.tryCast<std::vector<bool>>();
107 if (casted)
return rclcpp::ParameterValue(casted.value());
108 error = casted.error();
111 case rclcpp::PARAMETER_INTEGER_ARRAY: {
112 const auto casted = any.tryCast<std::vector<int64_t>>();
113 if (casted)
return rclcpp::ParameterValue(casted.value());
114 error = casted.error();
117 case rclcpp::PARAMETER_DOUBLE_ARRAY: {
118 const auto casted = any.tryCast<std::vector<double>>();
119 if (casted)
return rclcpp::ParameterValue(casted.value());
120 error = casted.error();
123 case rclcpp::PARAMETER_STRING_ARRAY: {
124 const auto casted = any.tryCast<std::vector<std::string>>();
125 if (casted)
return rclcpp::ParameterValue(casted.value());
126 error = casted.error();
132 return nonstd::make_unexpected(
133 "Conversion of BT::Any (Internal type: " + BT::demangle(any.type()) +
") to rclcpp::ParameterValue with type '" +
134 rclcpp::to_string(type) +
"' failed: " + error);