rosserial pub sub string

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

Is the problem with the buffer being full?

No.

How do I flush it?

That would depend on what the type of data is in the str_msg object. A link to the library would be useful.

What I want to send is 6 numbers followed by 4 letters. ex 123456abcd. Assuming 491023 would be the highest count. Not sure what the letters are yet.

Maybe what I should have asked is what would be the most efficient way to send this from the PC to the Arduino using rosserial?

Thanks.

Maybe what I should have asked is what would be the most efficient way to send this from the PC to the Arduino using rosserial?

First, you should explain what rosserial is, and why you want to use it.

All that templated stuff produces code that is far larger than what is needed to send 10 characters to the Arduino.