当前位置:   article > 正文

机器人局部避障的动态窗口法(dynamic window approach)_dwa算法

dwa算法





  1. 首先在V_m∩V_d的范围内采样速度:
  2. allowable_v = generateWindow(robotV, robotModel)
  3. allowable_w = generateWindow(robotW, robotModel)
  4. 然后根据能否及时刹车剔除不安全的速度:
  5. for each v in allowable_v
  6. for each w in allowable_w
  7. dist = find_dist(v,w,laserscan,robotModel)
  8. breakDist = calculateBreakingDistance(v)//刹车距离
  9. if (dist > breakDist) //如果能够及时刹车,该对速度可接收
  10. 如果这组速度可接受,接下来利用评价函数对其评价,找到最优的速度组

  1. 来源:http://adrianboeing.blogspot.com/2012/05/dynamic-window-algorithm-motion.html
  2. BEGIN DWA(robotPose,robotGoal,robotModel)
  3. laserscan = readScanner()
  4. allowable_v = generateWindow(robotV, robotModel)
  5. allowable_w = generateWindow(robotW, robotModel)
  6. for each v in allowable_v
  7. for each w in allowable_w
  8. dist = find_dist(v,w,laserscan,robotModel)
  9. breakDist = calculateBreakingDistance(v)
  10. if (dist > breakDist) //can stop in time
  11. heading = hDiff(robotPose,goalPose, v,w)
  12. //clearance与原论文稍不一样
  13. clearance = (dist-breakDist)/(dmax - breakDist)
  14. cost = costFunction(heading,clearance, abs(desired_v - v))
  15. if (cost > optimal)
  16. best_v = v
  17. best_w = w
  18. optimal = cost
  19. set robot trajectory to best_v, best_w
  20. END




