-
Notifications
You must be signed in to change notification settings - Fork 47
/
sensor_service_imu
executable file
·54 lines (44 loc) · 1.66 KB
/
sensor_service_imu
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
#!/usr/bin/env python
#
# Sensor service IMU is a node to
# * convert quaternion orientation into heading angle with our convention
# * transform NED (North East Down) reference IMU data into ENU (East North Up)
#
# Subscribe to: imu/data (Imu)
# Published topic: heading (Float32)
from __future__ import division
import rospy
import tf
import math
from std_msgs.msg import Float32
from sensor_msgs.msg import Imu
class heading_processing(object):
def __init__(self):
rospy.init_node('Heading_service')
self.heading = 0
self.heading_pub = rospy.Publisher('heading', Float32, queue_size=10)
self.pitch_pub = rospy.Publisher('pitch', Float32, queue_size=10)
self.roll_pub = rospy.Publisher('roll', Float32, queue_size=10)
rospy.Subscriber('imu/data', Imu, self.heading_publisher)
def heading_publisher(self, msg):
imu = msg.orientation
self.heading = (math.degrees(
tf.transformations.euler_from_quaternion(
(imu.x, imu.y,imu.z, imu.w))[2]) - 90) % 360
self.pitch = math.degrees(
tf.transformations.euler_from_quaternion(
(imu.x, imu.y,imu.z, imu.w))[1])
self.roll = math.degrees(
tf.transformations.euler_from_quaternion(
(imu.x, imu.y,imu.z, imu.w))[0])
def run(self):
r = rospy.Rate(20)
while not rospy.is_shutdown():
self.heading_pub.publish(self.heading)
r.sleep()
if __name__ == '__main__':
process = heading_processing()
try:
process.run()
except rospy.ROSInterruptException:
pass