当前位置:网站首页>GTSAM入门学习
GTSAM入门学习
2022-07-21 12:49:00 【wings0728】
二维机器人运动
x1、x2、x3分别为机器人的三次位姿,f为每个节点间的关系,其中o为里程计的意思。
#include <gtsam/geometry/Pose2.h>
#include <gtsam/geometry/Rot3.h>
#include <gtsam/geometry/Pose3.h>
#include <gtsam/slam/PriorFactor.h>
#include <gtsam/slam/BetweenFactor.h>
#include <gtsam/navigation/GPSFactor.h>
#include <gtsam/navigation/ImuFactor.h>
#include <gtsam/navigation/CombinedImuFactor.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/nonlinear/LevenbergMarquardtOptimizer.h>
#include <gtsam/nonlinear/Marginals.h>
#include <gtsam/nonlinear/Values.h>
#include <gtsam/inference/Symbol.h>
#include <gtsam/nonlinear/ISAM2.h>
int main(int argc, char** argv)
{
NonlinearFactorGraph graph;
gtsam::Pose2 priorMean(0.0, 0.0, 0.0);
noiseModel::Diagonal::shared_ptr priorNoise = noiseModel::Diagonal::Sigmas(Vector3(0.3, 0.3, 0.1));
graph.add(PriorFactor<Pose2>(1, priorMean, priorNoise));
gtsam::Pose2 odometry(2.0, 0, 0);
noiseModel::Diagonal::shared_ptr odometryNoise = noiseModel::Diagonal::Sigmas(Vector3(0.2, 0.2, 0.1));
graph.add(BetweenFactor<Pose2>(1, 2, odometry, odometryNoise));
graph.add(BetweenFactor<Pose2>(2, 3, odometry, odometryNoise));
Values initial;
initial.insert(1, Pose2(0.5, 0.0, 0.2));
initial.insert(2, Pose2(2.3, 0.1, -0.2));
initial.insert(3, Pose2(4.1, 0.1, 0.1));
Values result = LevenbergMarquardtOptimizer(graph, initial).optimize();
result.at(1).print();
result.at(2).print();
result.at(3).print();
}
- NonlinearFactorGraph graph创建一个因子图优化对象
- gtsam::Pose2 priorMean(0.0, 0.0, 0.0) 创建二维先验位姿(x, y, yaw)
- line 3~4创建先验位姿的噪声,并把先验位姿加入因子图优化
- gtsam::Pose2 odometry(2.0, 0, 0) 创建一个delta的里程计对象,x方向为2米,y为0米,yaw为0弧度
- line 6~8 创建里程计的噪声,并把里程计作为两个节点间的变换关系(BetweenFactor<Pose2>)传入因子图优化对象内
- line 9~12 定义三个节点的初始位姿
- line13 开始优化,把优化结果存入result
- 最后打印优化结果
可以看到我们三个节点的初始位姿分别为:
(0.5, 0.0, 0.2)
(2.3, 0.1, -0.2)
(4.1, 0.1, 0.1)经过优化后的打印结果为:
(7.46978e-16, -5.34409e-16, -1.78382e-16)
(2, -1.09237e-15, -2.48671e-16)
(4, -1.70076e-15, -2.50944e-16)
边栏推荐
- Merge sort solves the quantity problem of reverse order pairs
- Step by step introduction to the development framework based on sqlsugar (12) -- split the content of the page module into components to realize the division and rule processing
- Mapstruct code generator realizes object transformation
- Subvert cognition! There are as many as 13 methods to guarantee research?
- 归并排序解决逆序对的数量问题
- Go language environment construction and samples
- 【苏州大学】考研初试复试资料分享
- Cesium加载3D Tiles数据
- Cesium 事件详解(鼠标事件、相机事件、键盘事件、场景触发事件)
- Zhenhua scenery semiconductor passed the registration: with an annual revenue of 500million, China Electronics is the actual controller
猜你喜欢
云洲智能IPO被终止:年营收2.5亿亏1.3亿 曾拟募资15.5亿
[chestnut sugar GIS] ArcMap -- how to make text four Zhi of surface data
jvm初识
[Suzhou University] information sharing of postgraduate entrance examination and re examination
Understand the volatile implementation of JVM from the bottom, CPU cache, cache consistency MESI, store bufferi, nvalidate queue and other knowledge
阿里云ECS手动挂载磁盘
Real 3D has gradually become a general trend of Surveying and mapping, and data storage has ushered in a new outlet
Model/view architecture of QT
专访SPORTFIVE李莹:如何用Web3的方式推动体育IP拓展“新商业版图”
DRF -- cross domain problem solving
随机推荐
年中盘点 | 2022年,PaaS 再升级
Command line use of eslint
Go language environment construction and samples
泰山OFFICE技术讲座:页面的内容区宽高计算差异
Introduction to excellent verilog/fpga open source project (XXIX) - open source website
柠萌影视通过聆讯:年营收12亿 腾讯与芒果文创是股东
Apple lost 340million Yuan due to bad keyboard. SpaceX received the order. Webb's successor, meta, sued meta. Today, more new things are here
Shell foundation
Example demonstration of "uncover the secrets of asp.net core 6 framework" [04]: Custom dependency injection framework
PHP7.4使用composer报异常处理
[FPGA tutorial case 33] communication case 3 - BPSK modulation signal generation based on FPGA, and its constellation is tested by MATLAB
开源GIS体系
动态内存精讲
【板栗糖GIS】arcmap—如何快速生成四至信息
Common operations of windows10 system
scratch成绩查询 电子学会图形化编程scratch等级考试四级真题和答案解析2022年6月
JS array method
DRF--JWT2-用户认证-自定义控制simpjwt返回内容
window10任务栏操作
【板栗糖GIS】bat—如何对子文件中的数据进行批量重命名