Skip to content

Instantly share code, notes, and snippets.

@neale
Created May 29, 2018 17:42
Show Gist options
  • Save neale/f0bda15bbc0df1eca5885898337cefc1 to your computer and use it in GitHub Desktop.
Save neale/f0bda15bbc0df1eca5885898337cefc1 to your computer and use it in GitHub Desktop.
Parse ROS odometry output to (xyz) csv file
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