Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 314

Publisher or Subscriber inside a class [rosserial]

$
0
0
Hi, I'm using rosserial in Arduino and have a problem initializing the Publisher or Subscriber inside the class constructor: void setup() { DifferentialDriveRobot *my_robot = new DifferentialDriveRobot( ); } void loop() { ... } And the class is implemented as (in this example, with a subscriber): class DifferentialDriveRobot { ... public: ros::NodeHandle nh; ros::Subscriber sub; ... void ddr_callback(const geometry_msgs::Twist& msg) {...} DifferentialDriveRobot() { // Constructor nh.initNode() sub("/cmd_vel_mux/input/teleop", ddr_callback); nh.subscribe(sub); } }; And the compiling errors are the following: **error: no matching function for call to 'ros::Subscriber::Subscriber()'** **note: candidate expects 3 arguments, 0 provided** **error: no match for call to '(ros::Subscriber) (const char [26], void (&)(const geometry_msgs::Twist&))'** **sub("/cmd_vel_mux/input/teleop", ddr_callback);** I think that this is because of the initialization of the `sub` variable without any parameter. Should I declare it as a pointer? **NOTE:** If I declare the `ros::NodeHandle nh` and `ros::Subscriber sub("/cmd_vel_mux/input/teleop", ddr_callback)` in the main loop as global variables, the code works fine. I'm not very familiarized using templates, so I don't know exactly if exists an good implementation for this problem in the ros_lib library. Thanks for your help!

Viewing all articles
Browse latest Browse all 314

Trending Articles