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

Multiple Arguments of a subscriber ROS indigo, arduino, C++

asked 2016-05-16 13:18:05 -0600

Markus gravatar image

updated 2016-05-16 13:19:02 -0600

Hey I would like to control a adruino Board using rosserial. All works fine except when I would like to use a topic and give it two arguments I tired:

            //some code here
         void turn(const std_msgs::Bool& lr, const std_msgs::UInt16& angle){
           // some code here (I used here and at the right places
         //some code

         // now here I get my error: because I type in here 2 arguments:
          ros::Subscriber<std_msgs::Bool, std_msgs::UInt16> tur("Turn",turn);

        // setup(), loop() function etc. some other code

I already read e.g here: or here:

Now what I simply would like to do:

roscore, rosrun rosserial_python /dev/ttyACM0,
rostopic pub Turn std_msgs/Bool??? value1, value2

where value1 and value2 stands I just want to execute a topic with and give it two values instead of writing two seperate topics with only one argument.

I would be very happy if someone can write a little bit more detailed answer(more specific for my problem) than in the above links.

Thank you very much! :) Best Markus

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-05-16 15:48:53 -0600

NEngelhard gravatar image

You should create a custom message type that contains your two values as members: create ros msg

edit flag offensive delete link more


Thanks. I thought I could come around that. But according to ahendrix not when I want to use it on arduino.

Markus gravatar image Markus  ( 2016-05-17 02:38:48 -0600 )edit

answered 2016-05-16 14:04:00 -0600

ahendrix gravatar image

The arduino libraries for rosserial are significantly more limited than roscpp running on Linux. boost isn't available, so you can't use things like boost::bind to pass additional arguments to your subscriber.

It looks like you want to have two subscribers with different types, and you want you callback called when one or both of these subscribers gets new data. (The question you linked to is a different case; asking about using the same argument in a callback to process data from different subscribers).

On a Linux system, you can do something like what you're asking about with message_filters synchronizers, but that package doesn't exist for rosserial on arduino.

To be honest, I'm not sure that there's a way to do what you're asking on an Arduino. It's probably better to do the message synchronization on the PC side, publish the synchronized data on a single topic, and have the arduino subscribe to that topic.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-05-16 13:18:05 -0600

Seen: 461 times

Last updated: May 16 '16