Yura YuLife

ITエンジニアの覚え書き

ROSのbagファイルから特定トピックをcsv形式で出力する

めちゃくちゃ簡単。

環境

bagファイルをcsv形式で出力

以下のコマンド1行でいける。

$ rostopic echo -b bagファイル.bag -p /トピック名 > csvファイル.csv

例えば、Twist形式だと以下のようになる。

$ rostopic echo -b bagファイル.bag -p /velocity

%time,field.linear.x,field.linear.y,field.linear.z,field.angular.x,field.angular.y,field.angular.z
1458645072419031373,0.133069615205,0.0,0.0,0.0,0.0,0.5369403653
1458645072485691182,0.143589122067,0.0,0.0,0.0,0.0,0.447242712703
1458645072552957164,0.153924085326,0.0,0.0,0.0,0.0,0.377736128001
1458645072620157095,0.164047896997,0.0,0.0,0.0,0.0,0.322948435252
1458645072687306707,0.173941054616,0.0,0.0,0.0,0.0,0.279093465935
1458645072754349028,0.183588971233,0.0,0.0,0.0,0.0,0.24350186043
...

特定の速度成分のみを取り出すのも簡単。

$ rostopic echo -b bagファイル.bag -p /velocity/linear/x

%time,field
1458645057721221180,0.191296330546
1458645057788266707,0.18462966388
1458645057856087891,0.177962997213
1458645057922422050,0.171296330546
1458645057989690875,0.16462966388
...

参考URL