SLAM中的小工具

2023-05-16

g2o中有用的小工具


#ifndef G2O_STUFF_MISC_H
#define G2O_STUFF_MISC_H

#include "macros.h"
#include <cmath>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

/** @addtogroup utils **/
// @{

/** \file misc.h
 * \brief some general case utility functions
 *
 *  This file specifies some general case utility functions
 **/

namespace g2o {

/**
 * return the square value
 */
template <typename T>
inline T square(T x)
{
  return x*x;
}

/**
 * return the hypot of x and y
 */
template <typename T>
inline T hypot(T x, T y)
{
  return (T) (sqrt(x*x + y*y));
}

/**
 * return the squared hypot of x and y
 */
template <typename T>
inline T hypot_sqr(T x, T y)
{
  return x*x + y*y;
}

/**
 * convert from degree to radian
 */
inline double deg2rad(double degree)
{
  return degree * 0.01745329251994329576;
}

/**
 * convert from radian to degree
 */
inline double rad2deg(double rad)
{
  return rad * 57.29577951308232087721;
}

/**
 * normalize the angle
 */
inline double normalize_theta(double theta)
{
  if (theta >= -M_PI && theta < M_PI)
    return theta;
  
  double multiplier = floor(theta / (2*M_PI));
  theta = theta - multiplier*2*M_PI;
  if (theta >= M_PI)
    theta -= 2*M_PI;
  if (theta < -M_PI)
    theta += 2*M_PI;

  return theta;
}

/**
 * inverse of an angle, i.e., +180 degree
 */
inline double inverse_theta(double th)
{
  return normalize_theta(th + M_PI);
}

/**
 * average two angles
 */
inline double average_angle(double theta1, double theta2)
{
  double x, y;

  x = cos(theta1) + cos(theta2);
  y = sin(theta1) + sin(theta2);
  if(x == 0 && y == 0)
    return 0;
  else
    return std::atan2(y, x);
}

/**
 * sign function.
 * @return the sign of x. +1 for x > 0, -1 for x < 0, 0 for x == 0
 */
template <typename T>
inline int sign(T x)
{
  if (x > 0)
    return 1;
  else if (x < 0)
    return -1;
  else
    return 0;
}

/**
 * clamp x to the interval [l, u]
 */
template <typename T>
inline T clamp(T l, T x, T u) 
{
  if (x < l)
    return l;
  if (x > u)
    return u;
  return x;
}

/**
 * wrap x to be in the interval [l, u]
 */
template <typename T>
inline T wrap(T l, T x, T u) 
{
  T intervalWidth = u - l;
  while (x < l)
    x += intervalWidth;
  while (x > u)
    x -= intervalWidth;
  return x;
}

/**
 * tests whether there is a NaN in the array
 */
inline bool arrayHasNaN(const double* array, int size, int* nanIndex = 0)
{
  for (int i = 0; i < size; ++i)
    if (g2o_isnan(array[i])) {
      if (nanIndex)
        *nanIndex = i;
      return true;
    }
  return false;
}

/**
 * The following two functions are used to force linkage with static libraries.
 */
extern "C"
{
    typedef void (* ForceLinkFunction) (void);
}

struct ForceLinker
{
    ForceLinker(ForceLinkFunction function) { (function)(); }
};


} // end namespace

// @}

#endif

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SLAM中的小工具 的相关文章

