Go to the documentation of this file.00001
00002
00003 import rospy
00004 import tf
00005 from geometry_msgs.msg import PointStamped, TransformStamped
00006 from crazyflie_driver.srv import UpdateParams, Takeoff, Land
00007
00008 def onNewTransform(transform):
00009 global msg
00010 global pub
00011 global firstTransform
00012
00013 if firstTransform:
00014
00015 rospy.set_param("kalman/initialX", transform.transform.translation.x)
00016 rospy.set_param("kalman/initialY", transform.transform.translation.y)
00017 rospy.set_param("kalman/initialZ", transform.transform.translation.z)
00018 update_params(["kalman/initialX", "kalman/initialY", "kalman/initialZ"])
00019
00020 rospy.set_param("kalman/resetEstimation", 1)
00021
00022 update_params(["kalman/resetEstimation"])
00023 firstTransform = False
00024 else:
00025 msg.header.frame_id = transform.header.frame_id
00026 msg.header.stamp = transform.header.stamp
00027 msg.header.seq += 1
00028 msg.point.x = transform.transform.translation.x
00029 msg.point.y = transform.transform.translation.y
00030 msg.point.z = transform.transform.translation.z
00031 pub.publish(msg)
00032
00033
00034 if __name__ == '__main__':
00035 rospy.init_node('publish_external_position_vicon', anonymous=True)
00036 topic = rospy.get_param("~topic", "/vicon/cf/cf")
00037
00038 rospy.wait_for_service('update_params')
00039 rospy.loginfo("found update_params service")
00040 update_params = rospy.ServiceProxy('update_params', UpdateParams)
00041
00042 firstTransform = True
00043
00044 msg = PointStamped()
00045 msg.header.seq = 0
00046 msg.header.stamp = rospy.Time.now()
00047
00048 pub = rospy.Publisher("external_position", PointStamped, queue_size=1)
00049 rospy.Subscriber(topic, TransformStamped, onNewTransform)
00050
00051 rospy.spin()