0
$\begingroup$

Rosanswers logo

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


Originally posted by tejdeep on ROS Answers with karma: 1 on 2014-06-18

Post score: 0


Original comments

Comment by Wolf on 2014-06-19:\

  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.....
$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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);

Originally posted by fergs with karma: 13902 on 2014-06-20

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.