随机推荐

  • MissionPlanner日志保存方法

    闪存日志 目录 闪存日志 日志类型 闪存 VS 数传日志 设置你想要记录的数据 用Mission Planner下载日志 查看内容 详细信息 针对APM Copter 查看KMZ文件 视频教程 日志类型 闪存 VS 数传日志 有两种方法可以
  • Layui的laydate日期组件限制只能选择工作日

    如题 xff0c 在使用Layui的laydate日期组件时 xff0c layui只给我们提供了日期组件的min max配置 xff0c 分别对应最小可选时间和最大可选时间 xff0c 但是如果我们需求是只能选择工作日 xff08 周一至
  • python(5):TypeError: xxx() got an unexpected keyword argument ‘xxx‘

    定义了一个python函数 xff0c 调用时出现报错如下 xff1a Traceback most recent call last File 34 gaussian kernel py 34 line 18 in lt module g
  • 对《Java编程思想》读者的一点建议

    Java 编程思想 这本书在豆瓣的评分高达 9 1 分 xff0c 但我总觉得有点虚高 记得刚上大学那会 xff0c 就在某宝上买了一本影印版的 Java 编程思想 xff0c 但由于初学 Java xff0c 对编程极度缺乏信心 xff0
  • 强烈推荐10本程序员必读的书

    经常有读者私下问我 xff0c 能否推荐几本书 xff0c 以便空闲的时间读一读 于是我跑去自己的书架上筛选了 10 本我最喜欢的书 xff0c 你可以挑选感兴趣的来读一读 01 代码整洁之道 我可以这么肯定地说 xff1a 代码整洁之道
  • 教妹学Java(二十 七):this 关键字的用法

    你好呀 xff0c 我是沉默王二 xff0c xff08 目前是 xff09 CSDN 周排名前十的博客专家 这是 教妹学 Java 专栏的第二十七篇 xff0c 今天我们来谈谈 Java 的 this 关键字 this 关键字有哪些用法
  • PID控制原理

    PID控制原理 PID即 xff1a Proportional xff08 比例 xff09 Integral xff08 积分 xff09 Differential xff08 微分 xff09 的缩写 xff0c PID控制算法是结合比
  • ROS入门:IMU&GPS融合定位实例

    1 声明 xff1a a 本文主要针对IMU amp GPS融合定位仿真环境的搭建过程进行讲解 xff0c 而没有对具体原理的介绍 b 本人作为技术小白 xff0c 完全参考了https zhuanlan zhihu com p 15266
  • vSLAM研究综述:2010-2016

    作为vSLAM领域小白 xff0c 学习完 视觉SLAM十四讲 后 xff0c 抱着学习的心态研究了论文Visual SLAM algorithms a survey from 2010 to 2016 作为入门的第一步 xff0c 会有很
  • ROS学习:cv_bridge与opencv版本冲突三种解决方案

    cv bridge与opencv版本冲突三种解决方案 1 问题描述 xff1a 2 解决方案 xff1a 2 1 不使用cv bridge包2 2 令cv bridge使用opencv版本切换为自己工程所使用的版本2 3 下载cv brid
  • Kubernetes实战指南(三十四): 高可用安装K8s集群1.20.x

    文章目录 1 安装说明2 节点规划3 基本配置4 内核配置5 基本组件安装6 高可用组件安装7 集群初始化8 高可用Master9 添加Node节点10 Calico安装11 Metrics Server部署12 Dashboard部署 1
  • 烤四轴

    烤四轴方法 xff0c 先盗图一张 先调试内环后外环 xff08 不明白自行搜索串级PID xff09 1 在飞机的起飞油门基础上进行 PID 参数的调整 xff1b 2 将角度外环去掉 xff0c 将打舵量作为内环的期望 xff1b 3
  • 最全面的linux信号量解析

    2012 06 28 15 08 285人阅读 评论 0 收藏 编辑 删除 信号量 一 xff0e 什么是信号量 信号量的使用主要是用来保护共享资源 xff0c 使得资源在一个时刻只有一个进程 xff08 线程 xff09 所拥有 信号量的
  • ubuntu(20):xargs:clang-format: 没有那个文件或目录与ubuntu18.04安装clang-format

    1 报错排查 xff1a xargs clang format 没有那个文件或目录 运行脚本中的命令如下 xff1b 需要注意这里的clang format后面没有跟数字 修改前脚本 find dogm demo dogm include
  • ORA-28000 the account is locked处理办法

    启动项目的时候提示ORA 28000 the account is locked 这是因为用户被锁定了 oracle11g中默认在default概要文件中设置了 FAILED LOGIN ATTEMPTS 61 10次 xff0c 当输入密
  • 安卓手机 相机和IMU数据获取标定 在VINS-MONO运行自己的数据集(含打包方法) (非常详细一步一步来)

    Android手机上图像和IMU数据采集的方法 网上有相关的教程 xff0c 但都讲的很模糊 xff0c 而且不全 xff0c 甚至还有人要收费 自己完整做了一遍发现还是有些麻烦 xff0c 固记录下来供大家参考 xff0c 希望能帮到大家
  • ros学习笔记--如何看可视化的话题与节点

    输入 rosrun rqt graph rqt graph 可以打开一个界面观察节点与话题的关系 绿色和蓝色的是节点 红色的是话题
  • opencv 环境相关

    拷贝志强服务器的环境需要配置下opencv 安装opencv的一些依赖项 xff0c 防止编译不通过 1 拷贝的库放在 opt下 xff0c 改名字为libs x64 2 安装opencv的依赖项 sudo apt get install
  • ROS CMakeLists 写法

    SET CMAKE BUILD TYPE 34 Debug 34 SET CMAKE CXX FLAGS DEBUG 34 ENV CXXFLAGS O0 Wall g ggdb 34 SET CMAKE CXX FLAGS RELEASE
  • SLAM中的小工具

    g2o中有用的小工具 ifndef G2O STUFF MISC H define G2O STUFF MISC H include 34 macros h 34 include lt cmath gt ifndef M PI define