Skip to content

Instantly share code, notes, and snippets.

@AnthonyZJiang
Last active January 30, 2024 16:02
Show Gist options
  • Save AnthonyZJiang/25a39d6cf4c66c38755c1c08c53efc1c to your computer and use it in GitHub Desktop.
Save AnthonyZJiang/25a39d6cf4c66c38755c1c08c53efc1c to your computer and use it in GitHub Desktop.
ros2_bag_play_exclude

Download the script, then

chmod +x ros2_bag_play_exclude.sh
./ros2_bag_play_exclude.sh <ros2_bag_file> /topic_to_exclude /more_topics_to_exclude /wild_card_match*
bag_path=$1
topics=`ros2 bag info ${bag_path} | grep "Topic information" | awk '{print $4}'`
topics+=" "
topics+=`ros2 bag info ${bag_path} | grep Topic | grep -v "Topic information" | awk '{print $2}'`
no_faults=true
for exclude in "${@:2}"; do
if [[ "${topics}" != *${exclude}* ]]; then
echo "Can't find topic name ${exclude}"
no_faults=false
continue
fi
found=false
for topic in ${topics//" "/ } ; do
if [[ ${topic} == ${exclude} ]]; then
topics=${topics//${topic}/}
found=true
fi
done
if ! ${found}; then
echo "Topic name ${exclude} may be incomplete"
no_faults=false
fi
done
if ${no_faults}; then
ros2 bag play ${bag_path} --topics ${topics}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment