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

基于路径长度的样条插补算法(自动驾驶和路径跟踪控制适用)

以前在做车辆跟踪控制的时候发现在针对有多个X和多个Y对应的路径插补时候,总是报错,因为MATLAB里面的interp1插补函数它要求x要唯一对应一个y,当路径以单独的x或者y来求插补时候的时候就报错。由于在使用Matlab的interp1函数进行插值时,采样点必须是唯一的,否则可能会出现问题。如果输入的采样点包含重复的值,interp1函数可能无法确定应该在哪个点进行插值。这会导致函数返回错误或不确定的结果。为了解决这个问题,你可以先对输入的采样点进行处理,确保它们是唯一的。你可以使用Matlab的unique函数来去除重复值,或者通过其他方法确保采样点的唯一性。

针对这个问题,我根据路径的长度来插补,而不是利用单一的x或者单一的y。在遇到类似的情况时候,也可以用范数来插补。具体代码如下

clc,clear
close all
cx = [];
cy= [];
x0 = @(t_step) 15*sin(2 * t_step + 1);
y0 = @(t_step) -20*cos(t_step + 0.5);
for theta=0.9*pi:pi/200:1.8*picx(end + 1) = x0(theta);cy(end + 1) = y0(theta);
end
refer_path_primary= [cx', cy'];
x = refer_path_primary(:, 1)';
y = refer_path_primary(:, 2)';
points = [x; y]';
ds = 0.01 ;%等距插值处理的间隔
distance = [0, cumsum(hypot(diff(x, 1), diff(y, 1)))]';
distance_specific = 0:ds:distance(end);
hypot(diff(x, 1), diff(y, 1));
diff(x, 1);
diff(y, 1);
s = 0:ds:distance(end);
refer_path= interp1(distance, points, distance_specific, 'spline');
len_path = length(refer_path);
refer_path_x = refer_path(:,1);  % x
refer_path_y = refer_path(:,2); % y
for i=1:length(refer_path)if i==1dx = refer_path(i + 1, 1) - refer_path(i, 1);dy = refer_path(i + 1, 2) - refer_path(i, 2);ddx = refer_path(3, 1) + refer_path(1, 1) - 2 * refer_path(2, 1);ddy = refer_path(3, 2) + refer_path(1, 2) - 2 * refer_path(2, 2);elseif  i==length(refer_path)dx = refer_path(i, 1) - refer_path(i - 1, 1);dy = refer_path(i, 2) - refer_path(i - 1, 2);ddx = refer_path(i, 1) + refer_path(i - 2, 1) - 2 * refer_path(i - 1, 1);ddy = refer_path(i, 2) + refer_path(i - 2, 2) - 2 * refer_path(i - 1, 2);elsedx = refer_path(i + 1, 1) - refer_path(i, 1);dy = refer_path(i + 1, 2) - refer_path(i, 2);ddx = refer_path(i + 1, 1) + refer_path(i - 1, 1) - 2 * refer_path(i, 1);ddy = refer_path(i + 1, 2) + refer_path(i - 1, 2) - 2 * refer_path(i, 2);endrefer_path(i,3)=atan2(dy, dx);%refer_path(i,4)=(ddy * dx - ddx * dy) / ((dx ^ 2 + dy ^ 2) ^ (3 / 2));refer_path(i,5) = dx;refer_path(i,6) = dy;
end
for i=1:length(refer_path)if i==1dphai = refer_path(i + 1, 3) - refer_path(i, 3);elseif  i==length(refer_path)dphai = refer_path(i, 3) - refer_path(i - 1, 3);elsedphai = refer_path(i + 1, 3) - refer_path(i, 3);endrefer_path(i, 7) = dphai;%yaw
end
x_d=refer_path_x;
y_d=refer_path_y;
phai_d = refer_path(:, 3);
dx_d = refer_path(:, 5);
dy_d = refer_path(:, 6);
dphai_d = refer_path(:, 7);
figure(1)
plot(refer_path(:, 1), refer_path(:,2), Color='m',LineStyle='--',LineWidth=2)
axis equal
grid on

http://www.lryc.cn/news/388832.html

相关文章:

  • net Framework OAuth2.0
  • 速盾:服务器cdn加速超时如何解决?
  • 2024年6月总结及随笔之打卡网红点
  • 《Windows API每日一练》7.4 状态报告上使用计时器
  • python实现API调用缓存
  • 传输距离3000M|低延迟|48K采样音频传输模块-SA356大功率发射模块
  • 前端css性能优化
  • 如何在Windows上使用Docker搭建PHP开发环境
  • java 单例模式
  • 爬虫 属性 方法
  • HEX文件
  • 人机融合的智能操作系统
  • 数据结构之二叉树概念
  • Linux源码阅读笔记08-进程调度API系统调用案例分析
  • 短视频抓取:成都柏煜文化传媒有限公司
  • proto的前后端使用
  • 华为解决固态硬盘致命弱点:延长30~50%的SSD寿命
  • 登录验证码高扩展性设计方案
  • Spring MVC数据绑定和响应——数据回写(一)普通字符串的回写
  • 怎样才能更好地保护个人账号的安全
  • react native优质开源项目
  • 速盾:海外cdn有哪些优缺点呢?
  • Unity Shader 软粒子
  • nextTick的应用和原理理解
  • .Net Core 微服务之Consul
  • 速盾:cdn流量调度
  • Windows批处理入门:快速掌握批处理脚本的基本技巧
  • 【C++之unordered_set和unordered_map的模拟实现】
  • 服务器使用别人的conda
  • 农村程序员陈随易2024年中总结