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

Emiliano's profile - activity

2021-06-14 01:44:27 -0500 received badge  Favorite Question (source)
2021-05-31 15:29:39 -0500 received badge  Nice Question (source)
2021-01-05 16:54:37 -0500 received badge  Student (source)
2020-06-29 07:02:46 -0500 commented question Publisher or Subscriber inside a class [rosserial]

Would you create a new issue and point us there so we can give you precise feedback?

2020-06-29 07:02:37 -0500 commented question Publisher or Subscriber inside a class [rosserial]

Would you create a new issue and point us there so we can give you a precise feedback?

2017-04-22 08:58:54 -0500 received badge  Enthusiast
2017-04-16 17:54:42 -0500 commented answer Publisher or Subscriber inside a class [rosserial]

Thanks a lot!! This implementation saved me a lot of memory!

2017-04-09 20:50:51 -0500 received badge  Famous Question (source)
2017-04-09 08:52:43 -0500 answered a question Publisher or Subscriber inside a class [rosserial]

Error message shown by the Arduino IDE when compile the answer of DavidN:

Arduino: 1.6.12 (Linux), Board: "Arduino Leonardo"

In file included from /home/emiliano/catkin_ws/src/my_mobile_robot/from_keyboard_node-local_variables/from_keyboard_node-local_variables.ino:27:0:
DifferentialDriveRobot.h:45: error: invalid use of template-name 'ros::Subscriber' without an argument list
  ros::Subscriber sub;
  ^
sketch/DifferentialDriveRobot.h: In constructor 'DifferentialDriveRobot::DifferentialDriveRobot(DCMotor*, DCMotor*, double, double)':
DifferentialDriveRobot.h:67: error: 'sub' was not declared in this scope
  sub = nh.subscribe("/cmd_vel_mux/input/teleop", 1, &DifferentialDriveRobot::ddr_callback, this);
  ^
DifferentialDriveRobot.h:67: error: no matching function for call to 'ros::NodeHandle_<ArduinoHardware>::subscribe(const char [26], int, void (DifferentialDriveRobot::*)(const geometry_msgs::Twist&), DifferentialDriveRobot*)'
  sub = nh.subscribe("/cmd_vel_mux/input/teleop", 1, &DifferentialDriveRobot::ddr_callback, this);
                                                                                                ^
sketch/DifferentialDriveRobot.h:67:96: note: candidate is:
In file included from /home/emiliano/Arduino/libraries/ros_lib/ros.h:38:0,
                 from sketch/DifferentialDriveRobot.h:8,
                 from /home/emiliano/catkin_ws/src/my_mobile_robot/from_keyboard_node-local_variables/from_keyboard_node-local_variables.ino:27:
