#!/bin/bash

# List of bag files
bag_files=("RAW-UCM-0323-06.bag" "RAW-UCM-0323-08.bag" "RAW-UCM-0323-12.bag" "RAW-UCM-0323-13.bag" "RAW-UCM-0323-16.bag" "RAW-UCM-0323-17.bag" "RAW-UCM-0323-30.bag")
# "RAW-UCM-0323-06.bag" 

# Directory to save the new bag files
output_directory="../input"

# Loop through the list of bag files
for bag_file in "${bag_files[@]}"; do

  # Record the topics while excluding specific ones
  output_bag_file="$output_directory/$bag_file"
  rosbag record -a -x "/ublox/fix|/ublox/fix_velocity|/rosout" -o "$output_bag_file" & 
  sleep 1

  # Play the original bag file
  echo "Playing $bag_file"
  rosbag play "$bag_file" --start 0.1
  playbag_pid=$!
  sleep 1

  # Kill the rosbag play process
#   pkill -f "rosbag play $bag_file"
  kill -INT $playbag_pid
  rosnode kill /record_bag
done
