视觉SLAM十四讲学习笔记-第二讲-开发环境搭建

专栏系列文章如下: 

视觉SLAM十四讲学习笔记-第一讲_goldqiu的博客-CSDN博客

视觉SLAM十四讲学习笔记-第二讲-初识SLAM_goldqiu的博客-CSDN博客

​​​​​​​

linux编程入门

新建一个cpp文件,命名为helloSLAM.cpp

代码如下:

#include  
using namespace std;
int main( int argc, char** argv )
{ 
      cout<<"Hello SLAM!"<

用g++编译器对其编译

命令行敲:g++ helloSLAM.cpp

输出a.out文件

命令行敲:./a.out 即可运行此程序

窗口会输出Hello SLAM!

如果仅靠g++命令,我们需要输入大量的编译指令,整个编译过程会变得异常繁琐。所以我们使用cmake。

在同个文件夹下新建一个 CMakeLists.txt 文件。输入如下:

# 声明要求的 cmake 最低版本
cmake_minimum_required( VERSION 2.8 )
# 声明一个 cmake 工程 project( HelloSLAM )
# 添加一个可执行程序
# 语法:add_executable( 程序名源代码文件)
add_executable( helloSLAM helloSLAM.cpp )

终端命令行输入: cmake .

生成了MakeFile ,它是系统自动生成的编译指令文件。

同样执行可执行文件helloSLAM ,会有同样效果。

但是还有很多中间文件,我们可以建立一个build文件夹,在这个文件夹下面cmake ..

用CMAKE的好处就是在大型项目中很方便的能够对项目进行编译管理。

下面使用自己打包的库:书写一个 libHelloSLAM.cpp 文件写下:

//这是一个库文件
#include 
using namespace std; 
void printHello()
{ 
   cout<<"Hello SLAM"<

它没有main函数,这意味着这个库中没有可执行文件。我们在 CMakeLists.txt 里加一句:

add_library( hello libHelloSLAM.cpp )


重新cmake 编译后,生成一个 libhello.a 文件。

在Linux中,库文件分成静态库和共享库(动态库)两种。静态库以.a作为后缀名,共享库以.so结尾。所有库都是一些函数打包后的集合,差别在于静态库每次被调用都会生成一个副本,而共享库则只有一个副本,更省空间。如果我们想生成共享库而不是静态库,只需用:

add_library( hello_shared SHARED ​libHelloSLAM.cpp

此时得到的文件是 libhello_shared.so

库文件是一个压缩包,里头带有编译好的二进制函数。不过,仅有.a或.so库文件的话,我们并不知道它里头的函数到底是什么,调用的形式又是什么样的。为了让别人(或者自己)使用这个库,我们需要提供一个头文件,说明这些库里都有些什么。因此,对于库的使用者,只要拿到了头文件和库文件,就可以调用这个库了。

下面写 libhello 的头文件libHelloSLAM.h

#ifndef LIBHELLOSLAM_H_ 
#define LIBHELLOSLAM_H_ 
void printHello();
#endif

写一个可执行程序useHello.cpp,调用这个简单的函数。

#include "libHelloSLAM.h" 
int main( int argc, char** argv )
{ 
  printHello(); 
  return 0; 
}

在CMakeLists.txt中添加一个可执行程序的生成命令,链接到刚才我们使用的库上:

add_executable( useHello useHello.cpp ) 
target_link_libraries( useHello hello_shared )

通过这两句话,useHello程序就能顺利使用hello_shared库中的代码了。这个小例子演示了如何生成并调用一个库。对于他人提供的库,我们也可用同样的方式对它们进行调用,整合到自己的程序中。

总结:

1. 首先,程序代码由头文件和源文件组成;

2. 带有main函数的源文件编译成可执行程序,其他的编译成库文件。

3. 如果可执行程序想调用库文件中的函数,它需要参考该库提供的头文件,以明白调用的格式。同时,要把可执行程序链接到库文件上。

开发环境:

Clion:

Clion 相比于 Kdevelop和qtcreator来说cmake支持更加完善一些,但是它需要正版帐号。我们可以用学生邮箱(带edu)免费使用一年。

下面是官网:

https://www.jetbrains.com/idea/buy/#discounts?billing=yearly

选择For students and teachers下的 learn more

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第1张图片

点击APPLY NOW

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第2张图片

输入学生邮箱,验证完成后 他会发验证链接到邮箱,打开邮箱内链接,注册JBA,在注册JBA时候还需要你输入一个邮箱,这个时候就用自己的常用邮箱就可以了。

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第3张图片

注册成功如下:

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第4张图片

回到开始的窗口 ,激活CLion

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第5张图片

现在是调试cmakelists项目:

打开cmakelists文件,导入项目

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第6张图片

需要选择你要debug的源文件和工作路径

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第7张图片

将编译输出可执行文件路径选好:

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第8张图片

可以开始调试了:

视觉SLAM十四讲学习笔记-第二讲-开发环境搭建_第9张图片

Kdevelop :

这个ide是免费的,但是不太好用,我用不习惯。

Qtcreator:

这个IDE挺好用的,但是比较适合用qmake管理项目,特别适合做上位机,也可以用cmake管理项目,但是没有clion好用。在校学生建议还是用clion,有免费版。

Vscode:

这个ide也很适合开发cmake和ros。

注:后面有空专门写一篇ROS开发环境搭建的教程,使用clion或者vscode。

课后作业

1. 书中文献阅读:

[1] L. Haomin, Z. Guofeng, and B. Hujun, “A survey of monocular simultaneous localization and mapping,” Journal of Computer-Aided Design and Compute Graphics, vol. 28, no. 6, pp. 855–868, 2016. in Chinese.

[2] A. Davison, I. Reid, N. Molton, and O. Stasse, “Monoslam: Real-time single camera SLAM,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 6, pp. 1052–1067, 2007.

[3] R. Hartley and A. Zisserman, Multiple View Geometry in Computer Vision. Cambridge university press, 2003.

[4] R. C. Smith and P. Cheeseman, “On the representation and estimation of spatial uncertainty,” International Journal of Robotics Research, vol. 5, no. 4, pp. 56–68, 1986.

[5] S. Thrun, W. Burgard, and D. Fox, Probabilistic robotics. MIT Press, 2005.

[6] T. Barfoot, “State estimation for robotics: A matrix lie group approach,” 2016.

[7] A. Pretto, E. Menegatti, and E. Pagello, “Omnidirectional dense large-scale mapping and navigation based on meaningful triangulation,” 2011 IEEE International Conference on Robotics and Automation (ICRA 2011),pp. 3289–96, 2011.

[8] B. Rueckauer and T. Delbruck, “Evaluation of event-based algorithms for optical flow with ground-truth from inertial measurement sensor,” Frontiers in neuroscience, vol. 10, 2016.

[9] C. Cesar, L. Carlone, H. C., Y. Latif, D. Scaramuzza, J. Neira, I. D. Reid, and L. John J., “Past, present, and future of simultaneous localization and mapping: Towards the robust-perception age,” arXiv preprint arXiv:1606.05830,2016.

[10] P. Newman and K. Ho, “Slam-loop closing with visually salient features,” in proceedings of the 2005 IEEE International Conference on Robotics and Automation, pp. 635–642, IEEE, 2005.

[11] R. Smith, M. Self, and P. Cheeseman, “Estimating uncertain spatial relationships in robotics,” in Autonomous robot vehicles, pp. 167–193, Springer, 1990.

[12] P. Beeson, J. Modayil, and B. Kuipers, “Factoring the mapping problem: Mobile robot map-building in the hybrid spatial semantic hierarchy,” International Journal of Robotics Research, vol. 29, no. 4, pp. 428–459, 2010.

[13] H. Strasdat, J. M. Montiel, and A. J. Davison, “Visual slam: Why filter?,” Image and Vision Computing, vol. 30, no. 2, pp. 65–77, 2012. [14] M. Liang, H. Min, and R. Luo, “Graph-based slam: A survey,” ROBOT, vol. 35, no. 4, pp. 500–512, 2013. in Chinese.

2. 综述文章阅读

[9] C. Cesar, L. Carlone, H. C., Y. Latif, D. Scaramuzza, J. Neira, I. D. Reid, and L. John J., “Past, present, and future of simultaneous localization and mapping: Towards the robust-perception age,” arXiv preprint arXiv:1606.05830,2016.

[15] J. Fuentes-Pacheco, J. Ruiz-Ascencio, and J. M. Rendón-Mancha, “Visual simultaneous localization and mapping: a survey,” Artificial Intelligence Review, vol. 43, no. 1, pp. 55–81, 2015.

[16] J. Boal, Á. Sánchez-Miralles, and Á. Arranz, “Topological simultaneous localization and mapping: a survey,” Robotica, vol. 32, pp. 803–821, 2014.

[17] S. Y. Chen, “Kalman filter for robot vision: A survey,” IEEE Transactions on Industrial Electronics, vol. 59, no. 11, pp. 4409–4420, 2012. [18] Z. Chen, J. Samarabandu, and R. Rodrigo, “Recent advances in simultaneous localization and map-building using computer vision,” Advanced Robotics, vol. 21, no. 3-4, pp. 233–265, 2007.

3. g++命令有哪些参数?怎么填写参数可以更改生成的程序文件名?g++的错误信息?

https://blog.csdn.net/chengqiuming/article/details/88410794​blog.csdn.net/chengqiuming/article/details/88410794正在上传…重新上传取消​

4. 阅读《cmake实践》,了解cmake的其他语法。

5.完善hello SLAM的小程序,把它做成一个小程序库,安装到本地硬盘中。然后,新建一个工程,使用find_package找这个库并调用它。

这块目前还不需要,后面再学。

6.寻找其他cmake教学材料,深入了解cmake,例如

https://github.com/TheErk/ CMake-tutorial

7. 寻找Kdevelop的官方网站,看看它还有哪些特性。试试Kdevelop的vim编辑功能

这块看需求学吧,有好的IDE可选择。

你可能感兴趣的:(算法,书籍学习笔记,自动驾驶,人工智能,slam)