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

creating Publishers or Subscribers in the bodies of callbacks

asked 2020-05-17 07:27:51 -0500

azerila gravatar image

updated 2020-05-17 07:28:59 -0500

following a comment in this question it seems that triggering to publish a topic inside callback of a subscriber may cause issues such as TCP/IP connection. Although I'm not sure if the comment in the above question means making a publisher insider a call back or triggering to publish inside a callback.

I have an application that has two topics which make a loop by triggering publishment in their subscriber callbacks. I have tried to control the frquency by rospy.sleep to 1 kHz, but my question is if there are other things I can do to make sure this process stays stable with no issues. And my other question is if this is in general a bad idea for having a setup like above, and what can go wrong in general.

edit retag flag offensive close merge delete

Comments

if there are other things I can do to make sure this process stays stable with no issues.

yes. Don't use Python for systems with determinism requirements.

gvdhoorn gravatar image gvdhoorn  ( 2020-05-17 08:18:44 -0500 )edit

There is a big difference between publishing to a topic in a callback as you state in the question and creating a publisher in a callback as you state in the question title. As noted on a different post of yours, posting code is encouraged. As it stands right now, I don't even know what your question is.

billy gravatar image billy  ( 2020-05-17 13:08:59 -0500 )edit

@billy it is a large code base, I can't put any fraction of it here that would make sense, and for this I tried to make my questions as general as possible dependent only on ros itself. The question is if in any ros application triggering a publisher to publish in a callback may cause any issue, and if there's a something one can do about it.

azerila gravatar image azerila  ( 2020-05-18 13:12:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-05-18 13:20:19 -0500

gvdhoorn gravatar image

updated 2020-05-18 13:20:35 -0500

following a comment in this question it seems that triggering to publish a topic inside callback of a subscriber may cause issues such as TCP/IP connection.

that's not what I meant by my comment in that post.

I asked whether the OP of #q327312 was creating ros::Publisher or ros::Subscriber instances in his callbacks. That is not the same as publishing a message. This is also what @billy mentions.

Publishing from a callback should be fine.

Creating any instances of entities with "long" running initialisations or which require time to gather sufficient buffer content will almost never work in callbacks (unless the callbacks themselves are long running, but callbacks typically should not be).

edit flag offensive delete link more

Comments

I see now, thanks for the clarification,

azerila gravatar image azerila  ( 2020-05-18 13:33:27 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-05-17 07:27:51 -0500

Seen: 208 times

Last updated: May 17 '20