当前位置: 首页 > news >正文

轨迹规划——估计规划轨迹曲率代码实现

已经知道轨迹(x,y,theta)一系列点集合,根据之前一篇文章:

Estimating the Trajectory Curvature Using Three Trajectory Points Output From Motion Planning

代码如下:

#include<iostream>
#include<vector>
#include<math.h>
using namespace std;struct point
{double x;double y;double theta;
};int main()
{vector<point> path;point point_temp;double R;std::cout << "请输入一个圆的曲率半径的R:" << std::endl;cin>>R;std::cout << "曲率 curve is" << 1/R << std::endl;double x,y;double phi = 0;while(phi < 3.14){	x = R * cos(phi);y = R * sin(phi);phi += 0.5;std::cout << "x =" << x << " " << "y =" << y  << "phi = " << phi << std::endl; point_temp.x = x;point_temp.y = y;point_temp.theta = phi;path.push_back(point_temp);}/*//first pointpoint_temp.x = 9;point_temp.y = ;point_temp.theta = 0.5;	path.push_back(point_temp);//second pointpoint_temp.x = 1.3;point_temp.y = 2.5;point_temp.theta = 0.7;path.push_back(point_temp);//third pointpoint_temp.x = 1.7;point_temp.y = 2.9;point_temp.theta = 2.0;path.push_back(point_temp);*///calculate Path Curveint i = 1;double phi_error = path[i+1].theta - path[i-1].theta;double dist_1 =  (path[i].x - path[i-1].x) * (path[i].x - path[i-1].x) + (path[i].y - path[i-1].y) *  (path[i].y - path[i-1].y);double dist_2 =  (path[i+1].x - path[i].x) * (path[i+1].x - path[i].x) + (path[i+1].y - path[i].y) *  (path[i+1].y - path[i].y);double curve = phi_error/(sqrt(dist_1) + sqrt(dist_2));std::cout << "算法估计的曲率是:" << curve << std::endl;} 

这段代码模拟一个圆形轨迹,曲率固定为圆去测试。

	vector<point> path;point point_temp;double R;std::cout << "请输入一个圆的曲率半径的R:" << std::endl;cin>>R;std::cout << "曲率 curve is" << 1/R << std::endl;double x,y;double phi = 0;while(phi < 3.14){	x = R * cos(phi);y = R * sin(phi);phi += 0.5;std::cout << "x =" << x << " " << "y =" << y  << "phi = " << phi << std::endl; point_temp.x = x;point_temp.y = y;point_temp.theta = phi;path.push_back(point_temp);}

利用上述的几个点,去验证下面估计的曲率。

	//calculate Path Curveint i = 1;double phi_error = path[i+1].theta - path[i-1].theta;double dist_1 =  (path[i].x - path[i-1].x) * (path[i].x - path[i-1].x) + (path[i].y - path[i-1].y) *  (path[i].y - path[i-1].y);double dist_2 =  (path[i+1].x - path[i].x) * (path[i+1].x - path[i].x) + (path[i+1].y - path[i].y) *  (path[i+1].y - path[i].y);double curve = phi_error/(sqrt(dist_1) + sqrt(dist_2));std::cout << "算法估计的曲率是:" << curve << std::endl;

输出结果:

在这里插入图片描述


http://www.mrgr.cn/news/29678.html

相关文章:

  • 安科瑞工业绝缘监测装置:保障煤矿井下6kV供电系统安全运行的关键应用——安科瑞 丁佳雯
  • 动手学深度学习10.1. 注意力提示-笔记练习(PyTorch)
  • Transformer-GRU、Transformer、CNN-GRU、GRU、CNN五模型多变量回归预测
  • 【Android】View—基础知识,滑动,弹性滑动
  • 深入探讨 MySQL 配置与优化:从零到生产环境的最佳实践20241112
  • 关于指针p有关的3个值
  • 数据结构之结构体
  • bmp格式图片怎么转换jpg?这几种转换方法超级好用!
  • 保护您的企业免受网络犯罪分子侵害的四个技巧
  • Stream流操作
  • RabbitMQ:交换机详解(Fanout交换机、Direct交换机、Topic交换机)
  • TMStarget学习——T1 Segmentation数据处理及解bug
  • 揭秘AI+RPA:CSDN 自动登录 RPA 的实现之道
  • 【多模态大模型】社招秋招实习 -- 快手招聘!
  • Java--stream流、方法引用
  • vue 数组转字符串以逗号分隔
  • JVM相关
  • 【Git】远程仓库
  • C++中为什么构造函数和析构函数不允许调用虚函数?
  • 浅谈Spring Cloud:Nacos的配置
  • do { ... } while (0) 的意义
  • etsts
  • 英飞凌—TC377芯片详解(2)
  • 「全球大模型竞技场」更新:DeepSeek-V2.5全面领跑国内模型
  • Uinty Collider 有几种?
  • nonlocal本质讲解(前篇)——从滤波到Nonlocal均值滤波