-
Notifications
You must be signed in to change notification settings - Fork 4
/
ex2_pos_backandforth.m
60 lines (51 loc) · 1.19 KB
/
ex2_pos_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
clear; close all;
trajType = 'pos'; % for given position constraints
tmove = 1; % moving time
tdwell = 1; % dwelling time
% time boundary conditions
BCt = [tdwell, ... % dwell
tdwell+tmove, ... % step motion
tdwell+tmove+tdwell, ... % dwell
tdwell+tmove+tdwell+tmove,... % step motion
];
BCt = [BCt,BCt+BCt(end)]; % twice
% motion distance
pmove = 0.3;
% position boundary conditions
BCp = [0, pmove, pmove, 0];
BCp = [BCp,BCp]; % twice
% polynomial order
np = 5;
% Polynomial Trajectory generation
pBasis = backandforth(trajType,BCt,BCp,np);
%% Plot
Ts = 1e-3;
t = 0:Ts:9;
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
scatter(BCt,BCp, 'b', 'filled');
xlabel('time [s]');
title('position');
subplot(2,2,2);
plot(t,y2,'b-');
xlabel('time [s]');
title('velocity');
subplot(2,2,3);
plot(t,y3,'b-');
xlabel('time [s]');
title('acceleration');
subplot(2,2,4);
plot(t,y4,'b-');
xlabel('time [s]');
title('jerk');
% FigTools required
% https://github.com/ThomasBeauduin/FigTools
if exist('pubfig','file')
pfig = pubfig(hfig);
expfig('ex2','-png');
end