-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodom_tf.py
executable file
·61 lines (49 loc) · 1.95 KB
/
odom_tf.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
#!/usr/bin/env python3
#this is a simple program that subscribes to the odom topic and gets the position and orientation of the robot
import rospy
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
import math
import time
from std_srvs.srv import Empty
import tf
#callback function the odom pose (position+orientation) of the robot
def odomPoseCallback(odom_msg):
print ("odom pose callback")
#get the position of the robot
print ('x = ',odom_msg.pose.pose.position.x)
print ('y = ', odom_msg.pose.pose.position.y )
#get the velocity of the robot
print ('vx = ',odom_msg.twist.twist.linear.x)
print ('vz = ',odom_msg.twist.twist.angular.z)
#print the values of the orientation in quaternion
print ('qx=',odom_msg.pose.pose.orientation.x)
print ('qy=',odom_msg.pose.pose.orientation.y)
print ('qz=',odom_msg.pose.pose.orientation.z)
print ('qw=',odom_msg.pose.pose.orientation.w)
#formulate a quaternion as a list
quaternion = (
odom_msg.pose.pose.orientation.x,
odom_msg.pose.pose.orientation.y,
odom_msg.pose.pose.orientation.z,
odom_msg.pose.pose.orientation.w)
#convert the quaternion to roll-pitch-yaw
rpy = tf.transformations.euler_from_quaternion(quaternion)
#extract the values of roll, pitch and yaw from the array
roll = rpy[0]
pitch = rpy[1]
yaw = rpy[2]
#print the roll, pitch and yaw
print (math.degrees(roll), ' ', math.degrees(pitch), ' ', math.degrees(yaw))
print ('the orientation of the robot is: ',math.degrees(yaw))
if __name__ == '__main__':
try:
#init the node
rospy.init_node('turtlesim_motion_pose', anonymous=True)
#subscribe to the odom topic
position_topic = "/odom"
pose_subscriber = rospy.Subscriber(position_topic, Odometry, odomPoseCallback)
#spin
rospy.spin()
except rospy.ROSInterruptException:
rospy.loginfo("node terminated.")