slam学习笔记

本文记录了在Ubuntu20.04上使用VS Code进行SLAM(Simultaneous Localization and Mapping)开发的过程,包括CMake文件的配置、链接库和设置C++版本。内容涉及Eigen的矩阵运算、几何运算,机器人坐标变换,Pangolin的路径绘制及三维集合体的可视化。作者分享了自学SLAM的体验,并表示将继续深入学习。
摘要由CSDN通过智能技术生成

ubuntu20.04 使用vs code编写

现放cmake文件(记得链接库文件和配置C++版本)

cmake_minimum_required( VERSION 2.8 )

project(learingMatrix)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++17")

include_directories("/usr/include/eigen3")
add_executable(learningMatrix eigenMatrix.cpp)
add_executable(learnningGeometry useGeometry.cpp)
add_executable(coordinatetrans coordinateTransform.cpp)
add_executable(plot plotTrajectory.cpp)
add_executable(cube visualizeGeometry.cpp)

include_directories(${Pangolin_INCLUDE_DIRS})
find_package( Pangolin )

target_link_libraries(plot ${Pangolin_LIBRARIES})

target_link_libraries(cube ${Pangolin_LIBRARIES})

以下为eigen的简单运算部分

#include <iostream>
using namespace std;

#include <ctime>

#include <Eigen/Core>           //eigen 核心
#include <Eigen/Dense>          //稠密矩阵运算规则
using namespace Eigen;

#define MATRIX_SIZE 50

int main(int argc, char** argv)
{
    Matrix<float,2,3> matrix_23;   //Matrix模板类用三个参数生成一个矩阵 数据类型,行,列

    Vector3d v_3d;                 //Vector3d生成一个三维行向量,d是double的意思,本质上还是Matrix一个特殊形式 
    Matrix<double,3,1>  v1_3d;    //同一个意思

    Matrix3d matrix_33 = Matrix3d::Zero(); //Matrix3d生成一个3*3的方阵, Zero是0阵

    Matrix<double , Dynamic,Dynamic> matrix_dynamic; //定义动态矩阵,行和列随数据变化
    MatrixXd matrix_x;                               //同上

    // ------------------------------------------------------------------------------------

    matrix_23<<1,2,3,4,5,6;        //输入数据(运算符重载)

    cout<<"matrix 2*3 from 1 to 6 : "<<matrix_23<<endl; //输出(运算符重载)

    cout<<"print matrix 2*3: "<<endl;
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<matrix_23(i,j)<<"\t";
        }
        cout<<endl;
    }

    //-----------------------------------------------------------------------------------------
    v_3d << 3,2,1;
    v1_3d <<4,5,6;

    //Matrix<double ,2,1> result_wrong_type =matrix_23*v1_3d;(不能混用不同数据类型的矩阵,eigen不会自动升级数据类型)
    Matrix<double , 2, 1> result = matrix_23.cast<double>()*v_3d;           //cast转换数据类型
    cout<<"[1,2,3;4,5,6]*[3,2,1]="<<result.transpose()<<endl;

    Matrix<double , 2,1> result2 = matrix_23.cast<double>()*v1_3d;
    cout<<"[1,2,3;4,5,6]*[4,5,6]="<<result2.transpose()<<endl;              //transpose转置
    //Eigen::Matrix<double , 2,3 > result_wrong_dimension = matrix_23.cast<double>()*v_3d; (不同维度的矩阵不能直接赋值,eigen不会自动填充空白)

    //----------------------------------------------------------------------------------------
    matrix_33 = Matrix3d::Random();                                         //随机填充数
    cout<<"random matrix:\n"<<matrix_33<<endl;
    cout<<"transpose :\n"<<matrix_33.transpose()<<endl;
    cout<<"sum: \n"<<matrix_33.sum()<<endl;
    cout<<"trace: \n"<<matrix_33.trace()<<endl;
    cout<<"10 times: \n"<<10*matrix_33<<endl;
    cout<<"inverse ; \n"<<matrix_33.inverse()<<endl;                        //不推荐直接求逆,维度一大起来,计算量太大
    cout<<"det: \n"<<matrix_33.determinant()<<
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值