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

how to use std::find to search an element in the PoseStamped x and y.

asked 2019-01-30 03:47:30 -0500

rathish gravatar image

updated 2019-01-30 03:48:33 -0500

I am working with ros kinetic to check if my poseStamped messages has an element which passed on from a function

double gothrough(int in, int j ){ 
    std::vector<geometry_msgs::PoseStamped>  gothro;
    std::vector<geometry_msgs::PoseStamped> new_x;
    std::vector<geometry_msgs::PoseStamped> new_y;  

    new_x.push_back(gothrough_x); // where gothrough_x is the posestamped messages from the callback subscriber
    new_y.push_back(gothrough_y); // where gothrough_y is the posestamped messages from the callback subscriber
    int i =0;
    for(std::vector<int>::iterator it =new_x.begin(); it !=new_x.end(); it++){

           for(int i =0; i <  gothro.size(); i++ )
            std::find(std::begin(gothro), std::end(gothro), in);   // **I am trying to find if the element In is present in the gothrough_x but i am getting error at this line std:find, it would be grateful if someone help me out on this**

edit retag flag offensive close merge delete



This is more a C++ question. You could probably use std::find_if(..) and write a lambda that compares a geometry_msgs/PoseStamped to in in a meaningful way.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-30 04:04:57 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-01-30 07:09:46 -0500

A few things. Firstly if you're getting an error can you put the exact error in your question, it would help a lot.

What you're asking the compiler to do is not well defined, and your syntax is wrong causing this problem. Are you trying to find a PoseStamped message in the list which contains the number in in any of its elements or a specific element? If so what are you actually trying to achieve because this is a rather strange operation?

the in variable is an int, so you can't 'find' it in the gothro vector because this contains geometry_msgs::PoseStamped objects which cannot be directly compared to an int.

If you can be a bit clearer about what you're trying to do here we can probably suggest a solution.

edit flag offensive delete link more


geometry_msgs::PoseStamped objects which cannot be directly compared to an int.

that is true, but from the question it would seem that the OP wants to compare one of the fields of PoseStamped with in. That's why I suggested writing a lambda for std::find_if(..).

gvdhoorn gravatar image gvdhoorn  ( 2019-01-30 08:51:55 -0500 )edit

Question Tools


Asked: 2019-01-30 03:43:37 -0500

Seen: 168 times

Last updated: Jan 30 '19