publish_external_position_vicon.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
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         # initialize kalman filter
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         # rospy.set_param("locSrv/extPosStdDev", 1e-4)
00022         update_params(["kalman/resetEstimation"]) #, "locSrv/extPosStdDev"])
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()


crazyflie_demo
Author(s): Wolfgang Hoenig
autogenerated on Wed Jun 12 2019 19:20:46