站点图标 AI技术聚合

SLAM评估工具-EVO从安装到使用

SLAM评估工具-EVO从安装到使用

1、安装 evo

pip install evo --upgrade --no-binary evo --user

可以直接安装

如果它说它需要更新,只需更新它

/usr/local/bin/python3.7 -m pip install --upgrade pip

2、测试

evo_traj euroc 2.txt --plot

错误:
[ERROR] EuRoC format ground truth must have at least 8 entries per row and no trailing delimiter at the end of the rows (comma)

出现这个问题的原因是生成的原始文件中偶尔存在空格等不是完全规范的tum结果文件

解决方案:运行以下命令删除多余的空格
使用此方法尝试解决:

cat results.txt | tr -s [:space:] > results_new.txt

但错误
[ERROR] TUM trajectory files must have 8 entries per row and no trailing delimiter at the end of the rows (space)

我打开我的txt数据,发现只有七列而要求是八列,因此需要改成八列数据
请求的八列数据如下:
时间戳+三维坐标+四元数
我之前的路径输出是三个旋转角度,哭了,所以需要转换成四元数输出,重新修改代码运行,输出八列数据

它可以顺利运行:

处理我的真实轨迹文件并保留八列数据
如图所示,为了使用evo进行绘图,需要格式准确,这样还是报错
首先,你需要顶部框架,没有空格
其次,对空格的要求太高,需要把空格删掉,转成逗号比较安全,所以需要把上面的格式转换成下图所示的格式
代码放在下面:
新建一个create_txt.cpp

#include <ros/ros.h>
#include <ros/time.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/PointCloud.h>
#include <pcl/point_types.h>                 //pcl点云格式头文件
#include <pcl_conversions/pcl_conversions.h> //转换
#include <pcl/point_cloud.h>
#include <pcl/filters/voxel_grid.h>
#include <sensor_msgs/point_cloud_conversion.h>
#include "Eigen/Core"
#include <boost/foreach.hpp>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>

#include <stdlib.h>
#include <ctime>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>

#define foreach BOOST_FOREACH
using namespace std;


std::string  txt_path;
struct TRAJECTORY
{
    double time;
    double position_x;
    double position_y;
    double position_z;
    double orientation_w;
    double orientation_x;
    double orientation_y;
    double orientation_z;
};

void read_trajectory_file(std::string filepathIn)
{
    std::ifstream inFile(filepathIn);
    std::ofstream traj_ofs;
    traj_ofs.open( txt_path.c_str(), std::ios::app);
    if (!inFile)
    {
        cout << "open write file fail!" << endl;
    }
    // temp v
    char content[2000];
    std::string content_str = "";

    while (!inFile.eof())
    {
        content_str = "";
        inFile.getline(content, 2000);
        if (strlen(content) < 2)
            break;

        std::istringstream _Readstr(content);
        std::string partOfstr;
        double data[9];

        for (int i = 0; i < 9; i++)
        {
            getline(_Readstr, partOfstr, ' ');
            data[i] = strtold(partOfstr.c_str(), NULL);
        }

        TRAJECTORY trajectory;
        trajectory.time = data[0];
        trajectory.position_x = data[1];
        trajectory.position_y = data[2];
        trajectory.position_z = data[3];
        trajectory.orientation_w = data[4];
        trajectory.orientation_x = data[5];
        trajectory.orientation_y = data[6];
        trajectory.orientation_z = data[7];

        traj_ofs << std::setprecision(16) <<  trajectory.time << "," << trajectory.position_x << "," <<  trajectory.position_y<< "," <<  trajectory.position_z << "," << trajectory.orientation_w << "," << trajectory.orientation_x << "," << trajectory.orientation_y << "," << trajectory.orientation_z<<std::endl;
    }
    inFile.close();
    traj_ofs.close();
    cout << "read trajectory file end!" << endl;

}

int main(int argc, char **argv)
{

    ros::init(argc, argv, "create_txt");
    ros::NodeHandle nh;

    string traj_path = "";
    nh.param<string>("input_trajectory_path", traj_path, "");
    nh.param<string>("output_txt_path", txt_path, "");
    read_trajectory_file(traj_path);

    return 0;
}

这将成功转换

接下来使用命令

evo_traj euroc ground.txt --plot

可以绘制成功
但是我使用evo_traj tum ground.txt –plot就一直报错
应该是格式问题

3. 轨迹对齐

采用对齐指令将两条轨迹进行对齐。为此需要通过–ref参数指定参考轨迹,并增加参数-a(或–align)进行对齐(旋转与平移)

evo_traj euroc test.txt --ref=ground.txt -p --plot_mode xyz -a --correct_scale

但是报错:
[ERROR] found no matching timestamps between reference and test.txt with max。time diff 0.01 (s) and time offset 0.0 (s)
时间戳不匹配,我该怎么办?
需要时间戳对应才能比较,很无语

格式转换

evo_traj euroc test.txt --save_as_tum

就可以转化成tum格式了,其他的都类似

版权声明:本文为博主Laney_Midory原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/Laney_Midory/article/details/123042183

退出移动版