Ask Your Question
0

Convert from Int32MultiArray into vector (roscpp)

asked 2016-02-13 14:33:48 -0500

user23fj239 gravatar image

How to simply put array from the std_msgs into vector<double>

 void setdot(const std_msgs::Int32MultiArray::ConstPtr& arr){
    vector<double> tmp;
        tmp.push_back(arr[0]);
        tmp.push_back(arr[1]);
        tmp.push_back(arr[2]);
}

error: invalid use of void expression if i compile it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-02-13 14:52:39 -0500

user23fj239 gravatar image

updated 2016-02-13 15:49:38 -0500

For anyone who is interested I had a look at this, which converts the std_msgs into an Array but this is how the vector is done:

    void setdot(const std_msgs::Int32MultiArray::ConstPtr& array){
    vector<double> tmp;
    for(std::vector<int>::const_iterator it = array->data.begin(); it != array->data.end(); ++it)
    {   
        tmp.push_back( *it);
    }
    //do sth with tmp ..
    }

Furthermore check if the input message is not empty, which might occur on the first callbacks as it was in my case.
Otherwise Segmentation fault (core dumped) might happen.

edit flag offensive delete link more

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

Stats

Asked: 2016-02-13 14:33:48 -0500

Seen: 243 times

Last updated: Feb 13 '16