(转载请注明作者和出处:http://blog.csdn.net/heyijia0327 未经允许请勿用于商业用途)



参考:

dwa:

1.Fox.《The Dynamic Window Approach To CollisionAvoidance》

2.MarijaSeder. 《dynamic window based approach tomobile robot motion control in the presence of moving obstacles》

3.http://adrianboeing.blogspot.com/2012/05/dynamic-window-algorithm-motion.html

 

运动模型:

4. http://adrianboeing.blogspot.com.au/2010/09/circular-motion-in-2d-for-graphics-and.html

5.https://www.cs.princeton.edu/courses/archive/fall11/cos495/COS495-Lecture5-Odometry.pdf

6.http://rossum.sourceforge.net/papers/DiffSteer/


最后贴出matlab仿真代码

  1. % -------------------------------------------------------------------------
  2. %
  3. % File : DynamicWindowApproachSample.m
  4. %
  5. % Discription : Mobile Robot Motion Planning with Dynamic Window Approach
  6. %
  7. % Environment : Matlab
  8. %
  9. % Author : Atsushi Sakai
  10. %
  11. % Copyright (c): 2014 Atsushi Sakai
  12. %
  13. % License : Modified BSD Software License Agreement
  14. % -------------------------------------------------------------------------
  15. function [] = DynamicWindowApproachSample()
  16. close all;
  17. clear all;
  18. disp('Dynamic Window Approach sample program start!!')
  19. x=[0 0 pi/2 0 0]';% 机器人的初期状态[x(m),y(m),yaw(Rad),v(m/s),w(rad/s)]
  20. goal=[10,10];% 目标点位置 [x(m),y(m)]
  21. % 障碍物位置列表 [x(m) y(m)]
  22. % obstacle=[0 2;
  23. % 4 2;
  24. % 4 4;
  25. % 5 4;
  26. % 5 5;
  27. % 5 6;
  28. % 5 9
  29. % 8 8
  30. % 8 9
  31. % 7 9];
  32. obstacle=[0 2;
  33. 4 2;
  34. 4 4;
  35. 5 4;
  36. 5 5;
  37. 5 6;
  38. 5 9
  39. 8 8
  40. 8 9
  41. 7 9
  42. 6 5
  43. 6 3
  44. 6 8
  45. 6 7
  46. 7 4
  47. 9 8
  48. 9 11
  49. 9 6];
  50. obstacleR=0.5;% 冲突判定用的障碍物半径
  51. global dt; dt=0.1;% 时间[s]
  52. % 机器人运动学模型
  53. % 最高速度m/s],最高旋转速度[rad/s],加速度[m/ss],旋转加速度[rad/ss],
  54. % 速度分辨率[m/s],转速分辨率[rad/s]]
  55. Kinematic=[1.0,toRadian(20.0),0.2,toRadian(50.0),0.01,toRadian(1)];
  56. % 评价函数参数 [heading,dist,velocity,predictDT]
  57. evalParam=[0.05,0.2,0.1,3.0];
  58. area=[-1 11 -1 11];% 模拟区域范围 [xmin xmax ymin ymax]
  59. % 模拟实验的结果
  60. result.x=[];
  61. tic;
  62. % movcount=0;
  63. % Main loop
  64. for i=1:5000
  65. % DWA参数输入
  66. [u,traj]=DynamicWindowApproach(x,Kinematic,goal,evalParam,obstacle,obstacleR);
  67. x=f(x,u);% 机器人移动到下一个时刻
  68. % 模拟结果的保存
  69. result.x=[result.x; x'];
  70. % 是否到达目的地
  71. if norm(x(1:2)-goal')<0.5
  72. disp('Arrive Goal!!');break;
  73. end
  74. %====Animation====
  75. hold off;
  76. ArrowLength=0.5;%
  77. % 机器人
  78. quiver(x(1),x(2),ArrowLength*cos(x(3)),ArrowLength*sin(x(3)),'ok');hold on;
  79. plot(result.x(:,1),result.x(:,2),'-b');hold on;
  80. plot(goal(1),goal(2),'*r');hold on;
  81. plot(obstacle(:,1),obstacle(:,2),'*k');hold on;
  82. % 探索轨迹
  83. if ~isempty(traj)
  84. for it=1:length(traj(:,1))/5
  85. ind=1+(it-1)*5;
  86. plot(traj(ind,:),traj(ind+1,:),'-g');hold on;
  87. end
  88. end
  89. axis(area);
  90. grid on;
  91. drawnow;
  92. %movcount=movcount+1;
  93. %mov(movcount) = getframe(gcf);%
  94. end
  95. toc
  96. %movie2avi(mov,'movie.avi');
  97. function [u,trajDB]=DynamicWindowApproach(x,model,goal,evalParam,ob,R)
  98. % Dynamic Window [vmin,vmax,wmin,wmax]
  99. Vr=CalcDynamicWindow(x,model);
  100. % 评价函数的计算
  101. [evalDB,trajDB]=Evaluation(x,Vr,goal,ob,R,model,evalParam);
  102. if isempty(evalDB)
  103. disp('no path to goal!!');
  104. u=[0;0];return;
  105. end
  106. % 各评价函数正则化
  107. evalDB=NormalizeEval(evalDB);
  108. % 最终评价函数的计算
  109. feval=[];
  110. for id=1:length(evalDB(:,1))
  111. feval=[feval;evalParam(1:3)*evalDB(id,3:5)'];
  112. end
  113. evalDB=[evalDB feval];
  114. [maxv,ind]=max(feval);% 最优评价函数
  115. u=evalDB(ind,1:2)';%
  116. function [evalDB,trajDB]=Evaluation(x,Vr,goal,ob,R,model,evalParam)
  117. %
  118. evalDB=[];
  119. trajDB=[];
  120. for vt=Vr(1):model(5):Vr(2)
  121. for ot=Vr(3):model(6):Vr(4)
  122. % 轨迹推测; 得到 xt: 机器人向前运动后的预测位姿; traj: 当前时刻 到 预测时刻之间的轨迹
  123. [xt,traj]=GenerateTrajectory(x,vt,ot,evalParam(4),model); %evalParam(4),前向模拟时间;
  124. % 各评价函数的计算
  125. heading=CalcHeadingEval(xt,goal);
  126. dist=CalcDistEval(xt,ob,R);
  127. vel=abs(vt);
  128. % 制动距离的计算
  129. stopDist=CalcBreakingDist(vel,model);
  130. if dist>stopDist %
  131. evalDB=[evalDB;[vt ot heading dist vel]];
  132. trajDB=[trajDB;traj];
  133. end
  134. end
  135. end
  136. function EvalDB=NormalizeEval(EvalDB)
  137. % 评价函数正则化
  138. if sum(EvalDB(:,3))~=0
  139. EvalDB(:,3)=EvalDB(:,3)/sum(EvalDB(:,3));
  140. end
  141. if sum(EvalDB(:,4))~=0
  142. EvalDB(:,4)=EvalDB(:,4)/sum(EvalDB(:,4));
  143. end
  144. if sum(EvalDB(:,5))~=0
  145. EvalDB(:,5)=EvalDB(:,5)/sum(EvalDB(:,5));
  146. end
  147. function [x,traj]=GenerateTrajectory(x,vt,ot,evaldt,model)
  148. % 轨迹生成函数
  149. % evaldt:前向模拟时间; vt、ot当前速度和角速度;
  150. global dt;
  151. time=0;
  152. u=[vt;ot];% 输入值
  153. traj=x;% 机器人轨迹
  154. while time<=evaldt
  155. time=time+dt;% 时间更新
  156. x=f(x,u);% 运动更新
  157. traj=[traj x];
  158. end
  159. function stopDist=CalcBreakingDist(vel,model)
  160. % 根据运动学模型计算制动距离,这个制动距离并没有考虑旋转速度,不精确吧!!!
  161. global dt;
  162. stopDist=0;
  163. while vel>0
  164. stopDist=stopDist+vel*dt;% 制动距离的计算
  165. vel=vel-model(3)*dt;%
  166. end
  167. function dist=CalcDistEval(x,ob,R)
  168. % 障碍物距离评价函数
  169. dist=100;
  170. for io=1:length(ob(:,1))
  171. disttmp=norm(ob(io,:)-x(1:2)')-R;%僷僗偺埵抲偲忈奞暔偲偺僲儖儉岆嵎傪寁嶼
  172. if dist>disttmp% 离障碍物最小的距离
  173. dist=disttmp;
  174. end
  175. end
  176. % 障碍物距离评价限定一个最大值,如果不设定,一旦一条轨迹没有障碍物,将太占比重
  177. if dist>=2*R
  178. dist=2*R;
  179. end
  180. function heading=CalcHeadingEval(x,goal)
  181. % heading的评价函数计算
  182. theta=toDegree(x(3));% 机器人朝向
  183. goalTheta=toDegree(atan2(goal(2)-x(2),goal(1)-x(1)));% 目标点的方位
  184. if goalTheta>theta
  185. targetTheta=goalTheta-theta;% [deg]
  186. else
  187. targetTheta=theta-goalTheta;% [deg]
  188. end
  189. heading=180-targetTheta;
  190. function Vr=CalcDynamicWindow(x,model)
  191. %
  192. global dt;
  193. % 车子速度的最大最小范围
  194. Vs=[0 model(1) -model(2) model(2)];
  195. % 根据当前速度以及加速度限制计算的动态窗口
  196. Vd=[x(4)-model(3)*dt x(4)+model(3)*dt x(5)-model(4)*dt x(5)+model(4)*dt];
  197. % 最终的Dynamic Window
  198. Vtmp=[Vs;Vd];
  199. Vr=[max(Vtmp(:,1)) min(Vtmp(:,2)) max(Vtmp(:,3)) min(Vtmp(:,4))];
  200. function x = f(x, u)
  201. % Motion Model
  202. % u = [vt; wt];当前时刻的速度、角速度
  203. global dt;
  204. F = [1 0 0 0 0
  205. 0 1 0 0 0
  206. 0 0 1 0 0
  207. 0 0 0 0 0
  208. 0 0 0 0 0];
  209. B = [dt*cos(x(3)) 0
  210. dt*sin(x(3)) 0
  211. 0 dt
  212. 1 0
  213. 0 1];
  214. x= F*x+B*u;
  215. function radian = toRadian(degree)
  216. % degree to radian
  217. radian = degree/180*pi;
  218. function degree = toDegree(radian)
  219. % radian to degree
  220. degree = radian/pi*180;



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/386721
推荐阅读
相关标签
  

闽ICP备14008679号