publish_external_pose_vicon.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import tf
5 from geometry_msgs.msg import PoseStamped, TransformStamped
6 from crazyflie_driver.srv import UpdateParams, Takeoff, Land
7 
8 def onNewTransform(transform):
9  global msg
10  global pub
11  global firstTransform
12 
13  if firstTransform:
14  # initialize kalman filter
15  rospy.set_param("kalman/initialX", transform.transform.translation.x)
16  rospy.set_param("kalman/initialY", transform.transform.translation.y)
17  rospy.set_param("kalman/initialZ", transform.transform.translation.z)
18  update_params(["kalman/initialX", "kalman/initialY", "kalman/initialZ"])
19 
20  rospy.set_param("kalman/resetEstimation", 1)
21  # rospy.set_param("locSrv/extPosStdDev", 1e-4)
22  update_params(["kalman/resetEstimation"]) #, "locSrv/extPosStdDev"])
23  firstTransform = False
24  else:
25  msg.header.frame_id = transform.header.frame_id
26  msg.header.stamp = transform.header.stamp
27  msg.header.seq += 1
28  msg.pose.position.x = transform.transform.translation.x
29  msg.pose.position.y = transform.transform.translation.y
30  msg.pose.position.z = transform.transform.translation.z
31  msg.pose.orientation.x = transform.rotation.x
32  msg.pose.orientation.y = transform.rotation.y
33  msg.pose.orientation.z = transform.rotation.z
34  msg.pose.orientation.w = transform.rotation.w
35  pub.publish(msg)
36 
37 
38 if __name__ == '__main__':
39  rospy.init_node('publish_external_position_vicon', anonymous=True)
40  topic = rospy.get_param("~topic", "/vicon/cf/cf")
41 
42  rospy.wait_for_service('update_params')
43  rospy.loginfo("found update_params service")
44  update_params = rospy.ServiceProxy('update_params', UpdateParams)
45 
46  firstTransform = True
47 
48  msg = PoseStamped()
49  msg.header.seq = 0
50  msg.header.stamp = rospy.Time.now()
51 
52  pub = rospy.Publisher("external_pose", PoseStamped, queue_size=1)
53  rospy.Subscriber(topic, TransformStamped, onNewTransform)
54 
55  rospy.spin()


crazyflie_demo
Author(s): Wolfgang Hoenig
autogenerated on Mon Sep 28 2020 03:40:12