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

I am posting this because it took me some time to get it working and may be it can help someone in the future:

I was able to send and receive my custom message matrix

Header header
uint32 size #es cuadrada
int32[] data

By following this tutorial http://alexsleat.co.uk/2011/07/02/ros-publishing-and-subscribing-to-arrays/.

Arrays are stored as vector<int> and to iterate through them be sure to use const_iterator

vector<int>::const_iterator it;

To print the received matrix values looking like a matrix

int count=0;
for(int i=0;i<size*size;i++){
        if(count%input.size==0)
            cout<<endl;
        cout<<input.data[i]<<" ";
        cuenta++;
    }

And about how the messages store things like int32[], they do use a vector<int> so any size is allowed.

I am posting this because it took me some time to get it working and may be it can help someone in the future:

I was able to send and receive my custom message matrix

Header header
uint32 size #es cuadrada
int32[] data

By following this tutorial http://alexsleat.co.uk/2011/07/02/ros-publishing-and-subscribing-to-arrays/.

Arrays are stored as vector<int> and to iterate through them be sure to use const_iterator

vector<int>::const_iterator it;
it=matrix.data.begin();

To print the received matrix values looking like a matrix

int count=0;
for(int i=0;i<size*size;i++){
        if(count%input.size==0)
            cout<<endl;
        cout<<input.data[i]<<" cout<<matrix.data[i]<<" ";
        cuenta++;
    }

And about how the messages store things like int32[], they do use a vector<int> so any size is allowed.

I am posting this because it took me some time to get it working and may be it can help someone in the future:

I was able to send and receive my custom message matrixmatrix.msg

Header header
uint32 size #es cuadrada
int32[] data

By following this tutorial http://alexsleat.co.uk/2011/07/02/ros-publishing-and-subscribing-to-arrays/.

Arrays are stored as vector<int> and to iterate through them be sure to use const_iterator

vector<int>::const_iterator it;
it=matrix.data.begin();

To print the received matrix values looking like a matrix

int count=0;
for(int i=0;i<size*size;i++){
        if(count%input.size==0)
            cout<<endl;
        cout<<matrix.data[i]<<" ";
        cuenta++;
    }

I am posting this because it took me some time to get it working and may be it can help someone in the future:

I was able to send and receive my custom message matrix.msg

Header header
uint32 size #es cuadrada
int32[] data

By following this tutorial http://alexsleat.co.uk/2011/07/02/ros-publishing-and-subscribing-to-arrays/.

Arrays are stored as vector<int> and to that's why size doesn't matter. To iterate through them be sure to use const_iterator

vector<int>::const_iterator it;
it=matrix.data.begin();

To print the received matrix values looking like a matrix

int count=0;
for(int i=0;i<size*size;i++){
        if(count%input.size==0)
            cout<<endl;
        cout<<matrix.data[i]<<" ";
        cuenta++;
    }