-
Notifications
You must be signed in to change notification settings - Fork 4
/
ex4_acc_backandforth.m
69 lines (61 loc) · 1.71 KB
/
ex4_acc_backandforth.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
clear; close all;
trajType = 'acc'; % for given acceleration constraints
tjrk = 1.5; % jrk time
tconstacc = 1; % constant acceleration time
tconstvel = 1; % constant velocity time
tdwell = 0.5; % dwelling time
% time boundary conditions
BCt = [tdwell,... % dwell
tdwell+tjrk,... % jrk
tdwell+tjrk+tconstacc,... % const acc
tdwell+tjrk+tconstacc+tjrk,... % jrk
tdwell+tjrk+tconstacc+tjrk+tconstvel,... % const vel
tdwell+tjrk+tconstacc+tjrk+tconstvel+tjrk,... % jrk
tdwell+tjrk+tconstacc+tjrk+tconstvel+tjrk+tconstacc,... % const acc
tdwell+tjrk+tconstacc+tjrk+tconstvel+tjrk+tconstacc+tjrk,... % jrk
];
BCt = [BCt,BCt+BCt(end)]; % go and back
% max acceleration
amax = 1; % m/s
% acceleration boundary conditions
BCa = [0, amax, amax, 0, 0, -amax, -amax, 0];
BCa = [BCa, -BCa];
% polynomial order for acceleration trajectory
np = 3;
% Polynomial Trajectory generation
BC = cell(2,1);
BC{1} = 0; % initial position
BC{2} = 0; % initial velocity
BC{3} = BCa; % acceleration boundary conditions
pBasis = backandforth(trajType,BCt,BC,np);
%% Plot
Ts = 1e-3;
t = 0:Ts:20;
y1 = outPolyBasis(pBasis,1,t);
y2 = outPolyBasis(pBasis,2,t);
y3 = outPolyBasis(pBasis,3,t);
y4 = outPolyBasis(pBasis,4,t);
hfig = figure;
subplot(2,2,1);
plot(t,y1,'b'); hold on;
xlabel('time [s]');
title('position');
subplot(2,2,2);
plot(t,y2,'b'); hold on;
xlabel('time [s]');
title('velocity');
subplot(2,2,3);
plot(t,y3,'b'); hold on;
scatter(BCt,BCa, 'b', 'filled');
xlabel('time [s]');
title('acceleration');
subplot(2,2,4);
plot(t,y4,'b'); hold on;
xlabel('time [s]');
title('jerk');
% FigTools required
% https://github.com/ThomasBeauduin/FigTools
if exist('pubfig','file')
pfig = pubfig(hfig);
expfig('ex4','-png');
end