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

How to remove lag in marker publishing?

asked 2021-04-21 07:53:33 -0500

Py gravatar image

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.

edit retag flag offensive close merge delete

Comments

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.

miura gravatar image miura  ( 2021-04-21 09:19:37 -0500 )edit

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

Are markers also deleted?

gvdhoorn gravatar image gvdhoorn  ( 2021-04-21 09:43:05 -0500 )edit

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:
Py gravatar image Py  ( 2021-04-21 15:19:30 -0500 )edit
1

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.

gvdhoorn gravatar image gvdhoorn  ( 2021-04-22 05:09:19 -0500 )edit

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.

Py gravatar image Py  ( 2021-04-22 06:52:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-22 07:59:49 -0500

gvdhoorn gravatar image

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.

edit flag offensive delete link more

Comments

Perfect! I move the tf_buffer and the TransformListener into my classes __init__ function and that solved it. No more lag! Thanks very much :)

Py gravatar image Py  ( 2021-04-22 10:30:51 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-04-21 07:53:33 -0500

Seen: 861 times

Last updated: Apr 21 '21