Ask Your Question
0

Nodes asynchronously accessing messages/data

asked 2018-10-29 17:39:03 -0500

Geks gravatar image

I have a sensor which outputs data at a slow rate, I want to create another node which uses a nonblocking loop to access this data and either continues an action or changes actions based upon what it scans but I don't want the node to block and wait for the next sensor reading.

How do I do this in python and ROS? The rospy.waitformessage() function looks like it will block until the next message is published instead of accessing the most recent sensor scan - is this correct?

Should I make a subscriber node whose main spawns a separate thread? But then how do you transmit data between your callback function and that thread? I have seen people make a global variable which is used to transmit information between a subscriber and publisher which exist in a single node - is this the best way to do it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-29 20:14:01 -0500

ahendrix gravatar image

Yes; most code uses global variables, or creates a class to hold the callbacks and variables.

edit flag offensive delete link more

Comments

1

This might be something where message_filters/Cache could help.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-30 03:11:50 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-10-29 17:39:03 -0500

Seen: 126 times

Last updated: Oct 29 '18