How to publish 2D array of int type
How does one go about publishing a 2D array of the integer type in ROS? I am using C++ for this node i am writing.
#include "ros/ros.h"
#include <sstream>
//include?
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::int>("chatter", 1000); //Is this correct?
ros::Rate loop_rate(10);
//define array
data int[2][2];
data[0][0] = 12;
data[1][1] = 23;
while (ros::ok())
{
chatter_pub.publish(data);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
I have tried many things by now and I am really out of options. Anybody that can demonstrate this?
Simply said: I would like the above code to be checked and edited so that it compiles without errors and that it sends a 2D array of type integer.
then please tell us about that, as otherwise we run the risk of suggesting something you've already tried.
Please see the Support Guidelines.
@gdvhoorn, well honestly I would like the above way to work. This would be most convenient.
Have you worked with ROS before? I only ask because it seems strange to expect to be able to publish arbitrary primitive data types. It's possible, but typically you go through / use specialised message structures.
And you didn't answer my question: what have you tried already that didn't work?
I have worked a little with ROS before, but that was only using simple string messages. And using predefined messages aswell. I have tried using int as shown above, I tried something similar with int16 and something with int16MultiArray. I have not tried making a specialized message..