Modifing chatterCallback for a simple int and plot in multi-machine
Hi everyone, I'm new to ROS and C++ and I'm not actually understand the function chatterCallback. To learn about it I just remade the talker and listener (C++) using a uint32 called score (at data.msg) instead of string, And I'm trying to plot it in two different machines. I did the talker works nice, as in this code:
#include "ros/ros.h"
#include "firstplot/data.h"
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<firstplot::data>("num", 1000);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok())
{
firstplot::data msg;
msg.score = count;
ROS_INFO("Count: %d", count);
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
The main for subscriber is just:
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("num", 1000, chatterCallback);
ros::spin();
return 0;
}
But I'm really stuck for this chatterCallback, mostly because of the ConstPtr (that I didn't get whats for) and the '->' that I don't know what means.
The second question is: is it really necessary to use the listener to plot in another machine? I mean, I'm using a talker in a raspberry, and I want to plot this uint32 in my PC. I tried it, the topics are working, but rqt_plot dont
If anyone could explain for a really newbie programmer with examples, I would be grateful