首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >[ROS2]数据回放伴侣Rviz+plotjuggler

[ROS2]数据回放伴侣Rviz+plotjuggler

原创
作者头像
首飞
发布2022-05-01 22:43:12
发布2022-05-01 22:43:12
2.1K0
举报
文章被收录于专栏:ROS2ROS2

Plotjuggler简介

PlotJuggler是一个类似于rqt_plot的基于Qt的数据可视化工具。但PlotJuggler拥有更强大和好用的功能。你可以导入文本文件让它显示文本文件中的数据。你也可以导入ros的bag包,它能自动解析bag包中的数据。并可以回放bag包的数据,然后用Rviz来显示数据。PlotJuggler的功能有很多,这里只介绍几种我常用的功能。应该足以应付日常的机器人开发调试工作。

Plotjuggler官方网址:

https://www.plotjuggler.io/

github地址:

https://github.com/facontidavide/PlotJuggler

安装Plotjuggler

注意一下,如果是配合ROS1来使用,推荐安装PlotJuggler 2.X.X,如果是配合ROS2来使用,则推荐安装PlotJuggler 3.X.X

基于二进制AppImage文件安装

可以在二进制文件下载网页直接下载。

下载网页:https://github.com/facontidavide/PlotJuggler/releases

文件下载好后需要给文件增加执行权限,然后双击即可打开使用。

ROS二进制文件安装(推荐)

使用下面的命令:

代码语言:txt
复制
sudo apt install ros-${ROS_DISTRO}-plotjuggler-ros

运行Plotjuggler

对于ROS1

代码语言:txt
复制
rosrun plotjuggler plotjuggler

对于ROS2

代码语言:txt
复制
ros2 run plotjuggler plotjuggler

升级新版本时也可以使用该命令

代码语言:c++
复制
sudo apt-get update
sudo apt install ros-${ROS_DISTRO}-plotjuggler-ros

源码安装

用这种方式的话,你可能是想对Plotjuggler的代码进行修改。源码编译分两种情况,与ROS无关的源码编译需要与ROS联合使用的源码编译

如果拉取github代码很慢,可尝试使用github下载加速工具https://ghproxy.com/

  • 与ROS无关的源码编译

克隆仓库

代码语言:txt
复制
git clone https://github.com/facontidavide/PlotJuggler.git

安装编译前的依赖

代码语言:txt
复制
sudo apt -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev libqt5opengl5-dev libqt5x11extras5-dev libprotoc-dev

执行编译

代码语言:txt
复制
 mkdir build; cd build
 cmake ..
 make
 sudo make install

注意:使用该方式编译是没有ROS相关的插件的。

  • 需要与ROS联合使用的源码编译

对于ROS1

  1. 建立工作空间并拉取代码
代码语言:txt
复制
 mkdir -p ~/ws_plotjuggler/src
 cd ~/ws_plotjuggler/src
 git clone https://ghproxy.com/https://github.com/PlotJuggler/plotjuggler_msgs.git
 git clone https://ghproxy.com/https://github.com/facontidavide/PlotJuggler.git
 git clone https://ghproxy.com/https://github.com/PlotJuggler/plotjuggler-ros-plugins.git
  1. 解决依赖并编译
代码语言:txt
复制
cd ~/ws_plotjuggler
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make
  1. 启动Plotjuggler
代码语言:txt
复制
source devel/setup.bash
roslaunch plotjuggler_ros plotjuggler.launch

对于ROS2 Galactic

  1. 建立工作空间并拉取代码
代码语言:txt
复制
 mkdir -p ~/ws_plotjuggler/src
 cd ~/ws_plotjuggler/src
 git clone https://ghproxy.com/https://github.com/PlotJuggler/plotjuggler_msgs.git -b ros2
 git clone https://ghproxy.com/https://github.com/facontidavide/PlotJuggler.git
 git clone https://ghproxy.com/https://github.com/PlotJuggler/plotjuggler-ros-plugins.git -b galactic
  1. 解决依赖并编译
代码语言:txt
复制
cd ~/ws_plotjuggler
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
colcon build
  1. 启动Plotjuggler
代码语言:txt
复制
source install/setup.bash
ros2 run plotjuggler plotjuggler

用Plotjuggler显示机器人路径

保存机器人轨迹为CSV文件

使用下面的示例代码来存储机器人的位置。存储其他数据也可以用类似的方法。

代码语言:c++
复制
#include <fstream>
#include <ios>
#include <iostream>
#include <string>
#include <vector>

struct Pose
{
    double x;
    double y;
}

void saveCvsFile(std::string file_name, std::vector<Pose> path)
{
    std::ofstream outfile;
    outfile.open(file_name.c_str(), std::ios::trunc);
    outfile << "x"
        << ","
        << "y"
        << ","
        << "yaw"
        << ","
        << "num" << std::endl;
    int num_count = 0;
    for (int i = 0; i < path->size(); ++i)
    {
        outfile << path->at(i).x << "," << path->at(i).y << ","  
            << path->at(i).yaw << "," << num_count << std::endl;
        num_count++;
    }
    outfile.close();
}

Plotjuggler显示CSV文件路径

打开Plotjuggler,选中Data加载CSV文件。

选择num作为x轴

显示ROS bag中的数据

录制bag的命令

代码语言:c++
复制
ros2 bag record -o bagname 话题名称

示例:

代码语言:c++
复制
ros2 bag record -o turtlebot /turtle1/cmd_vel /turtle1/pose

Plotguggler加载ROS2 bag

这里以加载ROS2记录的bag为例。对于ROS1 bag,操作过程也是类似的。

ros bag中的数据是按时间顺序记录的,所以在Plotguggler中可以随意拖动进度条查看不同时间点的数据内容。这个功能对调试来说太方便了。

订阅ROS话题

点击下面的是start按钮开始订阅话题数据,点击stop结束话题订阅。然后左下方就能看到已经记录好的数据了。

Plotguggler回放ROS2 bag,Rviz显示数据

目前该功能在ROS2环境中还是有问题。Plotguggler的github中已经开了相关的Issue,但作者似乎修改的不彻底。仍然有崩溃的问题。Plotguggler 2.x.x的版本在ROS1环境下亲测可以正常使用。拖动进度条,可按任意节奏播放记录的话题数据。

Issue网址:

Segmentation Fault when trying to topic Re-Publisher

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Plotjuggler简介
  • 安装Plotjuggler
  • 用Plotjuggler显示机器人路径
  • 显示ROS bag中的数据
  • 订阅ROS话题
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档