-
Notifications
You must be signed in to change notification settings - Fork 448
/
mtraj.m
107 lines (94 loc) · 3.23 KB
/
mtraj.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
95
96
97
98
99
100
101
102
103
104
105
106
107
%MTRAJ Multi-axis trajectory between two points
%
% [Q,QD,QDD] = MTRAJ(TFUNC, Q0, QF, M) is a multi-axis trajectory (MxN) varying
% from configuration Q0 (1xN) to QF (1xN) according to the scalar trajectory function
% TFUNC in M steps. Joint velocity and acceleration can be optionally returned as
% QD (MxN) and QDD (MxN) respectively. The trajectory outputs have one row per
% time step, and one column per axis.
%
% The shape of the trajectory is given by the scalar trajectory function
% TFUNC which is applied to each axis:
% [S,SD,SDD] = TFUNC(S0, SF, M);
% and possible values of TFUNC include @lspb for a trapezoidal trajectory, or
% @tpoly for a polynomial trajectory.
%
% [Q,QD,QDD] = MTRAJ(TFUNC, Q0, QF, T) as above but T (Mx1) is a time
% vector which dictates the number of points on the trajectory.
%
% Notes::
% - If no output arguments are specified Q, QD, and QDD are plotted.
% - When TFUNC is @tpoly the result is functionally equivalent to JTRAJ except
% that no initial velocities can be specified. JTRAJ is computationally a little
% more efficient.
%
% See also JTRAJ, MSTRAJ, LSPB, TPOLY.
% Copyright (C) 1993-2017, by Peter I. Corke
%
% This file is part of The Robotics Toolbox for MATLAB (RTB).
%
% RTB is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RTB is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with RTB. If not, see <http://www.gnu.org/licenses/>.
%
% http://www.petercorke.com
function [S,Sd,Sdd] = mtraj(tfunc, q0, qf, M)
if ~isa(tfunc, 'function_handle')
error('first argument must be a function handle');
end
M0 = M;
if ~isscalar(M)
M = length(M);
end
if numcols(q0) ~= numcols(qf)
error('must be same number of columns in q0 and qf')
end
s = zeros(M, numcols(q0));
sd = zeros(M, numcols(q0));
sdd = zeros(M, numcols(q0));
for i=1:numcols(q0)
% for each axis
[s(:,i),sd(:,i),sdd(:,i)] = tfunc(q0(i), qf(i), M);
end
% - If no output arguments are specified S, SD, and SDD are plotted
% against time.
switch nargout
case 0
clf
if isscalar(M0)
t = [1:M0]';
else
t = M0;
end
subplot(311)
plot(t, s); grid; ylabel('s');
subplot(312)
plot(t, sd); grid; ylabel('sd');
subplot(313)
plot(t, sdd); grid; ylabel('sdd');
if ~isscalar(M0)
xlabel('time')
else
for c=get(gcf, 'Children');
set(c, 'XLim', [1 M0]);
end
end
shg
case 1
S = s;
case 2
S = s;
Sd = sd;
case 3
S = s;
Sd = sd;
Sdd = sdd;
end