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

Revision history [back]

click to hide/show revision 1
initial version

Here is a complete example (please edit if any mistakes found)

vector<double> vec;
while (ros::ok()){
    int i = 0;
    std_msgs::Float64MultiArray msg;
    vec = c.getvec(typ); //function which initializes the vector

    msg.layout.dim.push_back(std_msgs::MultiArrayDimension());  
    msg.layout.dim[0].size = vec.size();
    msg.layout.dim[0].stride = 1;
    msg.layout.dim[0].label = strings[typ+4];


    //push data into data blob
    vector<double>::const_iterator itr, end(vec.end());
    for(itr = vec.begin(); itr!= end; ++itr) {
        //cout<<*itr<<endl;
        msg.data.push_back(*itr); 
    }/**/

    chatter_pub.publish(msg);
    ros::spinOnce();

    //clear stuff and sleep
    vec.clear();
    loop_rate.sleep();
}

Unfortunate I wonder if its done right, see output by rostopic echo

layout: 
  dim: 
    - 
      label: /listener_socket/orient
      size: 6
      stride: 1
  data_offset: 0
data: [35589264796691.0, 3.0, 3.0, 167.94601, 1.6419868, 0.15967418]
---


I wonder if this is ok?

Here is a complete example (please edit if any mistakes found)

vector<double> vec;
while (ros::ok()){
    int i = 0;
    std_msgs::Float64MultiArray msg;
    vec = c.getvec(typ); //function which initializes the vector

    msg.layout.dim.push_back(std_msgs::MultiArrayDimension());  
    msg.layout.dim[0].size = vec.size();
    msg.layout.dim[0].stride = 1;
    msg.layout.dim[0].label = strings[typ+4];


    //push data into data blob
    vector<double>::const_iterator itr, end(vec.end());
    for(itr = vec.begin(); itr!= end; ++itr) {
        //cout<<*itr<<endl;
        msg.data.push_back(*itr); 
    }/**/

    chatter_pub.publish(msg);
    ros::spinOnce();

    //clear stuff and sleep
    vec.clear();
    loop_rate.sleep();
}

Unfortunate I wonder if its done right, see output by rostopic echo

layout: 
  dim: 
    - 
      label: /listener_socket/orient
      size: 6
      stride: 1
  data_offset: 0
data: [35589264796691.0, 3.0, 3.0, 167.94601, 1.6419868, 0.15967418]
---


I wonder if this is ok?

Here is a complete example (please edit if any mistakes found)

vector<double> vec;
while (ros::ok()){
    int i = 0;
    std_msgs::Float64MultiArray msg;
    vec = c.getvec(typ); //function which initializes the vector

    msg.layout.dim.push_back(std_msgs::MultiArrayDimension());  
    msg.layout.dim[0].size = vec.size();
    msg.layout.dim[0].stride = 1;
    msg.layout.dim[0].label = strings[typ+4];


    //push data into data blob
    vector<double>::const_iterator itr, end(vec.end());
    for(itr = vec.begin(); itr!= end; ++itr) {
        //cout<<*itr<<endl;
        msg.data.push_back(*itr); 
    }/**/

    chatter_pub.publish(msg);
    ros::spinOnce();

    //clear stuff and sleep
    vec.clear();
    loop_rate.sleep();
}

Unfortunate I wonder if its done right, see output by The result on rostopic echo looks like:

layout: 
  dim: 
    - 
      label: /listener_socket/orient
      size: 6
      stride: 1
  data_offset: 0
data: [35589264796691.0, 3.0, 3.0, 167.94601, 1.6419868, 0.15967418]
---