ROS进二阶学习笔记(1) TF 学习笔记3 -- TF Listener 编写 (Python)and Adding frame(Python)

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
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值