SLAM十四讲——ch3实践

ch3的实践及避坑

  • 一、ch3的总体步骤
  • 二、文件的执行
    • 1. 实践:Eigen
    • 2. 实践:Eigen几何模块
    • 3. 可视化演示
  • 出现的问题

一、ch3的总体步骤

  1. 确保已经安装Eigen库,Eigen库是一个C++开源线性代数库。
sudo apt-get install libeigen3-dev

说明: 它提供了快速的有关矩阵的线性代数运算,还包括解方程等功能;想g2o\Sophus等上层软件库也会使用Eigen库。

  1. 在终端中进入ch3文件夹下,顺序执行以下命令进行编译。
mkdir build
cd build
cmake ..
//注意,j4还是其他主要看自己的电脑情况
make -j4
  1. 在build文件中执行。

二、文件的执行

1. 实践:Eigen

在build文件中进一步进入到useEigen中,然后执行 ./eigenMatrix,得到结果如下:

matrix 2x3 from 1 to 6:
1 2 3
4 5 6
print matrix 2x3:
1       2       3
4       5       6
[1,2,3;4,5,6]*[3,2,1]=10 28
[1,2,3;4,5,6]*[4,5,6]: 32 77
random matrix:
 0.680375   0.59688 -0.329554
-0.211234  0.823295  0.536459
 0.566198 -0.604897 -0.444451
transpose:
 0.680375 -0.211234  0.566198
  0.59688  0.823295 -0.604897
-0.329554  0.536459 -0.444451
sum: 1.61307
trace: 1.05922
times 10:
 6.80375   5.9688 -3.29554
-2.11234  8.23295  5.36459
 5.66198 -6.04897 -4.44451
inverse:
-0.198521   2.22739    2.8357
  1.00605 -0.555135  -1.41603
 -1.62213   3.59308   3.28973
det: 0.208598
Eigen values =
0.0242899
 0.992154
  1.80558
Eigen vectors =
-0.549013 -0.735943  0.396198
 0.253452 -0.598296 -0.760134
-0.796459  0.316906 -0.514998
time of normal inverse is 0.14ms
x = -55.7896 -298.793  130.113 -388.455 -159.312  160.654 -40.0416 -193.561  155.844  181.144  185.125 -62.7786  19.8333 -30.8772 -200.746  55.8385 -206.604  26.3559 -14.6789  122.719 -221.449   26.233  -318.95 -78.6931  50.1446  87.1986 -194.922  132.319  -171.78 -4.19736   11.876 -171.779  48.3047  84.1812 -104.958 -47.2103 -57.4502 -48.9477 -19.4237  28.9419  111.421  92.1237 -288.248 -23.3478  -275.22 -292.062  -92.698  5.96847 -93.6244  109.734
time of Qr decomposition is 0.089ms
x = -55.7896 -298.793  130.113 -388.455 -159.312  160.654 -40.0416 -193.561  155.844  181.144  185.125 -62.7786  19.8333 -30.8772 -200.746  55.8385 -206.604  26.3559 -14.6789  122.719 -221.449   26.233  -318.95 -78.6931  50.1446  87.1986 -194.922  132.319  -171.78 -4.19736   11.876 -171.779  48.3047  84.1812 -104.958 -47.2103 -57.4502 -48.9477 -19.4237  28.9419  111.421  92.1237 -288.248 -23.3478  -275.22 -292.062  -92.698  5.96847 -93.6244  109.734
time of ldlt decomposition is 0.043ms
x = -55.7896 -298.793  130.113 -388.455 -159.312  160.654 -40.0416 -193.561  155.844  181.144  185.125 -62.7786  19.8333 -30.8772 -200.746  55.8385 -206.604  26.3559 -14.6789  122.719 -221.449   26.233  -318.95 -78.6931  50.1446  87.1986 -194.922  132.319  -171.78 -4.19736   11.876 -171.779  48.3047  84.1812 -104.958 -47.2103 -57.4502 -48.9477 -19.4237  28.9419  111.421  92.1237 -288.248 -23.3478  -275.22 -292.062  -92.698  5.96847 -93.6244  109.734

2. 实践:Eigen几何模块

(1)Eigen集合模块的数据演示
在build中进入 useGeometry,执行 ./eigenGeometry后,结果如下:

rotation matrix =
 0.707 -0.707      0
 0.707  0.707      0
     0      0      1
(1,0,0) after rotation (by angle axis) = 0.707 0.707     0
(1,0,0) after rotation (by matrix) = 0.707 0.707     0
yaw pitch roll = 0.785    -0     0
Transform matrix =
 0.707 -0.707      0      1
 0.707  0.707      0      3
     0      0      1      4
     0      0      0      1
v tranformed = 1.71 3.71    4
quaternion from rotation vector =     0     0 0.383 0.924
quaternion from rotation matrix =     0     0 0.383 0.924
(1,0,0) after rotation = 0.707 0.707     0
should be equal to 0.707 0.707     0     0

(2)实际的坐标变化例子
在build中进入 examples,执行 ./coordinateTransform后,结果如下:

-0.0309731    0.73499   0.296108

3. 可视化演示

(1)显示运动轨迹
在build中进入 examples,执行 ./plotTrajectory后,结果如下:

SLAM十四讲——ch3实践_第1张图片
同时终端输出:

read total 620 pose entries

(2)Eigen集合模块的可视化演示
在build中进入 visualizeGeometry,执行 ./visualizeGeometry后,结果如下:
SLAM十四讲——ch3实践_第2张图片

出现的问题

1.出现的为题:执行./plotTrajectory时出现下面错误

cannot find trajectory file at ./examples/trajectory.txt

解决办法:更改plotTrajectory.cpp文件,将第11行./examples/trajectory.txt改为:

// path to trajectory file
string trajectory_file = "/home/fighter/slam/slambook2/ch3/examples/trajectory.txt";

原因:主要是因为找不到文件导致,这里为了避免更多的问题和麻烦出现,建议直接改为绝对路径。

你可能感兴趣的:(SLAM,#,实践操作,ubuntu,linux,矩阵,线性代数,几何学)