ROS进二阶学习笔记(1) TF 学习笔记3 -- TF Listener 编写 (Python)
Ref: http://wiki.ros.org/tf/Tutorials/Writing%20a%20tf%20listener%20%28Python%29
In the previous tutorials we created a tf broadcaster to publish the pose of a turtle to tf. In this tutorial we'll create a tf listener to start using tf. and use tf to get access to frame transformations.
还是要请先读了Ref 再来这里sonictl@csdn看总结:
- 这个listen的程序做了3件事情:
- 1. 放个 turtle2乌龟到舞台上去,用的turtlesim/Spawn服务;
- 2. 用tf.TransformListener类下的lookupTransform方法,查询turtle2 相对于 turtle1 的位置。
- 3. 用查到的相对位置来发布cmd速度和角速度信息,引导 turtle2 运动
看看代码
我小改了下代码: (path: nodes/learning_tf_listener.py )
#!/usr/bin/env python
import roslib
roslib.load_manifest('learning_tf')
import rospy
import math
import tf
import geometry_msgs.msg
import turtlesim.srv
if __name__ == '__main__':
rospy.init_node('tf_turtle')
#next three lines: Create another turtle onto the stage
rospy.wait_for_service('spawn')
spawner = rospy.ServiceProxy('spawn', turtlesim.srv.Spawn)
#turtlesim has a service named: Spawn
spawner(4, 4, 0, 'turtle2') #(x,y,theta,name)
#Publisher for the turtle2's movement
turtle_vel = rospy.Publisher('turtle2/cmd_vel', geometry_msgs.msg.Twist,queue_size=1)
listener = tf.TransformListener() #tf transforListener
rate = rospy.Rate(10.0)
while not rospy.is_shutdown():
#All this is wrapped in a try-except bl