机器人控制算法——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

相关文章

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

Python如何实现PDF隐私信息检测

《Python如何实现PDF隐私信息检测》随着越来越多的个人信息以电子形式存储和传输,确保这些信息的安全至关重要,本文将介绍如何使用Python检测PDF文件中的隐私信息,需要的可以参考下... 目录项目背景技术栈代码解析功能说明运行结php果在当今,数据隐私保护变得尤为重要。随着越来越多的个人信息以电子形

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep

SpringBoot使用Apache Tika检测敏感信息

《SpringBoot使用ApacheTika检测敏感信息》ApacheTika是一个功能强大的内容分析工具,它能够从多种文件格式中提取文本、元数据以及其他结构化信息,下面我们来看看如何使用Ap... 目录Tika 主要特性1. 多格式支持2. 自动文件类型检测3. 文本和元数据提取4. 支持 OCR(光学

利用Python编写一个简单的聊天机器人

《利用Python编写一个简单的聊天机器人》这篇文章主要为大家详细介绍了如何利用Python编写一个简单的聊天机器人,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 使用 python 编写一个简单的聊天机器人可以从最基础的逻辑开始,然后逐步加入更复杂的功能。这里我们将先实现一个简单的

Redis主从/哨兵机制原理分析

《Redis主从/哨兵机制原理分析》本文介绍了Redis的主从复制和哨兵机制,主从复制实现了数据的热备份和负载均衡,而哨兵机制可以监控Redis集群,实现自动故障转移,哨兵机制通过监控、下线、选举和故... 目录一、主从复制1.1 什么是主从复制1.2 主从复制的作用1.3 主从复制原理1.3.1 全量复制

Python中的随机森林算法与实战

《Python中的随机森林算法与实战》本文详细介绍了随机森林算法,包括其原理、实现步骤、分类和回归案例,并讨论了其优点和缺点,通过面向对象编程实现了一个简单的随机森林模型,并应用于鸢尾花分类和波士顿房... 目录1、随机森林算法概述2、随机森林的原理3、实现步骤4、分类案例:使用随机森林预测鸢尾花品种4.1

Redis主从复制的原理分析

《Redis主从复制的原理分析》Redis主从复制通过将数据镜像到多个从节点,实现高可用性和扩展性,主从复制包括初次全量同步和增量同步两个阶段,为优化复制性能,可以采用AOF持久化、调整复制超时时间、... 目录Redis主从复制的原理主从复制概述配置主从复制数据同步过程复制一致性与延迟故障转移机制监控与维

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re