rosserial sending alphanumeric messages [closed]

asked 2016-01-15 01:01:02 -0500

updated 2016-01-15 02:01:44 -0500

gvdhoorn gravatar image

Hello All,

I'm trying to pass a message from my computer to an Arduino using rosserial. The type of message that I want to send is something along the lines of abcd123456 or 123.456abc. Overall length of message will be exactly that many characters every time but I'm not sure yet if there will be more letters and if the letters are first or last and if I'll have a decimal or not. I don't think these variances will make a difference in how the message is sent and received so that is why I have not decided on the exact format just yet.

Here is what I have started with:

#include <ros.h>
#include <std_msgs/String.h>

ros::NodeHandle nh;

const char *FromCPU;
char hello[13] = "hello world!";
char FromCPUArray [100];
byte gotit = LOW;

//////////////////////////////////////////

void messageCb( const std_msgs::String& msg)
{
  char* temp = NULL;
  FromCPU = msg.data;
  //temp = (char*)FromCPU;
  digitalWrite(13, HIGH-digitalRead(13));   // blink LED everytime new comand is received
  gotit = HIGH;
}
std_msgs::String str_msg;
ros::Subscriber<std_msgs::String> subscribe("NewDriverAndValue", &messageCb);
ros::Publisher oldFbPos("oldFbPos", &str_msg);

//////////////////////////////////////////

void setup()
{
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.advertise(oldFbPos);
  nh.subscribe(subscribe);
}

//////////////////////////////////////////

void loop()
{

  str_msg.data = hello;
  if (gotit==HIGH)
  {
    oldFbPos.publish( &str_msg );      // Publishes the str_msg on oldFbPos
  }
  gotit = LOW;
  nh.spinOnce();
  delay(500);
}

I want the message to be an array or string so that I can separate the letters and numbers and the numbers into two parts.

Does FromCPU need to be a const char * or can it be received as an array? What is the most efficient way to send and receive this type of message?

Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2017-02-15 20:49:15.191548

Comments

Can you please format code with the Preformatted text button in the future? That makes things much easier to read. It's the one with 101010 on it. Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2016-01-15 02:02:39 -0500 )edit

I did use that button. It then gave me a blue box where it said enter code here. I'll make sure next time that that is what actually saves.

MiniMe gravatar image MiniMe  ( 2016-01-15 02:41:57 -0500 )edit

Don't worry about it, it was just a suggestion. A tip: paste in your code (or anything you want to format verbatim), select it, and then press the button (or ctrl+k). Works everytime.

gvdhoorn gravatar image gvdhoorn  ( 2016-01-15 02:58:34 -0500 )edit