Converting Pose-stamped from one frame to another
Dear ROSers,
ROS_DISTRO: Melodic
OS: Ubuntu 18.04
I'm trying to, using tf
instead of tf2
(which I do not know yet) convert a PoseStamped
point from the world
frame to a moving child frame test_tf
.
The point is given in the RViz window with the Navgoal button, which publishes a PoseStamped
point to the relevant topic, in terms of the world
frame. I get the point through a subscriber but I try to convert it with listener.transformPose
, and it works at first, but I need to know it's relative position all the time, which does not get updated.
I output the X position relative to world
and to test_tf
and check it in rqt_console
but it does not update itself as the frame moves.
this is the Broadcaster (which makes the frame move in a sinusodial fashion):
def tf_pose(tf_name):
now = rospy.Time.now()
br.sendTransform((sin(now.secs), 0, 0),
tf.transformations.quaternion_from_euler(0, 0, 0),
now,
tf_name,
"world")
This is the listener
def handle_goal(goal):
global navpoint
rospy.loginfo("goal.x {}".format(goal.pose.position.x))
navpoint = goal
if __name__ == '__main__':
rospy.init_node('test_tf_listener')
listener = tf.TransformListener()
rospy.Subscriber('move_base_simple/goal',
PoseStamped,
handle_goal)
navpoint = None
rate = rospy.Rate(10.0)
listener.waitForTransform("/world", "/test_tf", rospy.Time(), rospy.Duration(4.0))
while not rospy.is_shutdown():
try:
(trans,rot) = listener.lookupTransform('/world', '/test_tf', rospy.Time(0))
if navpoint is None:
rospy.loginfo('navpoint is None')
else:
navpoint_loc = listener.transformPose('test_tf', navpoint)
rospy.loginfo('navpoint.x: {} -> navpoint_l.x: {}'.format(navpoint.pose.position.x,navpoint_loc.pose.position.x))
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
continue
rate.sleep()
The output I get from the rqt_console is:
navpoint.x: 0.0976972579956 -> navpoint_l.x: -0.889827448254
navpoint.x: 0.0976972579956 -> navpoint_l.x: -0.889827448254
navpoint.x: 0.0976972579956 -> navpoint_l.x: -0.889827448254
But I expect that the navpoint_l
which is the point location relative to the test_tf
should change as the frame moves.
I would like to know why it doesn't, and how can I access the most current available position of the point relative to the moving test_tf