ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
It looks like you're creating the transform publisher and then immediately trying to use it. The trouble with this is that, ROS subscribers take some time to subscribe to a topic after a new publisher comes online, and usually miss the first message on a topic - your delay is compensating for this a bit.
The other problem you're having is that you're only publishing once, and then destrying the publisher when you're done - any nodes that aren't running and subscribed to tf when you publish won't receive the transform.
You've also ignoring the time component of the transforms - tf is designed to handle time-varying transformations, and all frames should be published continuously in order to keep them up to date.
The more standard way to use tf is to set up a persistent tf publisher object, either as a class member variable or a global variable, and then publish transforms at a fixed rate - usually between 10 and 100Hz.
There are a couple of ways you could hide these complexities from your students: