Position.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import tf
5 from crazyflie_driver.msg import Position
6 from std_msgs.msg import Empty
7 from crazyflie_driver.srv import UpdateParams
8 
9 if __name__ == '__main__':
10  rospy.init_node('position', anonymous=True)
11  worldFrame = rospy.get_param("~worldFrame", "/world")
12 
13  rate = rospy.Rate(10) # 10 hz
14  name = "cmd_position"
15 
16  msg = Position()
17  msg.header.seq = 0
18  msg.header.stamp = rospy.Time.now()
19  msg.header.frame_id = worldFrame
20  msg.x = 0.0
21  msg.y = 0.0
22  msg.z = 0.0
23  msg.yaw = 0.0
24 
25  pub = rospy.Publisher(name, Position, queue_size=1)
26 
27  stop_pub = rospy.Publisher("cmd_stop", Empty, queue_size=1)
28  stop_msg = Empty()
29 
30  rospy.wait_for_service('update_params')
31  rospy.loginfo("found update_params service")
32  update_params = rospy.ServiceProxy('update_params', UpdateParams)
33 
34  rospy.set_param("kalman/resetEstimation", 1)
35  update_params(["kalman/resetEstimation"])
36  rospy.sleep(0.1)
37  rospy.set_param("kalman/resetEstimation", 0)
38  update_params(["kalman/resetEstimation"])
39  rospy.sleep(0.5)
40 
41  # take off
42  while not rospy.is_shutdown():
43  for y in range(10):
44  msg.x = 0.0
45  msg.y = 0.0
46  msg.yaw = 0.0
47  msg.z = y / 25.0
48  now = rospy.get_time()
49  msg.header.seq += 1
50  msg.header.stamp = rospy.Time.now()
51  rospy.loginfo("sending...")
52  rospy.loginfo(msg.x)
53  rospy.loginfo(msg.y)
54  rospy.loginfo(msg.z)
55  rospy.loginfo(msg.yaw)
56  # rospy.loginfo(now)
57  pub.publish(msg)
58  rate.sleep()
59  for y in range(20):
60  msg.x = 0.0
61  msg.y = 0.0
62  msg.yaw = 0.0
63  msg.z = 0.4
64  msg.header.seq += 1
65  msg.header.stamp = rospy.Time.now()
66  rospy.loginfo("sending...")
67  rospy.loginfo(msg.x)
68  rospy.loginfo(msg.y)
69  rospy.loginfo(msg.z)
70  rospy.loginfo(msg.yaw)
71  # rospy.loginfo(now)
72  pub.publish(msg)
73  rate.sleep()
74  break
75 
76  # go to x: 0.2 y: 0.2
77  start = rospy.get_time()
78  while not rospy.is_shutdown():
79  msg.x = 0.2
80  msg.y = 0.2
81  msg.yaw = 0.0
82  msg.z = 0.4
83  now = rospy.get_time()
84  if (now - start > 3.0):
85  break
86  msg.header.seq += 1
87  msg.header.stamp = rospy.Time.now()
88  rospy.loginfo("sending...")
89  rospy.loginfo(msg.x)
90  rospy.loginfo(msg.y)
91  rospy.loginfo(msg.z)
92  rospy.loginfo(msg.yaw)
93  pub.publish(msg)
94  rate.sleep()
95 
96  # land, spend 1 secs
97  start = rospy.get_time()
98  while not rospy.is_shutdown():
99  msg.x = 0.0
100  msg.y = 0.0
101  msg.z = 0.0
102  msg.yaw = 0.0
103  now = rospy.get_time()
104  if (now - start > 1.0):
105  break
106  msg.header.seq += 1
107  msg.header.stamp = rospy.Time.now()
108  rospy.loginfo("sending...")
109  rospy.loginfo(msg.x)
110  rospy.loginfo(msg.y)
111  rospy.loginfo(msg.z)
112  rospy.loginfo(msg.yaw)
113  pub.publish(msg)
114  rate.sleep()
115 
116  stop_pub.publish(stop_msg)
update_params
Definition: Position.py:32


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