0
$\begingroup$

Rosanswers logo

I am publishing markers in a subscriber callback so that whenever new data is received on a topic a marker is created. Markers are published and displayed well at first but after a while markers are slow to publish and therefore become spaced at greater and greater distances apart. Any idea how to solve this? To visualise I am using RViz and ros3djs.


Originally posted by Py on ROS Answers with karma: 501 on 2021-04-21

Post score: 1


Original comments

Comment by miura on 2021-04-21:
Can I use ros::Time to measure the time taken from the beginning to the end of a callback function? Also, do you know the interval between subscribing? (You can find it with rostopic hz /tf(?), I think. )

This is just a thought, but it may be that the time taken for the callback is longer than the interval to subscribe. Then gradually the buffer will fill up and topics will appear that are not stored in the buffer. That may be what is making the interval look large.

Comment by gvdhoorn on 2021-04-21:\

whenever new data is received on a topic a marker is created

Are markers also deleted?

Comment by Py on 2021-04-21:
Markers are not deleted. I'll measure the callback time tomorrow. For now, I've also seen this message in the terminal output which starts exactly when the lag begins: Could not find a connection between 'map' and 'odom' because they are not part of the same tree.Tf has two or more unconnected trees. This appears to be related to this function which is also called within my callback:

def get_map_pose(self, frame, required_position):
    tf_buffer = tf2_ros.Buffer()
    tf2_ros.TransformListener(tf_buffer)
    try:
        transform = tf_buffer.lookup_transform(frame, required_position, rospy.Time(0), rospy.Duration(1))
        self.map_pose.pose = tf2_geometry_msgs.do_transform_pose(self.odom_pose.pose, transform)
        self.map_pose.header.stamp = self.odom_pose.header.stamp
        return
    except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException) as error:

Comment by gvdhoorn on 2021-04-22:\

Markers are not deleted.

that's not necessarily a good idea. All physical systems have limits, and browsers are no exception.

re: your TF problem: you cannot create a TransformListener in a callback or function, there isn't sufficient time for the buffer to be filled with TF messages such that your lookups succeed.

This is a very well known anti-pattern.

Comment by Py on 2021-04-22:
OK thanks for the guidance. Are there any alternate approaches to getting the robot pose in the map frame within a callback? Also, I need markers to not be deleted for visualisation.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I'm not claiming you must absolutely delete markers. I just wanted to make you aware of a possible performance bottleneck.

Are there any alternate approaches to getting the robot pose in the map frame within a callback?

there is no need for an alternative, you just need to make sure you create your Buffer and TransformListener in a scope which stays around longer than your callback/function.


Originally posted by gvdhoorn with karma: 86574 on 2021-04-22

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Py on 2021-04-22:
Perfect! I move the tf_buffer and the TransformListener into my classes __init__ function and that solved it. No more lag! Thanks very much :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.