0
$\begingroup$

Rosanswers logo

Hey,

So I'm attempting to connect to multiple nodes through rosserial over bluetooth, but the connections are very inconsistent. Each node should subscribe to three topics, but a lot of the time, one or two of these subscriptions fail, and I have to re-try the connection.

It should look something like this, with three subscriptions set up:

[INFO] [WallTime: 1355082105.350746] ROS Serial Python Node
[INFO] [WallTime: 1355082105.364278] Connected on /dev/rfcomm2 at 57600 baud
[INFO] [WallTime: 1355082109.857011] Note: subscribe buffer size is 280 bytes
[INFO] [WallTime: 1355082109.857714] Setup subscriber on PS3_Status_1 [std_msgs/Int32MultiArray]
[INFO] [WallTime: 1355082109.867275] Setup subscriber on redBLANK [std_msgs/Int32MultiArray]
[INFO] [WallTime: 1355082109.883375] Setup subscriber on toArduinoLeadRED [std_msgs/Int32MultiArray]

But will typically look like this, with one or two missing:

[INFO] [WallTime: 1355082105.350746] ROS Serial Python Node
[INFO] [WallTime: 1355082105.364278] Connected on /dev/rfcomm2 at 57600 baud
[INFO] [WallTime: 1355082109.857011] Note: subscribe buffer size is 280 bytes
[INFO] [WallTime: 1355082109.857714] Setup subscriber on PS3_Status_1 [std_msgs/Int32MultiArray]
[INFO] [WallTime: 1355082109.867275] Setup subscriber on redBLANK [std_msgs/Int32MultiArray]
[INFO] [WallTime: 1355082109.883375] Packet Failed :  Failed to read msg data

Is there any way that I can make the node keep attempting to subscribe before running the code? Or is there a better way to make sure all of these subscriptions are properly connected? It's kind of annoying to have to turn everything off and reset everything if the subscription fails.

The nodes are arduinos, and the set up code is standard:

void messageCont( const std_msgs::Int32MultiArray& x);
void AIStates( const std_msgs::Int32MultiArray& x);
void leadUpdate( const std_msgs::Int32MultiArray& x);
.
.
.
char controlSUB[13] = "PS3_Status_1";
char aiSUB[9] = "redWHITE";
char leadSUB[17] = "toArduinoLeadRED";
.
.
.
ros::NodeHandle nh;
ros::Subscriber<std_msgs::Int32MultiArray> subControl(controlSUB, &messageCont );
ros::Subscriber<std_msgs::Int32MultiArray> subAI(aiSUB, &AIStates );
ros::Subscriber<std_msgs::Int32MultiArray> subLeader(leadSUB, &leadUpdate );

void setup(){
.
.
. 
   nh.initNode();
   nh.subscribe(subControl);
   nh.subscribe(subAI);
   nh.subscribe(subLeader);   
}
.
.
.

Thanks!

EDIT: After looking at the link posted by PerkinsJames, I think those are for the 'regular' ros subscriptions, and not the ones that arduino uses.

I think the functions that I need are the ones from rosserial_arduino (someone let me know if I am wrong): http://ftp.isr.ist.utl.pt/pub/roswiki/doc/diamondback/api/rosserial_arduino/html/libraries_2ros__lib_2ros__lib_8cpp_source.html

It would seem that the subscribe function gives a boolean value, but it only affirms that the subscription has been added to the array, and not if it has been connected (Line 105)

bool ros::NodeHandle::subscribe(Subscriber & s)
{
   int i;
   for(i = 0; i < MAX_SUBSCRIBERS; i++)
   {
     if(subscribers[i] == 0) // empty slot
     {
       subscribers[i] = &s;
       s.id_ = i+100;
       s.nh_ = this;
       return true;
     }
   }
   return false;
 }

So the questions now are:

  1. Is there any way to affirm the rosserial_arduino subscriptions are actually connecting? From looking at this file, I can't really see any. There aren't any functions that seem to do that.
  2. Is there a way to use the 'regular', 'non-arduino' subscribers and nodehandles to be able to use functions like getNumPublishers()? (Perhaps this is a way to check connections?)

Thanks!

EDIT 2:

It seems that the answer to #2 is No. As per another post. (http://answers.ros.org/question/50466/use-regular-ros-subscriptions-on-arduino-not-rosserial_arduino/)

I'm wondering if there's still any way at all to check whether or not the arduino itself is successfully subscribing? I'm trying to look at some of the python code, but I don't really understand how I would make it check and re-try initializing the specific subscribers?

Any help is appreciated! Thanks!


Originally posted by sgwhack on ROS Answers with karma: 73 on 2012-12-09

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Can you just use the information here?

http://www.ros.org/doc/api/roscpp/html/classros_1_1NodeHandle.html

If you go to your proper subscribe function you are using, it actually throws two exceptions:

InvalidNameException & ConflictingSubscriptionException

and can check your "handle."


Originally posted by PerkinsJames with karma: 506 on 2012-12-11

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by sgwhack on 2012-12-11:
which part is the 'handle'? I'm not sure what to put in there

Comment by PerkinsJames on 2012-12-12:
Looking other subscribe functions on that page there is a part that shows this: ros::Subscriber sub = handle.subscribe("my_topic", 1, callback) and then gives an example of it in an if(handle). It comes from the statement ros::NodeHandle handle that you have to create before you make subscribers.

Comment by sgwhack on 2012-12-12:
how does that distinguish the success of each individual subscription? if I use "if(handle{...}", and use nh as my handle, am I to assume that as long as one subscription fails, the if statement will detect this?

Comment by PerkinsJames on 2012-12-13:
good point. Check this previous post too for checking number of publishers that I had in the past: http://answers.ros.org/question/46116/determine-if-another-rosnode-is-subscribing-to-published-topic/ . Maybe there is something equivalent for a subscriber?

Comment by sgwhack on 2012-12-13:
I did want to use getNumPublishers(), from the subscription on the arduino side.

However, i'm not so sure if this option is available for the arduino version of the subscriber. If i do the check on the publisher side, i dont see how i can tell the arduino to try to re-subscribe if it fails

$\endgroup$
0
$\begingroup$

Rosanswers logo

have you tried roswtf to see if there are any errors when everything is running?


Originally posted by Kevin with karma: 2962 on 2012-12-11

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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