Robotics StackExchange | Archived questions

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

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++){

       gothro.push_back(*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**

             } 
    }

Asked by rathish on 2019-01-30 04:43:37 UTC

Comments

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.

Asked by gvdhoorn on 2019-01-30 05:04:57 UTC

Answers

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.

Asked by PeteBlackerThe3rd on 2019-01-30 08:09:46 UTC

Comments

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(..).

Asked by gvdhoorn on 2019-01-30 09:51:55 UTC