robot_leader.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # coding=utf-8
00003 
00004 __author__ = 'Minglong Li'
00005 
00006 import rospy
00007 
00008 import tf
00009 import math
00010 
00011 import geometry_msgs.msg
00012 from nav_msgs.msg import Odometry
00013 
00014 class Robot_leader(object):
00015     def __init__(self, name):
00016         self.robotname = rospy.get_param("~robot")
00017         self.br = tf.TransformBroadcaster()
00018         self.sub = rospy.Subscriber('/%s/base_pose_ground_truth' % self.robotname,
00019                                     Odometry,
00020                                     self.handle_robot_pose, 
00021                                     self.robotname)
00022                       
00023     def handle_robot_pose(self, msg, robotname):
00024         x = msg.pose.pose.orientation.x
00025         y = msg.pose.pose.orientation.y
00026         z = msg.pose.pose.orientation.z
00027         w = msg.pose.pose.orientation.w 
00028         yaw =  math.atan2(2*(w*z+x*y), 1-2*(y**2+z**2))
00029         if yaw > -1 * math.pi and yaw < 0:
00030             yaw = 2 * math.pi + yaw
00031         print "yaw: %f" %(yaw)
00032         self.br.sendTransform((msg.pose.pose.position.x, msg.pose.pose.position.y, 0),
00033                                tf.transformations.quaternion_from_euler(0, 0, yaw),
00034                                rospy.Time.now(),
00035                                self.robotname,
00036                                "map")#TODO:msg.theta
00037     
00038 if __name__ == '__main__':
00039     rospy.init_node('robot_leader')
00040     robot_leader = Robot_leader(rospy.get_name())
00041     rospy.spin()
00042 


micros_mars_task_alloc
Author(s): Minglong Li , Xiaodong Yi , Yanzhen Wang , Zhongxuan Cai
autogenerated on Mon Jul 1 2019 19:55:03