Hey Guys.
I have been trying to setup a string publisher and subscriber using rosserial. I first wrote my own sketch but had some possible buffer issues so I looked online for an example which I found. Here is the sketch that I found online.
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
void messageCb( const std_msgs::String& incoming_msg )
{
str_msg.data = incoming_msg.data;
chatter.publish( &str_msg );
}
ros::Subscriber<std_msgs::String> sub("test", &messageCb );
void setup()
{
nh.initNode();
nh.advertise(chatter);
nh.subscribe(sub);
}
void loop()
{
//chatter.publish( &str_msg );
nh.spinOnce();
delay(200);
}
This works fine until I move chatter.publish( &str_msg ); from where it is to void loop(). Once I move chatter to the main loop I experience the same problems as I did with my own code. It looks to me like the buffer is full and needs to be flushed each time.
Is the problem with the buffer being full? How do I flush it? Or is it something else?
Thanks