Access all the fields in ROS msg
This is probably a very simple and stupid question, but I searched everywhere, and maybe because it's so simple I can't find an answer.
I created a msg like this (and maybe Im gonna add a string later as well)
int64 intensity
int64 location
int64 duration
And now I'm trying to give values to each of this variables and publish them in a topic. I did the follow:
// (dont know how I'll do if I had the string, but thats not the problem **yet**)
ros::Publisher chatter_pub = n.advertise<std_msgs::Int64>("chatter", 1000);
std_msgs::Int64 msg;
Now the question comes here. In the ros publisher tutorials, we use msg.data, and as I searched online I found that data was the name of our variable. However, I did not understand that. How can I give values to every field of my message? I thought on doing something like this, but I know its not correct...
msg.data.intensity = 15;
msg.data.location = 100;
msg.data.duration = 37;
//ROS_INFO("intensity %d, local %d, dura %d ", msg.data.intensity,msg.data, msg.data);
chatter_pub.publish(msg);
Thank you!!