Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions scripts/rosbag_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import argparse
import rostopic

if __name__ == '__main__':
ap = argparse.ArgumentParser()

# Parameters
ap.add_argument('-t', '--topics', nargs='+', type=str, required=True, help='List topics to record')
ap.add_argument('-o', '--outfile', nargs=1, type=str, required=True, help='Output filename')

args = ap.parse_args()

# Check if bag output name exists
while(f"{args.outfile[0]}.bag" in os.listdir()):
args.outfile[0] = input("Filename already exists. Please change the name: ")

# Check if roscore is running
rosIsRunning = False

while(not rosIsRunning):
input("Press enter to start recording...")

try:
rostopic.get_topic_class('/rosout')
rosIsRunning = True
except rostopic.ROSTopicIOException as e:
rosIsRunning = False
print("Roscore needs to be active.")

# Create list of topics for command line
topicList = ""

for topics in args.topics:
topicList += topics + " "

print("Press CTRL+C to stop recording...")

# Start recosbag recording
os.system(f"rosbag record -O {args.outfile[0]}.bag {topicList}")