ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Unable to push_back float64 custom msg in std::vector<std_msgs::Float64>

asked 2018-11-06 17:24:38 -0500

surabhi96 gravatar image

updated 2018-11-06 17:28:19 -0500

I have a custom message as follows:

sensor_msgs/PointCloud2 velodynepoints 
float64[3] velodynenormal

and a subscriber nodelet with the following callback function

void class_name::func_name(const pkg_name::msg_file_name::ConstPtr &data) 
{
for (int i = 0; i < 3; i++) {
velodyne_n.push_back(data->velodynenormal[i]);
}
}

where velodyne_n is std::vector< std_msgs::Float64 > velodyne_n; However, I get the following error:

no matching function for call to ‘std::vector<std_msgs::Float64_<std::allocator<void> > >::push_back(const double&)’
 velodyne_n.push_back(data->velodynenormal[i]);
                                             ^

but if I define velodyne_n as std::vector<float> velodyne_n, I get no errors. Can someone help in pointing out where I might be going wrong? Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-11-06 17:59:27 -0500

The datatype std_msgs::Float64 is not the same as a c++ 64 bit float (double). It is a message object that contains a member called data which is a 64bit float type.

To add a std_msgs::Float64 to the velodyne_n vector you'll need to create a std_msgs::Float64 object set it's data member to one of the values from velodynenormal then push_back that object.

edit flag offensive delete link more

Comments

Thank you! I thought float64 in the custom message was of the type std_msgs::Float64

surabhi96 gravatar image surabhi96  ( 2018-11-06 19:02:44 -0500 )edit

I can see how that might be unclear. Glad you got this working

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-07 02:55:13 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-06 17:24:38 -0500

Seen: 2,376 times

Last updated: Nov 06 '18