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

How to send arrays with std_msgs/UInt8MultiArray and std_msgs/Float64MultiArray?

asked 2021-12-23 10:02:55 -0500

v.leto gravatar image

Hi! I woul like to send arrays to a node, I've tried with this code, but I think there is something wrong when I try to copy the array values in the data structure...

uint8_t SSS_ground_unito[doppio_bins]={0};
immagine::pixel_ned messaggio;
double point_seabed_n[doppio_bins]={0};
double point_seabed_e[doppio_bins]={0};

//funzione per inviare il messaggio al nuovo nodo
void send_immagine(uint8_t SSS_grnd_unito[],double point_sbed_n[], double point_sbed_e[]){;;;
    cout <<"send"<<<<endl;
    write_Out.publish(messaggio);//pubblica il messaggio sul topic 
    ROS_INFO("ping inviato");

this is my msg

std_msgs/UInt8MultiArray  pixel
std_msgs/Float64MultiArray nord
std_msgs/Float64MultiArray est
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-12-26 01:54:23 -0500

robustify gravatar image

The data fields of pixel, nord, and est are all std::vector, and must therefore have array elements allocated with either .resize() (see this) or by using .push_back() (see this).

Both ways will require your code to know how many array elements to expect in the input arguments to the send_immagine function. If you know there are N elements in the input arrays, you could use .resize(N) on each data field to allocate the required number of array elements, then copy each input array element into the corresponding vector element.

Alternatively, loop over the input array and call .push_back() once for each element.

edit flag offensive delete link more

Question Tools



Asked: 2021-12-23 10:02:55 -0500

Seen: 294 times

Last updated: Dec 26 '21