-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathodom_rot.py
executable file
·63 lines (50 loc) · 1.57 KB
/
odom_rot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
"""
This script broadcasts a tf frame called odom_rot that spins about the z axis
at a slow rate but also allows its yaw to be set at the command line.
The yaw is listed on the command line in radians.
"""
# Copyright (c) 2016, Fetch Robotics Inc.
# Author: Griswald Brooks
import rospy
import tf
import threading
class OdomTransform(object):
def __init__(self):
self.x = 1
self.y = 0
self.z = 0
self.roll = 0
self.pitch = 0
self.yaw = 0
def updateTransform(odom_transform):
while not rospy.is_shutdown():
new_yaw = raw_input("Enter new yaw[" + str(odom_transform.yaw) + "]: ")
try:
odom_transform.yaw = float(new_yaw)
except ValueError:
pass
def main():
# Create a node.
rospy.init_node("odom_rot")
# Create transform object
odom_rot = OdomTransform()
# Launch keyboard thread.
kb_th = threading.Thread(target=updateTransform, args=(odom_rot,))
kb_th.daemon = True
kb_th.start()
# Setup broadcast rate.
r = rospy.Rate(100)
# Broadcast odom_rot
br = tf.TransformBroadcaster()
while not rospy.is_shutdown():
br.sendTransform((odom_rot.x, odom_rot.y, odom_rot.z),
tf.transformations.quaternion_from_euler(odom_rot.roll, odom_rot.pitch, odom_rot.yaw),
rospy.Time.now(),
"odom_rot",
"odom")
# Increment yaw
odom_rot.yaw += 0.0001
r.sleep()
if __name__ == "__main__":
main()