【机器人学习】机器人轨迹规划A※算法代码

下载链接

clc
clear all
close all
disp('A Star Path Planing start!!')
p.start=[1,1];  %起始点
p.goal=[10,3];  %目标点
p.XYMAX=11; 
obstacle=GetBoundary(p);%得到边界数据
nObstacle=20;
obstacle=GetObstacle(nObstacle,obstacle,p);
path=AStar(obstacle,p);
figure(1)
if length(obstacle)>=1
    plot(obstacle(:,1),obstacle(:,2),'om');hold on;
end
plot(p.start(1),p.start(2),'*r');hold on;
plot(p.goal(1),p.goal(2),'*b');hold on;
if length(path)>=1
    plot(path(:,1),path(:,2),'-r');hold on;
end

grid on;

function path=AStar(obstacle,p)


path=[];

open=[p.start(1) p.start(2) h(p.start,p.goal) p.start(1) p.start(2)];
close=[];
next=MotionModel();
findFlag=false;%目标标志
while ~findFlag
      if isempty(open(:,1)) disp('No path to goal!!');
       return;
      end
       [Y,I] = sort(open(:,3))
        open=open(I,:);
        if isSamePosi(open(1,1:2),p.goal)
            disp('Find Goal!!');
             close=[open(1,:);close]  
             open(1,:)=[];
             findFlag=true;
          break;
        end
         for in=1:length(next(:,1))
          
          m=[open(1,1)+next(in,1) open(1,2)+next(in,2) open(1,3)];
          %m(3)=m(3)+next(in,3)+h(m(1:2),p.goal)-h(open(1,1:2),p.goal);
          
          m(3)=next(in,3)+h(m(1:2),p.goal);
          if isObstacle(m,obstacle) continue; end
          
         
          [flag, targetInd]=FindList(m,open,close)
       
          if flag==1 
              disp("cao")
              continue;
          elseif flag==2 
              continue;
          else 
              
              open=[open;[m open(1,1) open(1,2)]]
          end
         end
        if findFlag==false
          close=[close; open(1,:)]
          open(1,:)=[];
      end
    
end

path=GetPath(close,p.start);
            




结果展示
在这里插入图片描述
其他代码下载见链接:
在这里插入图片描述
咨询链接:matlab正逆运动学分析与轨迹规划

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CAE工作者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值