Maybe you can unsubscribe from the topic after a 1-time call.
You can do so, by calling subscriber.unregister()
this function.
def cb_once(msg, subscriber):
#do processing here
subscriber.unregister()
sub_once = None
sub_once = rospy.Subscriber('my_topic,', MyType, cb_once, sub_once)
Or
--
Solution
not a ros node, can that be possibly the problem for endless waiting??
have you created rospy.init_node? If not, I think you cannot execute this line without initializing the node.
system_info = rospy.wait_for_message(topic_name, SystemState, timeout=5)
This syntax it looks correct.
Originally posted by Ranjit Kathiriya with karma: 1622 on 2021-12-03
This answer was ACCEPTED on the original site
Post score: 0
Original comments
Comment by bhomaidan on 2021-12-03:
@RanjitKathiriya There is no spinOnce
in rsopy
, and I have read that some users were able to use wait_for_message
instead, that's why I do like to use it if possible, but I'm not sure if I'm using it correctly.
Comment by Ranjit Kathiriya on 2021-12-03:\
I have read that some users were able to use wait_for_message instead, that's why I do like to use it if possible
I have checked your syntax it looks correct. If possible can you re-edit your question and share the full code file. That's why I was asking for a detailed error in your question comment.
Moreover, you also can use unregister()
this is also a good option to consider.
Comment by bhomaidan on 2021-12-03:
@RanjitKathiriya I'm using this line system_info = rospy.wait_for_message(topic_name, SystemState, timeout=5)
inside a normal function, and not a ros node, can that be possibly the problem for endless waiting??
Comment by Ranjit Kathiriya on 2021-12-03:\
not a ros node, can that be possibly the problem for endless waiting??
have you created rospy.init_node
? If not, I think you cannot execute this line without initializing the node.
system_info = rospy.wait_for_message(topic_name, SystemState, timeout=5)
This syntax it looks correct.
Comment by bhomaidan on 2021-12-03:
@RanjitKathiriya thanks, that solved my problem.
Comment by Ranjit Kathiriya on 2021-12-03:
Tick the answer, if you got your answer. That can help others.