error while compling in rosserial_arduino
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
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.....