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

AyeSir's profile - activity

2019-06-09 02:19:02 -0500 received badge  Famous Question (source)
2019-06-09 02:19:02 -0500 received badge  Notable Question (source)
2018-07-25 14:04:31 -0500 received badge  Famous Question (source)
2017-04-04 03:44:34 -0500 received badge  Notable Question (source)
2017-02-12 15:13:58 -0500 received badge  Popular Question (source)
2016-09-19 03:38:23 -0500 received badge  Enthusiast
2016-09-12 11:11:27 -0500 received badge  Popular Question (source)
2016-09-09 04:27:55 -0500 commented answer Invalid Conversion from void(*) to ros::Subscriber function

And the error shown is

invalid use of template-name 'ros::Subscriber' without an argument list on both lines

So is there any right format for me to write the function correctly?

2016-09-09 04:24:00 -0500 commented answer Invalid Conversion from void(*) to ros::Subscriber function

Yes i am trying to create subscriber. The 2 lines are what my senior had used and implement it into my code which i dont really understand. i have change the 2 lines

ros::Subscriber sub=nh.subscribe("lwheel_vtarget",10, lmotorCb);

ros::Subscriber sub=nh.subscribe("rwheel_vtarget",10, rmotorCb)

2016-09-09 01:39:52 -0500 asked a question Invalid Conversion from void(*) to ros::Subscriber function

Hi Friends,

I am new to ROS and Arduino programming. I am using linux ros system with intel nuc connected to a arduino mega2560 board which then connect to the DSP controller to control the left and right wheels of a robot to move around.

I am trying to program a robot motor to run by sending command through the ros system. It then will translate the command to the arduino mega2560 board and then send signal to the controller.

The problem that i am facing lies with these 2 lines

ros::Subscriber std_msgs::Float32 lwheel_vtarget("lwheel_vtarget", lmotorCb);

ros::Subscriber std_msgs::Float32 rwheel_vtarget("rwheel_vtarget", rmotorCb);

and the error states that

invalid conversion from 'void (*)()' to 'ros::Subscriber<std_msgs::float32>::CallbackT {aka void ()(const std_msgs::Float32&)}' [-fpermissive] ros::Subscriber<std_msgs::float32> lwheel_vtarget("lwheel_vtarget", lmotorCb);

So i dont understand what the error is stating about and require some explanation from your expertise.

Please do state which info you guys need and i will provide it accordingly.

#include <ros.h> #include <std_msgs/Int32.h> #include <std_msgs/Int16.h> #include <std_msgs/Float32.h> #include <std_msgs/String.h>
 
/******/ /*  Variables setup   */ /******/
 
int interruptPin = 2; char bufferX[9]; char bufferY[9]; String str = ""; String str_ = ""; bool go = false; int R; int L; std_msgs::Int32 lwheel_msg; std_msgs::Int32 rwheel_msg; std_msgs::Float32 lmotor_msg; std_msgs::Float32 rmotor_msg;
 
/******/ /*  Subscribed Nodes    */ /*******/
 
ros::NodeHandle nh; ros::Publisher lwheel("lwheel", &lwheel_msg); ros::Publisher rwheel("rwheel", &rwheel_msg);
 
void lmotorCb(){
    Serial1.print("V21=");  // left wheel
    Serial1.println(L);
    Serial1.println("V31=1"); } void rmotorCb(){
    Serial1.print("V22="); // right wheel
    Serial1.println(R);
    Serial1.println("V31=1"); }
  
ros::Subscriber<std_msgs::Float32> lwheel_vtarget("lwheel_vtarget", lmotorCb);
  
ros::Subscriber<std_msgs::Float32> rwheel_vtarget("rwheel_vtarget", rmotorCb);
 
void setup() {  
  Serial.begin(115200);
  Serial1.begin(38400);
  pinMode(interruptPin, INPUT);  
  UCSR1C = (UCSR1C & 0xCF) | (0b11 << 4);  // Enable odd parity
 
  /******/
  /   ROS Node setup   */
  /******/
  
  nh.getHardware()->setBaud(115200);
  nh.initNode();
  nh.subscribe(lwheel_vtarget);
  nh.subscribe(rwheel_vtarget);
  nh.advertise(lwheel);
  nh.advertise(rwheel); }
 