/home/emiliano/Arduino/libraries/ros_lib/ros/node_handle.h:352:12: note: template<class SubscriberT> bool ros::NodeHandle_<Hardware, MAX_SUBSCRIBERS, MAX_PUBLISHERS, INPUT_SIZE, OUTPUT_SIZE>::subscribe(SubscriberT&) [with SubscriberT = SubscriberT; Hardware = ArduinoHardware; int MAX_SUBSCRIBERS = 25; int MAX_PUBLISHERS = 25; int INPUT_SIZE = 512; int OUTPUT_SIZE = 512]
       bool subscribe(SubscriberT& s){
            ^
/home/emiliano/Arduino/libraries/ros_lib/ros/node_handle.h:352:12: note:   template argument deduction/substitution failed:
In file included from /home/emiliano/catkin_ws/src/my_mobile_robot/from_keyboard_node-local_variables/from_keyboard_node-local_variables.ino:27:0:
sketch/DifferentialDriveRobot.h:67:96: note:   candidate expects 1 argument, 4 provided
  sub = nh.subscribe("/cmd_vel_mux/input/teleop", 1, &DifferentialDriveRobot::ddr_callback, this);
                                                                                                ^
exit status 1
invalid use of template-name 'ros::Subscriber' without an argument list
2017-04-09 08:52:36 -0500 commented answer Publisher or Subscriber inside a class [rosserial]

I put the error message in another answer because of the restrictions of this comment text.

2017-04-06 19:40:06 -0500 commented answer Publisher or Subscriber inside a class [rosserial]

I got some errors:

First, the sub declaration must have a <geometry_msgs::Twist>.

Second, I got the error: no matching function for call to 'ros::Subscriber<geometry_msgs::twist>::Subscriber()'. I think it's because there is only 1 constructor in subscriber.h (in arduino ros_lib package).

2017-04-06 19:23:33 -0500 received badge  Scholar (source)
2017-04-05 05:01:53 -0500 received badge  Notable Question (source)
2017-03-30 21:16:35 -0500 commented answer Publisher or Subscriber inside a class [rosserial]

I want to do an implementation like this example, but using rosserial.

2017-03-30 21:13:31 -0500 received badge  Popular Question (source)
2017-03-30 10:52:11 -0500 asked a question Publisher or Subscriber inside a class [rosserial]

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<geometry_msgs::Twist> 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<geometry_msgs::twist>::Subscriber()'

note: candidate expects 3 arguments, 0 provided

error: no match for call to '(ros::Subscriber<geometry_msgs::twist>) (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<geometry_msgs::Twist> 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!


Update

Error message shown by the Arduino IDE when compile the answer of @DavidN:

Arduino: 1.6.12 (Linux), Board: "Arduino Leonardo"

In file included from /home/emiliano/catkin_ws/src/my_mobile_robot/from_keyboard_node-local_variables/from_keyboard_node-local_variables.ino:27:0:
DifferentialDriveRobot.h:45: error: invalid use of template-name 'ros::Subscriber' without an argument list
  ros::Subscriber sub;
  ^
sketch/DifferentialDriveRobot.h: In constructor 'DifferentialDriveRobot::DifferentialDriveRobot(DCMotor*, DCMotor*, double, double)':
DifferentialDriveRobot.h:67: error: 'sub' was not declared in this scope
  sub = nh.subscribe("/cmd_vel_mux/input/teleop", 1, &DifferentialDriveRobot::ddr_callback, this);
  ^
DifferentialDriveRobot.h:67: error: no matching function for call to 'ros::NodeHandle_<ArduinoHardware>::subscribe(const char [26], int, void (DifferentialDriveRobot::*)(const geometry_msgs::Twist&), DifferentialDriveRobot*)'
  sub = nh.subscribe("/cmd_vel_mux/input/teleop", 1, &DifferentialDriveRobot::ddr_callback, this);
                                                                                                ^
sketch/DifferentialDriveRobot.h:67:96: note: candidate is:
In file included from /home/emiliano/Arduino/libraries/ros_lib/ros.h:38:0,
                 from sketch/DifferentialDriveRobot.h:8,
                 from /home/emiliano/catkin_ws/src/my_mobile_robot/from_keyboard_node-local_variables/from_keyboard_node-local_variables.ino:27:
/home/emiliano/Arduino/libraries/ros_lib/ros/node_handle.h:352:12: note: template<class SubscriberT> bool ros::NodeHandle_<Hardware, MAX_SUBSCRIBERS, MAX_PUBLISHERS, INPUT_SIZE, OUTPUT_SIZE>::subscribe(SubscriberT&) [with SubscriberT = SubscriberT; Hardware = ArduinoHardware; int MAX_SUBSCRIBERS = 25; int MAX_PUBLISHERS = 25; int INPUT_SIZE = 512; int OUTPUT_SIZE = 512]
       bool subscribe(SubscriberT& s){
            ^
/home/emiliano/Arduino/libraries/ros_lib/ros/node_handle.h:352:12: note:   template argument deduction/substitution failed:
In file included from /home/emiliano/catkin_ws/src/my_mobile_robot/from_keyboard_node-local_variables/from_keyboard_node-local_variables.ino:27:0:
sketch/DifferentialDriveRobot.h:67:96: note:   candidate expects 1 argument, 4 provided
  sub = nh.subscribe("/cmd_vel_mux/input/teleop", 1, &DifferentialDriveRobot::ddr_callback, this);
                                                                                                ^
exit status 1
invalid use of template-name 'ros::Subscriber' without an argument list
2016-11-14 08:56:19 -0500 received badge  Supporter (source)