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

One time publish executable

asked 2017-06-22 08:48:24 -0500

andreasvo gravatar image

updated 2017-06-22 08:49:21 -0500


Im trying to use a specific node (program A) as a test program being executed once taking the value to be published on a topic (lets call it "foo").

Program B is already subscribed to this topic and is running in a loop.

Program A will be ran like this: "rosrun package node argument", and published the argument (a number) to topic "foo".

program B never receives this message. My idea at this point is the fact that they never get to pair up with tcp with the use of the master node since the subscribing node isnt really subscribed.

Is there any way of making this executable able to send to the looped node B? or is there a specific reason this doesnt work?

I know this might seem like a stupid idea, but it is necessary for testing of the robot, and I dont know how to pass values to a running node for it to then publish.

In advance, thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-06-22 09:19:04 -0500

NEngelhard gravatar image

You most probably terminate your program immediately after calling pub.publish(msg) so that the publisher has no time to actually send the message. Could you show your code? The hacky solution is to simply wait a bit after sending, you could also check if the other node is listening with pub.getNumSubscribers().

edit flag offensive delete link more


The code is large, this is the chain of events though:

  1. A topic holder node starts the topic and holds it alive.
  2. Subscriber node starts subscribes.
  3. Publisher node advertises every time it is launched and publishes to that topic.

The issue might be trying to publish from a second node?

andreasvo gravatar image andreasvo  ( 2017-06-22 11:11:32 -0500 )edit

pub.getNumSubscribers() gave 0.

andreasvo gravatar image andreasvo  ( 2017-06-22 11:11:53 -0500 )edit

answered 2017-06-22 11:40:07 -0500

andreasvo gravatar image

The problem is solved!

I realized the subscriber object might also have a sub.getNumPublishers(), this way I could check this each loop. Also to ensure this worked I let the publisher sleep 1 second after advertising, then 1 second after publishing.

This is probably a hacky solution but it is only for a test where I can force values on my autonomous robot in the command line on the fly.

Thanks for the tip NEngelhard, it led me towards my solution.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-06-22 08:48:24 -0500

Seen: 282 times

Last updated: Jun 22 '17