The comment that you need to publish the transform the other way is incorrect.
Only one of these should be used:
They will fight with each other and cause continuous reparenting such that at any given time the last one recieved will win. Likely the first version tested caused a disconnected tree by inadvertent reparenting and adding the second call masked it out.
And while I'm looking at this code. It's cleaner and more efficient to publish a vector of static transforms to take advantage of latching rather than publishing a sequence of individual transforms.
We brought this up here before: https://github.com/mavlink/mavros/pull/1252#issuecomment-503084522
@TSC21 FYI
@jkflying @baumanta Can you guys try to test if the timestamp issue exists with the duplicate publisher removed?
@tfoote you were right with your you comment on issue #388 . The tf loop in mavros seems to be responsible for getting always the tf at ros::Time::now().
I put a tf listener in the avoidance code which retrieved the transforms at the timestamp of the last pointcloud and at ros::Time::now() and printed both transforms. As the drone was moving I would expect the transforms to be slightly different. Using Mavros 0.29.2. both transforms were always identical even thought the timestamps were not. Using Mavros PR #1252 the transforms were different.
OK, I suspect why the odom
plugin code wasn't working is due to an obscure limitation of latched topics - you cannot publish different messages to a latched topic from the same process.
See https://github.com/ros/ros_comm/issues/146 and https://answers.ros.org/question/261815/how-can-i-access-all-static-tf2-transforms/.
The workaround for this is to construct a vector of all the transforms and publish them in one shot (pass to specialized TF2 function http://docs.ros.org/melodic/api/tf2_ros/html/c++/classtf2__ros_1_1StaticTransformBroadcaster.html#a83d0664cb0cc85688b60a2236e9d81ff)