Last active
February 7, 2022 15:06
-
-
Save rgov/dd1048e930da4619502708b6d7da9afc to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
import argparse | |
import csv | |
import datetime | |
import math | |
import rosbag | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--topic') | |
parser.add_argument('--every', type=int, default=1) | |
parser.add_argument('input') | |
parser.add_argument('output') | |
args = parser.parse_args() | |
bag = rosbag.Bag(args.input) | |
writer = csv.writer(open(args.output, 'w', newline='')) | |
# Write the header row | |
writer.writerow(('time', 'value')) | |
i = -1 | |
for topic, msg, t in bag: | |
if topic == args.topic: | |
i += 1 | |
if i % args.every != 0: | |
continue | |
ts = datetime.datetime.utcfromtimestamp(t.to_sec()) | |
writer.writerow(( | |
ts.isoformat(), | |
msg.data | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment