-
Notifications
You must be signed in to change notification settings - Fork 4
/
imu_convertion.py
52 lines (41 loc) · 1.56 KB
/
imu_convertion.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Script that creates an imu bin file that can be used in dataset2bag')
parser.add_argument('imu_raw', help='imu raw log')
parser.add_argument('imu_new', help='imu new log')
args = parser.parse_args()
orientation = "1 0 0 0 1 0 0 0 1"
fr = open(args.imu_raw,"r") #information obtained from sensor
fw = open(args.imu_new,"w") #new imu file to use with dataset2bag
#since number of characters of the values may change lines are splitted usings spaces as delimiters
for line in fr:
splitted_line = line.split(" ")
seconds,nanoseconds = splitted_line[0].split(".")
nanoseconds = nanoseconds + "000"
Gx = splitted_line[3]
Gy = splitted_line[4]
Gz = splitted_line[5]
Tx = splitted_line[6]
Ty = splitted_line[7]
Tz = splitted_line[8]
### adjustment of value's offsets
Gx = float(Gx)+4.5970119258
Gy = float(Gy)-4.78218418728
Gz = float(Gz)-7.36174929329
Tx = float(Tx)-926.447738516
Ty = float(Ty)+15.4401130742
Tz = float(Tz)+401.003545936
### convertion from g to m/s²
Tx_meters = Tx * 9.80665
Ty_meters = Ty * 9.80665
Tz_meters = Tz * 9.80665
### convertion from degrees to rad/s
Gx_rads = Gx * math.pi / 180
Gy_rads = Gy * math.pi / 180
Gz_rads = Gz * math.pi / 180
fw.write(seconds + " " + nanoseconds + " " + str(Gx_rads) + " " + str(Gy_rads) + " " + str(Gz_rads) + " " + str(Tx_meters) + " " + str(Ty_meters) + " " + str(Tz_meters) + " " + orientation + "\n")
fr.close()
fw.close()