Combination of timer and subscriber

asked 2022-11-15 21:07:32 -0500

nemunatu gravatar image

updated 2022-11-15 21:51:12 -0500

ravijoshi gravatar image

Hello, I am currently struggling to write a node for synchronous processing while subscribing to a topic.

Specifically,

  • There is a topic that is published at 100~150 Hz.
  • Then I have a synchronization process that I want to do at 2 ms (500 Hz).
  • The node subscribes to the topic and updates its values, but if the topic cannot be subscribed to in 2 ms (500 Hz), it performs the calculation by referring to the data of the last topic it subscribed to.

I tried to write a node to accomplish this requirement, but ros::subscriber cannot perform the 2 ms (500 Hz) synchronization process because the process stops until the topic is subscribed.

Is there any solution?

edit retag flag offensive close merge delete

Comments

It would be nice to share a minimal reproducible example

ravijoshi gravatar image ravijoshi  ( 2022-11-15 21:49:41 -0500 )edit

@nemunatu you need to spend more time studying how publish/subscribe systems work. You subscribe once when the app starts, and then after that ros will call a function that you specified for each message that arrives. Setting up a subscribe does take some time, but once it is set up it runs very quick.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-11-16 19:46:45 -0500 )edit