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

Can I subscribe a new topic in a subscribe callback?

asked 2021-03-24 05:13:13 -0500

victorvl998 gravatar image

updated 2021-03-24 08:21:05 -0500

Hi everyone,

Problem description:

I have a system and use a Realsense Camera to generate point clouds. But I found that the actual point clouds output is at a relatively high frequency (60hz). One thing I concern about is if point cloud2 message at high frequency would cost much memory and affect ros performance on Jeston Nano. Besides, what I want to do is to sample this point clouds message every time it travels 1m.


I am planning to create a node that subscribes to and sample a topic (i.e point cloud) every time the agent travels 1m.

Because my point cloud topic is continuous, my idea is to subscribe and publish the point cloud in an odometry callback where I can see if the agent travels 1m.

I wonder if it is achievable in ros or if there is any better idea.

Thank you

edit retag flag offensive close merge delete

Comments

Do you want to publish a message every N metres, or do you want to receive a message every N metres?

Please describe that clearly so we can avoid an xy-problem.

gvdhoorn gravatar image gvdhoorn  ( 2021-03-24 07:56:09 -0500 )edit

Hi @gvhoorn, thank you for your response. I have updated the problem description and hope it would be clear to you

victorvl998 gravatar image victorvl998  ( 2021-03-24 08:23:46 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-03-24 10:22:35 -0500

gvdhoorn gravatar image

Although creating and destroying a subscription at runtime -- as @miura suggests -- is certainly possible, I would probably suggest to use ros::topic::waitForMessage(..) instead.

See #q270298 for an earlier Q&A about it, with an example and a link to the API documentation.

(and see #q240768 for a similar question or perhaps even a duplicate of yours, although it's about time, not distance)

edit flag offensive delete link more
0

answered 2021-03-24 09:39:25 -0500

miura gravatar image

I don't know how to publish every 1 meter, but I will suggest two approaches that might be useful. ( If there is a way to control the publishing interval, I'd like to know too! )

1. subscribe every 1m

  1. create a point cloud subscriber for every 1m
  2. shutdown the subscriber in the point cloud when the point cloud callback is received.

Although there is a load to keep publishing realsense, I should be able to reduce the frequency of callback processing to almost every 1m.

ref shutdown method: http://docs.ros.org/en/melodic/api/ro...

2. Change the period

You may be able to drop the publishing cycle of the point cloud from 60hz. In the case of camera images, I was able to drop it to 6hz by updating the fps parameter such as color_fps.

https://github.com/IntelRealSense/rea...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-03-24 05:13:13 -0500

Seen: 167 times

Last updated: Mar 24 '21