Ask Your Question

Push_back doesn't work

asked 2015-01-19 04:38:14 -0500

JacoPisa gravatar image

hi everyone, i'm writing a node that could save 3 coordinate and then add a point to a pointcloud. i'm trying to use pushback for the array of points in the cloud, this is the code:

struct stru
   float x,y,z;

sensor_msgs::PointCloud output;

mypoints.x = input->pose.position.x;
mypoints.y = input->pose.position.y;
mypoints.z = input->pose.position.z;

and the catkin_make give me this error:

/home/jacopo/catkin_ws/src/beginner_tutorials/src/svocloud.cpp: In member function ‘void SubAndPub::callback(const ConstPtr&)’:
/home/jacopo/catkin_ws/src/beginner_tutorials/src/svocloud.cpp:56:39: error: no matching function for call to ‘std::vector<geometry_msgs::Point32_<std::allocator<void> >, std::allocator<geometry_msgs::Point32_<std::allocator<void> > > >::push_back(stru&)’
/home/jacopo/catkin_ws/src/beginner_tutorials/src/svocloud.cpp:56:39: note: candidate is:
/usr/include/c++/4.6/bits/stl_vector.h:826:7: note: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = geometry_msgs::Point32_<std::allocator<void> >, _Alloc = std::allocator<geometry_msgs::Point32_<std::allocator<void> > >, std::vector<_Tp, _Alloc>::value_type = geometry_msgs::Point32_<std::allocator<void> >]
/usr/include/c++/4.6/bits/stl_vector.h:826:7: note:   no known conversion for argument 1 from ‘stru’ to ‘const value_type& {aka const geometry_msgs::Point32_<std::allocator<void> >&}’

i'm missing something about push_back but cannot understand what.... do somebody could help me??


edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-01-19 04:45:33 -0500

Erwan R. gravatar image

updated 2015-01-19 06:48:21 -0500

push_back expects the pushed data to be of the type defined by the std::vector<type> that handle the array. PointCloud points array is defined as an array of geometry_msgs/Point32 so you have to use it instead of your custom data structure.

PointCloud doc :

EDIT : If you want to display several markers, you may look at MarkerArray message. If you just want to convert from Point to Point32, you may just fill fields with the corresponding data (the structure are the same), and checking that your conversion doesn't lose data (from float64 to float32)

You should really have a look at message documentation : , , ... so that you can choose the relevant message for you application.

edit flag offensive delete link more


yes that's right! but i'm doing that for converting the coordinate from a marker, for including it into a pointcloud. the pointcloud rappresent it with the geometry_msgs/Point32, but in the marker the coordinate are geometry_msgs/Point. how i can convert one in another format??

JacoPisa gravatar image JacoPisa  ( 2015-01-19 06:23:59 -0500 )edit

Edited my answer, see above.

Erwan R. gravatar image Erwan R.  ( 2015-01-19 06:49:06 -0500 )edit

reading about the pointcloud messages, i find this: "It is recommeded to use Point wherever possible instead of Point32." can i choose that after using pointcloud?? how?? if that is not possible, i'm trying to do what you've said, but x=y where x is float32 and y float64 is not working,how i can do?

JacoPisa gravatar image JacoPisa  ( 2015-01-19 06:55:42 -0500 )edit

answered 2015-01-21 04:24:57 -0500

JacoPisa gravatar image

i'd solve that in this way:

      sensor_msgs::PointCloud output;
      output.header = input->header;
      geometry_msgs::Point32 as;
      as.x = input->pose.position.x;
      as.y = input->pose.position.y;
      as.z = input->pose.position.z; 

But the input->pose.position is the pose of the drone and not the pointcloud, probably i'd read in the wrong way the topics and the messages on Rviz.

i hope this maybe could help someone...

thanks for all your advices Erwan, i appriciate!

edit flag offensive delete link more


I don't get what you want to do at the end, but this solution is in my opinion a good way to push Points into PointCloud, independantly from the source. From your example I understand that you want to add input->pose to the pointcloud, what your code does. Maybe you could explain the final goal ?

Erwan R. gravatar image Erwan R.  ( 2015-01-22 03:19:36 -0500 )edit

the final goal is to extract from a geometry_msgs the coordinates of the point rappresented by the marker and add it to a pointcloud. in particular svo use 2 different ns, "pts" and "trajectory". only the coordinates from "pts" are needed for compose the pointcloud.

JacoPisa gravatar image JacoPisa  ( 2015-01-23 02:36:33 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-01-19 04:38:14 -0500

Seen: 3,118 times

Last updated: Jan 21 '15