机器人控制算法——TEB算法障碍物检测分析

2023-11-02 09:36

本文主要是介绍机器人控制算法——TEB算法障碍物检测分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.Background

在规划路线的时,需要机器人路线附近的障碍物距离,机器人控制系统需要知道当前机器人与障碍物最短的距离。本文主要是分析如何计算机器人与障碍物的距离,如果将机器人和障碍物分别考虑成质点,机器人与障碍物的距离就很容易求解了,但是事实上,障碍物与机器人在实际工程中不可能是质点。因此,本文需要解决的是:
机器人形状分别圆形、线性、多边形,障碍物也分别是圆形、线性、多边形时,二者的最小距离求解。

2.Algorithm

TEB算法的障碍物程序的入口在此处:

void TebOptimalPlanner::AddEdgesObstacles(double weight_multiplier){if (cfg_->optim.weight_obstacle==0 || weight_multiplier==0 || obstacles_==nullptr )return; // if weight equals zero skip adding edges!bool inflated = cfg_->obstacles.inflation_dist > cfg_->obstacles.min_obstacle_dist;Eigen::Matrix<double,1,1> information;information.fill(cfg_->optim.weight_obstacle * weight_multiplier);//mat.fill(n) 将 mat 的所有元素均赋值为 nEigen::Matrix<double,2,2> information_inflated;information_inflated(0,0) = cfg_->optim.weight_obstacle * weight_multiplier;information_inflated(1,1) = cfg_->optim.weight_inflation;information_inflated(0,1) = information_inflated(1,0) = 0;std::vector<Obstacle*> relevant_obstacles;relevant_obstacles.reserve(obstacles_->size());// iterate all teb points (skip first and last)for (int i=1; i < teb_.sizePoses()-1; ++i){double left_min_dist = std::numeric_limits<double>::max();double right_min_dist = std::numeric_limits<double>::max();Obstacle* left_obstacle = nullptr;Obstacle* right_obstacle = nullptr;relevant_obstacles.clear();const Eigen::Vector2d pose_orient = teb_.Pose(i).orientationUnitVec();// iterate obstaclesfor (const ObstaclePtr& obst : *obstacles_){// we handle dynamic obstacles differently below  //我们以不同的方式处理下面的动态障碍if(cfg_->obstacles.include_dynamic_obstacles && obst->isDynamic())continue;// calculate distance to robot model// //! 根据不同的机器人模型(点,圆,多边形等),不同的障碍物模型(点,线,多边形),有不同的距离计算方法double dist = robot_model_->calculateDistance(teb_.Pose(i), obst.get());
1. 机器人是圆形时
(1)障碍物是圆形时:
        /*** @brief Calculate the distance between the robot and an obstacle* @param current_pose Current robot pose* @param obstacle Pointer to the obstacle* @return Euclidean distance to the robot*/virtual double calculateDistance(const PoseSE2& current_pose, const Obstacle* obstacle) const{return obstacle->getMinimumDistance(current_pose.position()) - radius_;}
        // implements getMinimumDistance() of the base classvirtual double getMinimumDistance(const Eigen::Vector2d& position) const{return (position-pos_).norm() - radius_;}

使用机器人坐标计算出机器人坐标与障碍物坐标的距离,然后再分别减去机器人的半径radius_和障碍物的半径radius_即可

(2)障碍物是多边形
 virtual double getMinimumDistance(const Eigen::Vector2d& position) const{return distance_point_to_polygon_2d(position, vertices_);}
/*** @brief Helper function to calculate the smallest distance between a point and a closed polygon* @param point 2D point* @param vertices Vertices describing the closed polygon (the first vertex is not repeated at the end)* @return smallest distance between point and polygon
*/inline double distance_point_to_polygon_2d(const Eigen::Vector2d& point, const Point2dContainer& vertices){double dist = HUGE_VAL;// the polygon is a pointif (vertices.size() == 1){return (point - vertices.front()).norm();}// check each polygon edgefor (int i=0; i<(int)vertices.size()-1; ++i){double new_dist = distance_point_to_segment_2d(point, vertices.at(i), vertices.at(i+1));
//       double new_dist = calc_distance_point_to_segment( position,  vertices.at(i), vertices.at(i+1));if (new_dist < dist)dist = new_dist;}if (vertices.size()>2) // if not a line close polygon 数组头和尾顶点的边也要算上{double new_dist = distance_point_to_segment_2d(point, vertices.back(), vertices.front()); // check last edgeif (new_dist < dist)return new_dist;}return dist;}

position是机器人圆心位置坐标,vertices_为多边形的顶点,我们会使用循环计算出来,机器人位置与多边形的每条边的距离(本质就是点到直线距离的求解),然后取最小,最小的距离再减去机器人圆形的半径就是机器人距离障碍物的最小距离。

2. 机器人是多变形
障碍物是多边形时,这种是最复杂的情况求解。
          * @brief Calculate the distance between the robot and an obstacle* @param current_pose Current robot pose* @param obstacle Pointer to the obstacle* @return Euclidean distance to the robot*/virtual double calculateDistance(const PoseSE2& current_pose, const Obstacle* obstacle) const{Point2dContainer polygon_world(vertices_.size());transformToWorld(current_pose, polygon_world);return obstacle->getMinimumDistance(polygon_world);}
       // implements getMinimumDistance() of the base classvirtual double getMinimumDistance(const Point2dContainer& polygon) const{return distance_polygon_to_polygon_2d(polygon, vertices_);}

polygon代表机器人的多边形形状的顶点, vertices_代表障碍物的多边形的顶点。

/*** @brief Helper function to calculate the smallest distance between two closed polygons* @param vertices1 Vertices describing the first closed polygon (the first vertex is not repeated at the end)* @param vertices2 Vertices describing the second closed polygon (the first vertex is not repeated at the end)* @return smallest distance between point and polygon
*/inline double distance_polygon_to_polygon_2d(const Point2dContainer& vertices1, const Point2dContainer& vertices2){double dist = HUGE_VAL;// the polygon1 is a pointif (vertices1.size() == 1){return distance_point_to_polygon_2d(vertices1.front(), vertices2);}// check each edge of polygon1for (int i=0; i<(int)vertices1.size()-1; ++i){double new_dist = distance_segment_to_polygon_2d(vertices1[i], vertices1[i+1], vertices2);if (new_dist < dist)dist = new_dist;}if (vertices1.size()>2) // if not a line close polygon1{double new_dist = distance_segment_to_polygon_2d(vertices1.back(), vertices1.front(), vertices2); // check last edgeif (new_dist < dist)return new_dist;}return dist;}

这个代码的思路就是,以障碍物的顶点为准,然后循环计算该顶点和机器人的多边形每个边的距离(本质也是点到直线距离,很容易求解)并记录最短距离,然后障碍物的顶点遍历完即可,这样找对了最小距离。

3.Summary

上述没有介绍全,机器人有好多形状,障碍物也有好多形状,二者随机组合,就会出现不同的距离求解方法,具体可去看TEB开源代码。

这篇关于机器人控制算法——TEB算法障碍物检测分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/329697

相关文章

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

康拓展开(hash算法中会用到)

康拓展开是一个全排列到一个自然数的双射(也就是某个全排列与某个自然数一一对应) 公式: X=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[i]*(i-1)!+...+a[1]*0! 其中,a[i]为整数,并且0<=a[i]<i,1<=i<=n。(a[i]在不同应用中的含义不同); 典型应用: 计算当前排列在所有由小到大全排列中的顺序,也就是说求当前排列是第

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

【数据结构】——原来排序算法搞懂这些就行,轻松拿捏

前言:快速排序的实现最重要的是找基准值,下面让我们来了解如何实现找基准值 基准值的注释:在快排的过程中,每一次我们要取一个元素作为枢纽值,以这个数字来将序列划分为两部分。 在此我们采用三数取中法,也就是取左端、中间、右端三个数,然后进行排序,将中间数作为枢纽值。 快速排序实现主框架: //快速排序 void QuickSort(int* arr, int left, int rig

poj 3974 and hdu 3068 最长回文串的O(n)解法(Manacher算法)

求一段字符串中的最长回文串。 因为数据量比较大,用原来的O(n^2)会爆。 小白上的O(n^2)解法代码:TLE啦~ #include<stdio.h>#include<string.h>const int Maxn = 1000000;char s[Maxn];int main(){char e[] = {"END"};while(scanf("%s", s) != EO

烟火目标检测数据集 7800张 烟火检测 带标注 voc yolo

一个包含7800张带标注图像的数据集,专门用于烟火目标检测,是一个非常有价值的资源,尤其对于那些致力于公共安全、事件管理和烟花表演监控等领域的人士而言。下面是对此数据集的一个详细介绍: 数据集名称:烟火目标检测数据集 数据集规模: 图片数量:7800张类别:主要包含烟火类目标,可能还包括其他相关类别,如烟火发射装置、背景等。格式:图像文件通常为JPEG或PNG格式;标注文件可能为X

秋招最新大模型算法面试,熬夜都要肝完它

💥大家在面试大模型LLM这个板块的时候,不知道面试完会不会复盘、总结,做笔记的习惯,这份大模型算法岗面试八股笔记也帮助不少人拿到过offer ✨对于面试大模型算法工程师会有一定的帮助,都附有完整答案,熬夜也要看完,祝大家一臂之力 这份《大模型算法工程师面试题》已经上传CSDN,还有完整版的大模型 AI 学习资料,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

dp算法练习题【8】

不同二叉搜索树 96. 不同的二叉搜索树 给你一个整数 n ,求恰由 n 个节点组成且节点值从 1 到 n 互不相同的 二叉搜索树 有多少种?返回满足题意的二叉搜索树的种数。 示例 1: 输入:n = 3输出:5 示例 2: 输入:n = 1输出:1 class Solution {public int numTrees(int n) {int[] dp = new int