void loop() {
  
  //Fetching encoder line
  Serial1.find('=');
 
  str = Serial1.readStringUntil(',');
  str_ = Serial1.readStringUntil('\n');
  
  strncpy(bufferX, str.c_str(), 9); //String to char
  rwheel_msg.data = (unsigned int)strtol(&bufferX[1], NULL, 16);
 
  strncpy(bufferY, str_.c_str(), 9); //String to char
  lwheel_msg.data = (unsigned int)strtol(&bufferY[1], NULL, 16);
  
  lwheel.publish(&lwheel_msg);
  nh.spinOnce();
  rwheel.publish(&rwheel_msg);
  nh.spinOnce();
  
  /***********/
  /* Tesiting routine (use when needed) */
  /***********/
  /*   Serial.print("Left wheel: ");   Serial.print(lwheel_msg.data);   Serial.print(" - Right wheel: ");   Serial.print(rwheel_msg.data);   Serial.print("\n");   /
  
}

2016-09-08 00:40:33 -0500 asked a question invalid conversion from void(*) to ros

Hi , i am new to ROS and arduino . i had some problems with my codes . Do you guys mind helping me take a look at my codes ?

#include <ros.h> #include <std_msgs/Int32.h> #include <std_msgs/Int16.h> #include <std_msgs/Float32.h> #include <std_msgs/String.h> /**********************/ /*  Variables setup   */ /**********************/ int interruptPin = 2; char bufferX[9]; char bufferY[9]; String str = ""; String str_ = ""; bool go = false; int R; int L; std_msgs::Int32 lwheel_msg; std_msgs::Int32 rwheel_msg; std_msgs::Float32 lmotor_msg; std_msgs::Float32 rmotor_msg; /***********************/ /*  Subscribed Nodes   */ /***********************/ ros::NodeHandle nh; ros::Publisher lwheel("lwheel", &lwheel_msg); ros::Publisher rwheel("rwheel", &rwheel_msg); void lmotorCb(){
    Serial1.print("V21=");
    Serial1.println(L);
    Serial1.println("V31=1"); } void rmotorCb(){
    Serial1.print("V22=");
    Serial1.println(R);
    Serial1.println("V31=1"); } ros::Subscriber<std_msgs::Float32> lwheel_vtarget("lwheel_vtarget", lmotorCb); ros::Subscriber<std_msgs::Float32> rwheel_vtarget("rwheel_vtarget", rmotorCb); void setup() {
  
  Serial.begin(115200);
  Serial1.begin(38400);
  pinMode(interruptPin, INPUT);
  
  UCSR1C = (UCSR1C & 0xCF) | (0b11 << 4);  // Enable odd parity

  /**********************/
  /*   ROS Node setup   */
  /**********************/
  
  nh.getHardware()->setBaud(115200);
  nh.initNode();
  nh.subscribe(lwheel_vtarget);
  nh.subscribe(rwheel_vtarget);
  nh.advertise(lwheel);
  nh.advertise(rwheel);
  
} void loop() {
  
  //Fetching encoder line
  Serial1.find('=');

  str = Serial1.readStringUntil(',');
  str_ = Serial1.readStringUntil('\n');
  
  strncpy(bufferX, str.c_str(), 9); //String to char
  rwheel_msg.data = (unsigned int)strtol(&bufferX[1], NULL, 16);

  strncpy(bufferY, str_.c_str(), 9); //String to char
  lwheel_msg.data = (unsigned int)strtol(&bufferY[1], NULL, 16);
  
  lwheel.publish(&lwheel_msg);
  nh.spinOnce();
  rwheel.publish(&rwheel_msg);
  nh.spinOnce();
  
  /**************************************/
  /* Tesiting routine (use when needed) */
  /**************************************/
  /*   Serial.print("Left wheel: ");   Serial.print(lwheel_msg.data);   Serial.print(" - Right wheel: ");   Serial.print(rwheel_msg.data);   Serial.print("\n");   */
  
} 

And this is the error shown

/tmp/arduino_modified_sketch_623299/AMC-8004.ino:52:77: warning: invalid conversion from 'void ()()' to 'ros::Subscriber<std_msgs::float32>::CallbackT {aka void ()(const std_msgs::Float32&)}' [-fpermissive] ros::Subscriber<std_msgs::float32> lwheel_vtarget("lwheel_vtarget", lmotorCb); ^