Webots:VSCode作为控制器IDE并调用Eigen库
0.目的与最终效果
在设计机器人的控制器时无法避免的会用到很多的矩阵相关的运算,为了提高效率,采用开源矩阵运算库是比较合适的。
本文选用Eigen库作为控制器矩阵和矢量运算,数值分析及其相关的算法的运算库。
使用VSCode作为Webots控制器IDE的配置过程参看上一篇博客。
本文介绍如何在上述VSCode作为Webots控制器IDE的基础上添加Eigen库作为控制器的矩阵运算库,配置完成后的效果如下图所示。
1.下载Eigen库
直接去Eigen官方网站下载最新的稳定版本
由于是在Windows上使用所以直接下载ZIP格式,下载完成后解压到即可。
2.在Webots控制器的Makefile中添加链接库
打开Webots生成的C++控制器的Makefile文件,在其中添加如下内容,D:/eigen-3.4.0/Eigen为解压后Eigen的目录
### ---- Linked libraries ----
### if your program needs additional libraries:
INCLUDE = -I D:/eigen-3.4.0/Eigen
### LIBRARIES = -L D:/eigen-3.4.0/Eigen/src/Core -lMatrix
###
### ---- Linking options ----
### if special linking flags are needed:
### LFLAGS = -s
###
### ---- Webots included libraries ----
### if you want to use the Webots C API in your C++ controller program:
### USE_C_API = true
###
3.在VSCode的c_cpp_properties.json文件中链接库
经过在Makefile文件中添加Eigen库,即可通过编译正常使用Eigen库,但此时在VSCode中对代码进行修改时并不具备自动补全功能,因此需要在c_cpp_properties.json文件中配置Eigen库路径
{
"configurations": [
{
"name": "Win32",
"includePath": [
"D: