How to set std::vector<bool> as ros parameter ?
I'm trying to set parameter in two different ways. In both case I'm getting error.
Here is the code example:
Method 1:
std::vector<bool> odomConfig;
nh.param<std::vector<bool>>(odom0_config", odomConfig,
{false, false, false, false, false, false, true, true, true, false, false, false, false, false, false});
Method 2:
std::vector<bool> odomConfig;
ros::param::param<std::vector<bool>>(odom0_config", odomConfig,
{false, false, false, false, false, false, true, true, true, false, false, false, false, false, false});
The error i get in both case is as follows:
[FATAL] [1664453231.205964254]: ASSERTION FAILED
file = /home/user111/git_repos/catkin_ws/src/robot_localization/src/ros_filter.cpp
line = 2280
cond = topicConfig.getType() == XmlRpc::XmlRpcValue::TypeArray
The error is thrown by this line of code link.
Where am I doing wrong in setting parameters ?
Edit 1:
With the answers given, there is no solution to my problem addressed although.
Just a simple problem.
A ros parameter need to be set for ekf_localization_node
of robot_localization
package.
I now set the parameter as follows: (Changed vector template argument type to int
)
But, there is an error (pls see above for the error.)
ros::param::set("odom0", "/husky_velocity_controller/odom");
std::vector<int> odomConfig;
ros::param::param<std::vector<int>>("odom0_config", odomConfig,
{false, false, false, false, false, false, true, true, true, false, false, false, false, false, false});
When I run my project, the below function is called:
template<typename T>
std::vector<int> RosFilter<T>::loadUpdateConfig(const std::string &topicName)
{
XmlRpc::XmlRpcValue topicConfig;
std::vector<int> updateVector(STATE_SIZE, 0);
std::string topicConfigName = topicName + "_config";
try
{
nhLocal_.getParam(topicConfigName, topicConfig);
ROS_ASSERT(topicConfig.getType() == XmlRpc::XmlRpcValue::TypeArray);
}
catch (XmlRpc::XmlRpcException &e)
{
ROS_FATAL_STREAM("Could not read sensor update configuration for topic " << topicName );
}
Here,
std::string topicConfigName = topicName + "_config";
outputs "odom0_config"
The program fails at the line ROS_ASSERT()
Note: The below function is called inside nh.setParam()
function:
template <class T>
void setImpl(const std::string& key, const std::vector<T>& vec)
{
// Note: the XmlRpcValue starts off as "invalid" and assertArray turns it
// into an array type with the given size
XmlRpc::XmlRpcValue xml_vec;
xml_vec.setSize(vec.size());
// Copy the contents into the XmlRpcValue
for(size_t i=0; i < vec.size(); i++) {
xml_vec[i] = vec.at(i);
}
ros::param::set(key, xml_vec);
}
Just a notice, std::vector<bool> is not recommended to use - avoid
std::vector<bool>
and useboost::vector<bool>
. And if you really need to save bits then useboost::dynamic_bitset
.Thank you for the suggestions. However, my team doesn't use boost library for the projects. Also, it would be really helpful when you give actual reasons for your suggestions / recommendations. Then it might be easy to make further considerations.
By the second source in the comment above:
In the new edit - what is the failing result on the LHS. with
topicConfig.getType()
?I think it's a typo only in the question, but in your Method (both 1 & 2) you don't have
odom0_config
within" ... "
topicConfig.getType()
should match the RHS. The ros::param::set() will set the value totype
XmlRpc::XmlRpcValue::TypeArray
.Sorry, its a typo here in the question I posted. In my program, I have set