5 from geometry_msgs.msg
import PoseStamped
6 from sensor_msgs.msg
import Joy
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")
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
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]
42 pub = rospy.Publisher(name, PoseStamped, queue_size=1)
43 rospy.Subscriber(joy_topic, Joy, joyChanged)
45 while not rospy.is_shutdown():
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]
63 msg.header.stamp = rospy.Time.now()