-
Notifications
You must be signed in to change notification settings - Fork 13
/
main_path_planning.m
94 lines (77 loc) · 2.55 KB
/
main_path_planning.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
% main algorithm for Frenet path planning
clc
clear
close all
set(0,'DefaultLineLineWidth',1);
disp('Optimal Frenet Path Planning')
%% 2.set up the trajectory
% 2.1 set up the track
w_x=[0.0, 10.0, 20.5, 30.0, 40.5, 50.0, 60.0];
w_y=[0.0, -4.0, 1.0, 6.5, 9.0, 10.0, 6.0];
% w_x=[0.0 10.0 20.5 35.0 70.5]
% w_y=[0 -6 5 6.5 0]
figure(1)
plot(w_x,w_y)
% 2.2 set up the obstacle
ob=[20.0, 10.0 ;
30.0, 6.0 ;
30.0, 5.0 ;
35.0, 7.0 ;
50.0, 12.0 ] ;
hold on
plot(ob(:,1),ob(:,2),'*r')
% 2.3 create a reference track
ds=0.1; %discrete step size
GenerateTargetCourse = @(wx, wy) calcSplineCourse(wx, wy, ds);
[RefX, RefY, RefYaw, RefCurvature, runningLength, referencePath]=...
GenerateTargetCourse(w_x, w_y);
hold on
plot(RefX(1,:),RefY(1,:),'*r')
% [rx, ry, ryaw, rk, s, oSpline]=calcSplineCourse(x,y,ds);
% Initial state
s0_d=10.0 / 3.6; % current speed [m/s]
d0 = 2.0; % current lateral position [m]
d0_d=0; % current lateral speed [m/s]
d0_dd = 0; % current lateral acceleration [m/s^2]
s0= 0; % current course position[m]
area=20; % animation area length[m]
objFrenetPlanner = OptimalFrenetPlanner();
show_animation=true;
if show_animation
figure
end
writerObj=VideoWriter('test.avi'); %// 定义一个视频文件用来存动画
open(writerObj); %// 打开该视频文件
%start simulation
T=500;
for t = 1:T
t;
trajectory = objFrenetPlanner.FrenetOptimalPlanning (...
referencePath, s0, s0_d, d0, d0_d, d0_dd, ob);
%store the updated state of the planned trajectorut as initial
%state of next iteration for the new trajectory
s0 = trajectory.s(2);
s0_d= trajectory.ds(2);
d0 = trajectory.d(2);
d0_d = trajectory.dd(2);
d0_dd=trajectory.ddd(2);
if(show_animation)
cla;
plot(RefX,RefY);
hold on
axis equal
plot(ob(:,1),ob(:,2),'xk')
plot(trajectory.x(1:end),trajectory.y(1:end), '-ob');
% plot(trajectory.x(1), trajectory.y(1), 'vc');
grid on
drawnow
if(sqrt((trajectory.x(1)-RefX(end))^2+(trajectory.y(1)-RefY(end))^2)<2.0)
print("complete goal")
close(writerObj); %// 关闭视频文件句柄
break
end
frame = getframe; %// 把图像存入视频文件中
frame.cdata = imresize(frame.cdata, [653 514]); %重新定义帧大小
writeVideo(writerObj,frame); %// 将帧写入视频
end
end