Created
May 29, 2018 17:42
-
-
Save neale/f0bda15bbc0df1eca5885898337cefc1 to your computer and use it in GitHub Desktop.
Parse ROS odometry output to (xyz) csv file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import csv | |
def get_n(string): | |
return re.findall(r"[-+]?\d*\.\d+|\d+", string) | |
lines = [] | |
with open('coordsOut.txt', 'r') as f: | |
for line in f.readlines(): | |
lines.append(line) | |
x, y, z = [], [], [] | |
for i, line in enumerate(lines): | |
if 'position' in line: | |
coord_x = get_n(lines[i+1]) | |
coord_y = get_n(lines[i+2]) | |
coord_z = get_n(lines[i+3]) | |
x.append(coord_x[0]) | |
y.append(coord_y[0]) | |
z.append(coord_z[0]) | |
print (len(x), len(y), len(z)) | |
with open('coords.csv', 'w') as f: | |
writer = csv.writer(f, delimiter=',') | |
for line in zip(x, y, z): | |
writer.writerow(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment