ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

error while compling in rosserial_arduino

asked 2014-06-18 06:04:43 -0500

tejdeep gravatar image

updated 2014-06-20 02:44:53 -0500

fergs gravatar image

This is my code for the publisher.

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

ros::NodeHandle n;
std_msgs::String str_msg;
ros::Publisher pub_voltage("volts", &str_msg); 
int left_IR_pin = 5;
int centre_IR_pin = 4;
int right_IR_pin = 10;
char right[12] ="right off";
char left[12] ="left off";
boolean directl,directr;
void setup()
{
  n.initNode();
  n.advertise(pub_voltage);
  pinMode(left_IR_pin,INPUT);
  pinMode(centre_IR_pin,INPUT);
  pinMode(right_IR_pin,INPUT);


  directl=digitalRead(left_IR_pin);
  directr=digitalRead(right_IR_pin);
}
void loop(){
  if (directl)
  { str_msg.data = left;
    pub_voltage.publish(&std_msgs);
  }
  if (directr)
  { str_msg.data = right;
    pub_voltage.publish(&std_msgs);
  }
  n.spinOnce();
  delay(1000);

}

After compiling I get the following error: sketch_jun18a.cpp: In function ‘void loop()’: sketch_jun18a.cpp:31:34: error: expected primary-expression before ‘)’ token sketch_jun18a.cpp:35:34: error: expected primary-expression before ‘)’ token

edit retag flag offensive close merge delete

Comments

1) My suggestion is to always try to recompile with arduino IDE, it occasionally fails for whatever reason... 2) if your problem persists 3 or 4 tries, please mark your code as code in the answers.ros.org editor. It is not really readable the way it is now.....

Wolf gravatar image Wolf  ( 2014-06-19 02:25:53 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2014-06-20 02:47:42 -0500

fergs gravatar image

I presume the issue here is the .publish(&std_msgs)... you can't publish a namespace, I presume you meant to publish str_msg, and you shouldn't need the &, so it should just be:

pub_voltage.publish(str_msg);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-06-18 06:04:43 -0500

Seen: 338 times

Last updated: Jun 20 '14