Ask Your Question
0

ROS Serial Arduino "Hello World" Error

asked 2021-08-24 13:06:31 -0600

matthewfwork gravatar image

Just getting rosserial setup after a few days of issues. When trying to run the Hello World example (code below) I error out (also below). Any help would be great!

*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

// Use the following line if you have a Leonardo or MKR1000
//#define USE_USBCON

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

ros::NodeHandle nh;

std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
{
  nh.initNode();
  nh.advertise(chatter);
}

void loop()
{
  str_msg.data = hello;
  chatter.publish( &str_msg );
  nh.spinOnce();
  delay(1000);
}

Error code

Arduino: 1.8.15 (Linux), Board: "Arduino Uno"

Hello_world:2:14: error: expected constructor, destructor, or type conversion before 'Publisher'
  * rosserial Publisher Example
              ^~~~~~~~~
exit status 1
expected constructor, destructor, or type conversion before 'Publisher'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
edit retag flag offensive close merge delete

Comments

When trying to run the Hello World example

please, always link to whatever you are referring to.

We cannot see what you are seeing, so without a link, we have to spend time finding it ourselves, which means less time to help you solve your problem.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-24 14:08:27 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-24 14:07:38 -0600

gvdhoorn gravatar image

If this is a verbatim copy-paste, you have this:

*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

Note how the first line starts with a *.

It's very likely you made a mistake copying the example, and it should actually be /*, which would be the start of a multi-line comment.

A single star (*) on its own is not a legal character there, hence the compiler error.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-08-24 13:06:31 -0600

Seen: 34 times

Last updated: Aug 24