通过脚本过滤掉ROS bag中不需要的topic

该脚本需要输入两个参数,参数1为要过滤的bag,参数二为新生成的bag。脚本中对/monitor//*进行过滤,并生成新的bag文件。

#!/bin/bash

#1.get the info of the bag
if [ $# != 2 ]; then
   echo "the input params number is not 2,please try again!"
   exit 1
fi
rosbag info $1 > bag.txt
#2.get the delete topics form the bag
bag_file=./bag.txt
for line in $(grep "/monitor//*" $bag_file)
do
    result=$(echo $line | grep "/monitor//*")
    if [[ "$result" != "" ]]
    then
       echo $line >> topics.txt
    fi
    #echo $line >> topics.txt
done
topic_file=./topics.txt
if [ ! -s $topic_file ]
then
    echo "there is not the /monitor/* topic in the $1 bag."
    exit 1
fi
#3.chreate the command to del the topics
line_count=0
topicinfo=""
for line in $(cat $topic_file)
do
    if [ 0 == $line_count ];then
        topicinfo="topic!='$line'"
    else
        topicinfo=$topicinfo" and topic!='$line'"
    fi
    line_count=$line_count+1
done

echo "rosbag filter $1 $2 ""\""$topicinfo"\"" > rosbag.sh
#4.execute the cmd
chmod 777 rosbag.sh
./rosbag.sh
echo "###########the new bag $2 has created now#############"
#5.delete the files no need
rm -rf bag.txt
rm -rf topics.txt
rm -rf rosbag.sh

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值