From 1453b731897b65d64ae7f4364b8ad3a9d134292a Mon Sep 17 00:00:00 2001 From: lumpia2 Date: Fri, 14 Oct 2022 00:22:21 -0400 Subject: [PATCH 1/6] Created rosbag record script --- .../f1tenth_modules/rosbag/rosbag_record.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py diff --git a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py new file mode 100644 index 0000000..92e995b --- /dev/null +++ b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py @@ -0,0 +1,26 @@ +import os +import rosbag +import argparse + +if __name__ == '__main__': + ## TODO Check if roscore is active ## + + 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, default='nameMe', help='Output filename') + + args = ap.parse_args() + + input("Press enter to start") + + topicList = "" + + for topics in args.topics: + topicList += topics + + print(topicList) + exit() + + # os.system(f"rosbag record -O {args.outfile} {}") \ No newline at end of file From 819e72555d598577848f2d6259e46ae6c397a603 Mon Sep 17 00:00:00 2001 From: lumpia2 Date: Fri, 14 Oct 2022 06:23:42 -0400 Subject: [PATCH 2/6] Added interrupt to stop rosbag recording --- .../f1tenth_modules/rosbag/rosbag_record.py | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py index 92e995b..7fdeb50 100644 --- a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py +++ b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py @@ -1,9 +1,19 @@ import os -import rosbag import argparse +from time import sleep +import keyboard +from signal import signal, SIGINT + +def handler(sig_received, frame): + # Signal received, stop rosbag + print("Rosbag record completed...exiting") + sleep(1) + exit(0) if __name__ == '__main__': ## TODO Check if roscore is active ## + + signal(SIGINT, handler) ap = argparse.ArgumentParser() @@ -13,14 +23,19 @@ args = ap.parse_args() - input("Press enter to start") + input("Press enter to start recording...") + + # Create list of topics for command line topicList = "" for topics in args.topics: - topicList += topics - - print(topicList) - exit() + topicList += topics + " " + + # Start recosbag recording + os.system(f"rosbag record -O {args.outfile} {topics}") + + print("Press CTRL+C to stop recording...") - # os.system(f"rosbag record -O {args.outfile} {}") \ No newline at end of file + while(True): + pass \ No newline at end of file From b9e6904c7b80a957029a145671460f6d730f6edd Mon Sep 17 00:00:00 2001 From: lumpia2 Date: Sat, 15 Oct 2022 00:34:54 -0400 Subject: [PATCH 3/6] rosbag_record collects data on all topics inputted into inputted output file name --- .../f1tenth_modules/rosbag/rosbag_record.py | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py index 7fdeb50..8654f38 100644 --- a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py +++ b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py @@ -1,41 +1,28 @@ import os import argparse -from time import sleep -import keyboard -from signal import signal, SIGINT - -def handler(sig_received, frame): - # Signal received, stop rosbag - print("Rosbag record completed...exiting") - sleep(1) - exit(0) if __name__ == '__main__': ## TODO Check if roscore is active ## - - signal(SIGINT, handler) 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, default='nameMe', help='Output filename') + ap.add_argument('-o', '--outfile', nargs=1, type=str, required=True, help='Output filename') args = ap.parse_args() + + ## TODO Check if bag output name exists input("Press enter to start recording...") - # Create list of topics for command line topicList = "" for topics in args.topics: topicList += topics + " " - - # Start recosbag recording - os.system(f"rosbag record -O {args.outfile} {topics}") - + print("Press CTRL+C to stop recording...") - - while(True): - pass \ No newline at end of file + + # Start recosbag recording + os.system(f"rosbag record -O {args.outfile[0]}.bag {topicList}") \ No newline at end of file From 5c333275a2c13879bb315c3f5fda840cc00566dc Mon Sep 17 00:00:00 2001 From: lumpia2 Date: Sun, 16 Oct 2022 09:15:31 -0400 Subject: [PATCH 4/6] Check if rosbag output name already exists --- catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py index 8654f38..a71e8b2 100644 --- a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py +++ b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py @@ -12,7 +12,9 @@ args = ap.parse_args() - ## TODO Check if bag output name exists + # 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: ") input("Press enter to start recording...") From cc28ab21cb73e50afbc0eda41ed027598ec79770 Mon Sep 17 00:00:00 2001 From: lumpia2 Date: Sun, 16 Oct 2022 09:30:50 -0400 Subject: [PATCH 5/6] Checks if roscore is running --- .../src/f1tenth_modules/rosbag/rosbag_record.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py index a71e8b2..bd7cdc5 100644 --- a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py +++ b/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py @@ -1,9 +1,8 @@ import os import argparse +import rostopic if __name__ == '__main__': - ## TODO Check if roscore is active ## - ap = argparse.ArgumentParser() # Parameters @@ -15,8 +14,19 @@ # 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 - input("Press enter to start recording...") + 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 = "" From 420d18de7af7cd7de3052ad058afce99046d693c Mon Sep 17 00:00:00 2001 From: lumpia2 Date: Wed, 19 Oct 2022 13:30:46 -0400 Subject: [PATCH 6/6] Removed rosbag folder and moved rosbag_record.py to scripts dir --- .../src/f1tenth_modules/rosbag => scripts}/rosbag_record.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {catkin_ws/src/f1tenth_modules/rosbag => scripts}/rosbag_record.py (100%) diff --git a/catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py b/scripts/rosbag_record.py similarity index 100% rename from catkin_ws/src/f1tenth_modules/rosbag/rosbag_record.py rename to scripts/rosbag_record.py