4 import roslib; roslib.load_manifest(
'xbot_node')
7 from tf.transformations
import euler_from_quaternion
8 from math
import degrees
10 from nav_msgs.msg
import Odometry
11 from geometry_msgs.msg
import Quaternion
12 from geometry_msgs.msg
import Pose2D
16 rospy.init_node(
"getOdom2D", anonymous=
True)
18 self.
pub = rospy.Publisher(
"pose2d", Pose2D, queue_size=10)
21 px = data.pose.pose.position.x
22 py = data.pose.pose.position.y
23 quat = data.pose.pose.orientation
24 q = [quat.x, quat.y, quat.z, quat.w]
25 roll, pitch, yaw = euler_from_quaternion(q)
27 vx = data.twist.twist.linear.x
28 vy = data.twist.twist.linear.y
29 yaw_rate = data.twist.twist.angular.z
30 print "pose: x: {0:+2.5f}".format(px) +
", y: {0:+2.5f}".format(py)\
31 +
", th: {0:+.4f}".format(yaw) +
" rad; "\
32 +
"{0:+.2f}".format(degrees(yaw)) +
" deg" 33 print "rate: x: {0:+2.5f}".format(vx) +
", y: {0:+2.5f}".format(vy)\
34 +
", th: {0:+.2f}".format(yaw_rate) +
" rad/s; "\
35 +
"{0:+.2f}".format(degrees(yaw_rate)) +
" deg/s" 41 self.pub.publish(pose2d)
43 if __name__ ==
'__main__':
47 print "It prints x, y, theta values from Odom message of mobile base." 50 except rospy.ROSInterruptException:
pass def OdomCallback(self, data)