ROS开源工具总结

ROS开源工具总结

[TOC]
ROS中有很多开源工具很好用,本文会汇总一些使用过的好用的工具,持续更新.

绘制线形

ROS中查看数据,绘制线形,第一想法便是rqt_plot,并且配合着parameter server可以实现在线调参等高级功能.然而对于录制好的rosbag数据,rqt_plot稍有些不够灵活,首先需要启动roscore,然后需要rosbag play回放完数据才能得到线形.有没有更灵活,线下处理rosbag,抽取感兴趣数据的工具?本文介绍两个,一个是PlotJuggler,另一个是bagpy.

PlotJuggler

安装

基于Qt需要先安装Qt库.

1
2
sudo apt-get -y install qtbase5-dev libqt5svg5-dev qtdeclarative5-dev qtmultimedia5-dev libqt5multimedia5-plugins
sudo apt-get install ros-kinetic-plotjuggler

运行

1
2
roscore
rosrun plotjuggler plotjuggler

特点及使用

  • 多个绘图窗口:可以按行/列排列分窗口,并且每个分窗口都有独立的标签选项.
  • 离线读取rosbag,也支持在线读取ros message.
  • 缩放简单:例如鼠标滚轮缩放,左键拉选框放大等,还可以锁定所有图的X轴.
  • 保存/加载页面布局
  • 快捷键Undo/Redo
  • 方便地导入/导出csv
  • 展示多个topics的数据,只需要拖拽到绘图窗口即可
  • 还可以re-publish message
  • 通过脚本语言Lua,对数据进行分析.
  • 所有的功能可以通过标签选项很快明白,非常容易上手.
PlotJuggler.png Function Library 注意红框处的函数库以及Lua脚本的函数编辑处.

选项参数

1
2
3
4
5
6
7
8
9
10
11
12
13
rosrun plotjuggler PlotJuggler --help
Usage: /opt/ros/kinetic/lib/plotjuggler/PlotJuggler [options]
PlotJuggler: the time series visualization tool that you deserve

Options:
-v, --version Displays version information.
-h, --help Displays this help.
-n, --nosplash Don't display the splashscreen
-t, --test Generate test curves at startup
-d, --datafile <file> Load a file containing data
-l, --layout <file> Load a file containing the layout configuration
--buffer_size <seconds> Change the maximum size of the streaming buffer
(minimum: 10 default: 60)

写到 launchfile like 里:

1
2
3
4
5
6
7
<launch>
<node name="plotjuggler_with_layout"
pkg="plotjuggler"
type="PlotJuggler"
args="--layout $(find my_package)/config/my_plotjuggler_layout.xml"
/>
</launch>

bagpy

PlotJuggler还是需要手动拖拽手动导出成csv,如果对于rosbag的数据分析重复性很强的情况下,需要脚本帮忙实现.bagpy是基于python实现上述功能的.同时利用pandas里的DataFrame类可以很方便地分析数据,同时利用matplotlib实现数据的可视化.

安装

要求:

Ubuntu 18.04(实际16.04也可以),Python 3.5 以上,不支持Python2.x,不对Windows进行官方支持.

1
pip install bagpy

依赖的库requirements.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pandas==0.25
setuptools
setuptools_scm
importlib-resources
Sphinx==3.2.1
rinohtype
numpy
matplotlib>=3.3.1
seaborn>=0.9.0
ipython
bitstring>=3.1.6
sphinx_rtd_theme
sphinx_autodoc_typehints==1.4.0
recommonmark
pathlib
mkdocs
sphinx_bootstrap_theme
sphinx-markdown-parser
pymdown-extensions
m2r2
ytsphinx
python-dotenv
pycryptodomex
pyyaml
rospkg
py3rosmsgs
nbsphinx
pandoc
pandocfilters
yolk3k

安装踩过的坑:

1
TclError:cann't find a usable tk.tcl in the following directories

但是tk的python库,python3-tk的apt库都是安装的,查到网上说是安装目录不对.

1
sudo cp -r /usr/share/tcltk/tk8.6/* /usr/lib/tk.8.6

注意bagpy不支持已经压缩过的rosbag,因此对于已经压缩过的rosbag,需要先解压一下:

1
rosbag decompress BAG_FILE

使用教程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import bagpy
from bagpy import bagreader
import pandas as pd
import seaborn as sea
import matplotlib.pyplot as plt
import numpy as np

#read your rosbag file
b = bagreader('1.bag')
#check available topics
b.topic_table
#decode message on every topic
data = b.message_by_topic('TOPIC_NAME')
#output selected topic data as csv with a created new folder
print("File saved: {}".format(data))
#read csv data as DataFrame in pandas
df = pd.read_csv(data)
#plot a scatter graph
fig, axis = bagpy.create_fig(1)
axis[0].scatter(x = 'X_data', y = 'Y_data', data = df, s= 1, label = 'label_name')
axis.legend()
axis.set_xlabel('Time')
plt.show()
作者

cx

发布于

2021-11-24

更新于

2022-07-29

许可协议