最近准备学习下lego loam的深层次算法原理,学习的最好办法就是对源代码进行解析重构,matlab有很好的显示效果,可以随时查看过程数据,是一个很好的重构语言(用C++重构和抄一遍没啥区别,再说我c++水平一般),这次记录在matlab(windows)下重构的过程和分析。这里是第一部分:如何配置安装GTSAM toolbox。
准备工作:
ubuntu18.04
系统未安装gtsam,如果已经安装,请删除
安装方式和环境需求在源码中的readme文件都有,非常详细
https://github.com/borglab/gtsam.git
最新版本的gtsam matlab toolbox安装方式稍微改了下,按照此方案可能安装不成功,建议下载4.0.3版本。
打开CMakelist.txt,按照readme原文操作This is the GTSAM MATLAB toolbox, a MATLAB wrapper around the GTSAM C++ library. To build it, enable GTSAM_INSTALL_MATLAB_TOOLBOX=ON in CMake.
找到GTSAM_INSTALL_MATLAB_TOOLBOX,把OFF改为ON
删除matlab以下文件夹中包含libstdc++
的文件
/usr/local/MATLAB/[version]/sys/os/[system]/
/usr/local/MATLAB/[version]/bin/[system]/
将matlab /usr/local/MATLAB/R2018a/extern/include/路径下的 中mex.h matrix.h tmwtypes.h复制到gtsam下
mkdir build
cd build
cmake ..
sudo make install
cmake后出现下面这些才算配置成功
........
-- Installing Matlab Toolbox to /home/sy/software/toolbox
........
-- MATLAB toolbox flags
-- Install MATLAB toolbox : Enabled
-- MATLAB root : /usr/local/MATLAB/R2018a
-- MEX binary : /usr/local/MATLAB/R2018a/bin/mex
gtsam安装在系统目录下,执行
sudo ldconfig
在build文件下:
make LocalizationExample
make LocalizationExample.run
出现
Scanning dependencies of target LocalizationExample.run
Factor Graph:
size: 5
Factor 0: BetweenFactor(1,2)
measured: (2, 0, 0)
noise model: diagonal sigmas[0.2; 0.2; 0.1];
Factor 1: BetweenFactor(2,3)
measured: (2, 0, 0)
noise model: diagonal sigmas[0.2; 0.2; 0.1];
Factor 2: keys = { 1 }
isotropic dim=2 sigma=0.1
Factor 3: keys = { 2 }
isotropic dim=2 sigma=0.1
Factor 4: keys = { 3 }
isotropic dim=2 sigma=0.1
Initial Estimate:
Values with 3 values:
Value 1: (gtsam::Pose2) (0.5, 0, 0.2)
Value 2: (gtsam::Pose2) (2.3, 0.1, -0.2)
Value 3: (gtsam::Pose2) (4.1, 0.1, 0.1)
Final Result:
Values with 3 values:
Value 1: (gtsam::Pose2) (-1.54238289e-14, 1.34169378e-15, -1.38878964e-16)
Value 2: (gtsam::Pose2) (2, 3.06264612e-16, -8.52875719e-17)
Value 3: (gtsam::Pose2) (4, -6.04907398e-16, -8.23580555e-17)
x1 covariance:
0.00828571429 4.32065084e-19 -1.14226768e-18
4.32065084e-19 0.00944444444 -0.00305555556
-1.14226768e-18 -0.00305555556 0.00819444444
x2 covariance:
0.00714285714 2.54833475e-19 -3.35014688e-19
2.54833475e-19 0.00777777778 -0.00111111111
-3.35014688e-19 -0.00111111111 0.00819444444
x3 covariance:
0.00828571429 4.39373657e-19 1.15570434e-18
4.39373657e-19 0.00944444444 0.00305555556
1.15570434e-18 0.00305555556 0.0181944444
[100%] Built target LocalizationExample.run
安装成功
根据安装路径配置toolbox(我的是 /path/install/toolbox),使用matlab设置路径添加该文件夹,gtsam toolbox设置完成。