publish_pose_teleop.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
6 from sensor_msgs.msg import Joy
7 from math import fabs
8 
9 lastData = None
10 
11 def joyChanged(data):
12  global lastData
13  lastData = data
14  # print(data)
15 
16 if __name__ == '__main__':
17  rospy.init_node('publish_pose', anonymous=True)
18  worldFrame = rospy.get_param("~worldFrame", "/world")
19  name = rospy.get_param("~name")
20  r = rospy.get_param("~rate")
21  joy_topic = rospy.get_param("~joy_topic", "joy")
22  x = rospy.get_param("~x")
23  y = rospy.get_param("~y")
24  z = rospy.get_param("~z")
25 
26  rate = rospy.Rate(r)
27 
28  msg = PoseStamped()
29  msg.header.seq = 0
30  msg.header.stamp = rospy.Time.now()
31  msg.header.frame_id = worldFrame
32  msg.pose.position.x = x
33  msg.pose.position.y = y
34  msg.pose.position.z = z
35  yaw = 0
36  quaternion = tf.transformations.quaternion_from_euler(0, 0, yaw)
37  msg.pose.orientation.x = quaternion[0]
38  msg.pose.orientation.y = quaternion[1]
39  msg.pose.orientation.z = quaternion[2]
40  msg.pose.orientation.w = quaternion[3]
41 
42  pub = rospy.Publisher(name, PoseStamped, queue_size=1)
43  rospy.Subscriber(joy_topic, Joy, joyChanged)
44 
45  while not rospy.is_shutdown():
46  global lastData
47  if lastData != None:
48  if fabs(lastData.axes[1]) > 0.1:
49  msg.pose.position.z += lastData.axes[1] / r / 2
50  if fabs(lastData.axes[4]) > 0.1:
51  msg.pose.position.x += lastData.axes[4] / r * 1
52  if fabs(lastData.axes[3]) > 0.1:
53  msg.pose.position.y += lastData.axes[3] / r * 1
54  if fabs(lastData.axes[0]) > 0.1:
55  yaw += lastData.axes[0] / r * 2
56  quaternion = tf.transformations.quaternion_from_euler(0, 0, yaw)
57  msg.pose.orientation.x = quaternion[0]
58  msg.pose.orientation.y = quaternion[1]
59  msg.pose.orientation.z = quaternion[2]
60  msg.pose.orientation.w = quaternion[3]
61  # print(pose)
62  msg.header.seq += 1
63  msg.header.stamp = rospy.Time.now()
64  pub.publish(msg)
65  rate.sleep()


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