plateform
stringclasses 1
value | repo_name
stringlengths 13
113
| name
stringlengths 3
74
| ext
stringclasses 1
value | path
stringlengths 12
229
| size
int64 23
843k
| source_encoding
stringclasses 9
values | md5
stringlengths 32
32
| text
stringlengths 23
843k
|
---|---|---|---|---|---|---|---|---|
github
|
RobinAmsters/GT_mobile_robotics-master
|
ikcon.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/ikcon.m
| 4,777 |
utf_8
|
6280fb801405a6b8a91539e63609e98f
|
%SerialLink.IKCON Inverse kinematics by optimization with joint limits
%
% Q = R.ikcon(T, OPTIONS) are the joint coordinates (1xN) corresponding to
% the robot end-effector pose T which is an SE3 object or homogenenous
% transform matrix (4x4), and N is the number of robot joints. OPTIONS is
% an optional list of name/value pairs than can be passed to fmincon.
%
% Q = robot.ikunc(T, Q0, OPTIONS) as above but specify the
% initial joint coordinates Q0 used for the minimisation.
%
% [Q,ERR] = robot.ikcon(T, ...) as above but also returns ERR which is the
% scalar final value of the objective function.
%
% [Q,ERR,EXITFLAG] = robot.ikcon(T, ...) as above but also returns the
% status EXITFLAG from fmincon.
%
% [Q,ERR,EXITFLAG,OUTPUT] = robot.ikcon(T, ...) as above but also returns
% a structure with information such as total number of iterations, and final
% objective function value. See the documentation of fmincon for a complete list.
%
% Trajectory operation::
%
% In all cases if T is a vector of SE3 objects (1xM) or a homogeneous transform
% sequence (4x4xM) then returns the joint coordinates corresponding to
% each of the transforms in the sequence. Q is MxN where N is the number
% of robot joints. The initial estimate of Q for each time step is taken as
% the solution from the previous time step.
%
% ERR and EXITFLAG are also Mx1 and indicate the results of optimisation
% for the corresponding trajectory step.
%
% Notes::
% - Requires fmincon from the MATLAB Optimization Toolbox.
% - Joint limits are considered in this solution.
% - Can be used for robots with arbitrary degrees of freedom.
% - In the case of multiple feasible solutions, the solution returned
% depends on the initial choice of Q0.
% - Works by minimizing the error between the forward kinematics of the
% joint angle solution and the end-effector frame as an optimisation.
% The objective function (error) is described as:
% sumsqr( (inv(T)*robot.fkine(q) - eye(4)) * omega )
% Where omega is some gain matrix, currently not modifiable.
%
% Author::
% Bryan Moutrie
%
% See also SerialLink.ikunc, fmincon, SerialLink.ikine, SerialLink.fkine.
% Copyright (C) Bryan Moutrie, 2013-2015
% Licensed under the GNU Lesser General Public License
% see full file for full statement
%
% LICENSE STATEMENT:
%
% This file is part of pHRIWARE.
%
% pHRIWARE 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.
%
% pHRIWARE 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 General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with pHRIWARE. If not, see <http://www.gnu.org/licenses/>.
function [qstar, error_, exitflag_, out_] = ikcon(robot, T, varargin)
% check if Optimization Toolbox exists, we need it
assert( exist('fmincon', 'file')>0, 'rtb:ikcon:nosupport', 'Optimization Toolbox required');
if isa(T, 'SE3')
T = T.T;
end
% create output variables
T_sz = size(T, 3);
qstar = zeros(T_sz, robot.n);
error = zeros(T_sz, 1);
exitflag = zeros(T_sz, 1);
problem.x0 = zeros(1, robot.n);
problem.options = optimoptions('fmincon', ...
'Algorithm', 'active-set', ...
'Display', 'off'); % default options for ikcon
if nargin > 2
% check if there is a q0 passed
if isnumeric(varargin{1}) && length(varargin{1}) == robot.n
problem.x0 = varargin{1};
varargin = varargin(2:end);
end
end
if ~isempty(varargin)
% if given, add optional argument to the list of optimiser options
problem.options = optimoptions(problem.options, varargin{:});
end
% set the joint limit bounds
problem.lb = robot.qlim(:,1);
problem.ub = robot.qlim(:,2);
problem.solver = 'fmincon';
reach = sum(abs([robot.a, robot.d]));
omega = diag([1 1 1 3/reach]);
for t = 1: T_sz
problem.objective = ...
@(x) sumsqr(((T(:,:,t) \ robot.fkine(x).T) - eye(4)) * omega);
[q_t, err_t, ef_t, out] = fmincon(problem);
qstar(t,:) = q_t;
error(t) = err_t;
exitflag(t) = ef_t;
problem.x0 = q_t;
end
if nargout > 1
error_ = error;
end
if nargout > 2
exitflag_ = exitflag
end
if nargout > 3
out_ = out;
end
end
function s = sumsqr(A)
s = sum(A(:).^2);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
accel.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/accel.m
| 3,676 |
utf_8
|
42821333a63ef7022599dba3741d4d4d
|
%SerialLink.accel Manipulator forward dynamics
%
% QDD = R.accel(Q, QD, TORQUE) is a vector (Nx1) of joint accelerations that result
% from applying the actuator force/torque (1xN) to the manipulator robot R in
% state Q (1xN) and QD (1xN), and N is the number of robot joints.
%
% If Q, QD, TORQUE are matrices (KxN) then QDD is a matrix (KxN) where each row
% is the acceleration corresponding to the equivalent rows of Q, QD, TORQUE.
%
% QDD = R.accel(X) as above but X=[Q,QD,TORQUE] (1x3N).
%
% Note::
% - Useful for simulation of manipulator dynamics, in
% conjunction with a numerical integration function.
% - Uses the method 1 of Walker and Orin to compute the forward dynamics.
% - Featherstone's method is more efficient for robots with large numbers
% of joints.
% - Joint friction is considered.
%
% References::
% - Efficient dynamic computer simulation of robotic mechanisms,
% M. W. Walker and D. E. Orin,
% ASME Journa of Dynamic Systems, Measurement and Control, vol. 104, no. 3, pp. 205-211, 1982.
%
% See also SerialLink.fdyn, SerialLink.rne, SerialLink, ode45.
% 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 qdd = accel(robot, Q, qd, torque)
n = robot.n;
if nargin == 2
assert(length(Q) == (3*robot.n), 'RTB:accel:badarg', 'Input vector X is length %d, should be %d (q, qd, tau)', length(Q), 3*robot.n);
% accel(X)
Q = Q(:)'; % make it a row vector
q = Q(1:n);
qd = Q(n+1:2*n);
torque = Q(2*n+1:3*n);
elseif nargin == 4
% accel(Q, qd, torque)
if numrows(Q) > 1
% handle trajectory by recursion
assert(numrows(Q) == numrows(qd), 'RTB:accel:badarg', 'for trajectory q and qd must have same number of rows');
assert(numrows(Q) == numrows(torque), 'RTB:accel:badarg', 'for trajectory q and torque must have same number of rows');
qdd = [];
for i=1:numrows(Q)
qdd = cat(1, qdd, robot.accel(Q(i,:), qd(i,:), torque(i,:))');
end
return
else
q = Q';
if length(q) == n
q = q(:)';
qd = qd(:)';
end
assert(numcols(Q) == n, 'RTB:accel:badarg', 'q must have %d columns', n);
assert(numcols(qd) == robot.n, 'RTB:accel:badarg', 'qd must have %d columns', n);
assert(numcols(torque) == robot.n, 'RTB:accel:badarg', 'torque must have %d columns', n);
end
else
error('RTB:accel:badarg', 'insufficient arguments');
end
% compute current manipulator inertia
% torques resulting from unit acceleration of each joint with
% no gravity.
M = rne(robot, ones(n,1)*q, zeros(n,n), eye(n), 'gravity', [0 0 0]);
% compute gravity and coriolis torque
% torques resulting from zero acceleration at given velocity &
% with gravity acting.
tau = rne(robot, q, qd, zeros(1,n));
qdd = M \ (torque - tau)';
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
itorque.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/itorque.m
| 1,454 |
utf_8
|
d9772d233f666445737e6d06f55011e3
|
%SerialLink.itorque Inertia torque
%
% TAUI = R.itorque(Q, QDD) is the inertia force/torque vector (1xN) at the
% specified joint configuration Q (1xN) and acceleration QDD (1xN), and N
% is the number of robot joints. TAUI = INERTIA(Q)*QDD.
%
% If Q and QDD are matrices (KxN), each row is interpretted as a joint state
% vector, and the result is a matrix (KxN) where each row is the corresponding
% joint torques.
%
% Note::
% - If the robot model contains non-zero motor inertia then this will
% included in the result.
%
% See also SerialLink.inertia, SerialLink.rne.
% 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 it = itorque(robot, q, qdd)
it = rne(robot, q, zeros(size(q)), qdd, 'gravity', [0;0;0]);
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
rne_mdh.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/rne_mdh.m
| 5,106 |
utf_8
|
ef0ee9390e2f669674340d0eb6b5bb43
|
%SERIALLINK.RNE_MDH Compute inverse dynamics via recursive Newton-Euler formulation
%
% Recursive Newton-Euler for modified Denavit-Hartenberg notation. Is invoked by
% R.RNE().
%
% See also SERIALLINK.RNE.
% 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 tau = rne_mdh(robot, a1, a2, a3, a4, a5)
z0 = [0;0;1];
grav = robot.gravity; % default gravity from the object
fext = zeros(6, 1);
% Set debug to:
% 0 no messages
% 1 display results of forward and backward recursions
% 2 display print R and p*
debug = 0;
n = robot.n;
if numcols(a1) == 3*n
Q = a1(:,1:n);
Qd = a1(:,n+1:2*n);
Qdd = a1(:,2*n+1:3*n);
np = numrows(Q);
if nargin >= 3,
grav = a2(:);
end
if nargin == 4
fext = a3;
end
else
np = numrows(a1);
Q = a1;
Qd = a2;
Qdd = a3;
if numcols(a1) ~= n || numcols(Qd) ~= n || numcols(Qdd) ~= n || ...
numrows(Qd) ~= np || numrows(Qdd) ~= np
error('bad data');
end
if nargin >= 5,
grav = a4(:);
end
if nargin == 6
fext = a5;
end
end
if robot.issym || any([isa(Q,'sym'), isa(Qd,'sym'), isa(Qdd,'sym')])
tau = zeros(np,n, 'sym');
else
tau = zeros(np,n);
end
for p=1:np
q = Q(p,:).';
qd = Qd(p,:).';
qdd = Qdd(p,:).';
Fm = [];
Nm = [];
pstarm = [];
Rm = [];
w = zeros(3,1);
wd = zeros(3,1);
vd = grav(:);
%
% init some variables, compute the link rotation matrices
%
for j=1:n
link = robot.links(j);
Tj = link.A(q(j));
switch link.type
case 'R'
D = link.d;
case 'P'
D = q(j);
end
alpha = link.alpha;
pm = [link.a; -D*sin(alpha); D*cos(alpha)]; % (i-1) P i
if j == 1
pm = t2r(robot.base) * pm;
Tj = robot.base * Tj;
end
Pm(:,j) = pm;
Rm{j} = t2r(Tj);
if debug>1
Rm{j}
Pm(:,j).'
end
end
%
% the forward recursion
%
for j=1:n
link = robot.links(j);
R = Rm{j}.'; % transpose!!
P = Pm(:,j);
Pc = link.r;
%
% trailing underscore means new value
%
switch link.type
case 'R'
% revolute axis
w_ = R*w + z0*qd(j);
wd_ = R*wd + cross(R*w,z0*qd(j)) + z0*qdd(j);
%v = cross(w,P) + R*v;
vd_ = R * (cross(wd,P) + ...
cross(w, cross(w,P)) + vd);
case 'P'
% prismatic axis
w_ = R*w;
wd_ = R*wd;
%v = R*(z0*qd(j) + v) + cross(w,P);
vd_ = R*(cross(wd,P) + ...
cross(w, cross(w,P)) + vd ...
) + 2*cross(R*w,z0*qd(j)) + z0*qdd(j);
end
% update variables
w = w_;
wd = wd_;
vd = vd_;
vdC = cross(wd,Pc).' + ...
cross(w,cross(w,Pc)).' + vd;
F = link.m*vdC;
N = link.I*wd + cross(w,link.I*w);
Fm = [Fm F];
Nm = [Nm N];
if debug
fprintf('w: '); fprintf('%.3f ', w)
fprintf('\nwd: '); fprintf('%.3f ', wd)
fprintf('\nvd: '); fprintf('%.3f ', vd)
fprintf('\nvdbar: '); fprintf('%.3f ', vdC)
fprintf('\n');
end
end
%
% the backward recursion
%
fext = fext(:);
f = fext(1:3); % force/moments on end of arm
nn = fext(4:6);
for j=n:-1:1
%
% order of these statements is important, since both
% nn and f are functions of previous f.
%
link = robot.links(j);
if j == n
R = eye(3,3);
P = [0;0;0];
else
R = Rm{j+1};
P = Pm(:,j+1); % i/P/(i+1)
end
Pc = link.r;
f_ = R*f + Fm(:,j);
nn_ = Nm(:,j) + R*nn + cross(Pc,Fm(:,j)).' + ...
cross(P,R*f);
f = f_;
nn = nn_;
if debug
fprintf('f: '); fprintf('%.3f ', f)
fprintf('\nn: '); fprintf('%.3f ', nn)
fprintf('\n');
end
switch link.type
case 'R'
% revolute
tau(p,j) = nn.'*z0 + ...
link.G^2 * link.Jm*qdd(j) - ...
friction(link, qd(j));
case 'P'
% prismatic
tau(p,j) = f.'*z0 + ...
link.G^2 * link.Jm*qdd(j) - ...
friction(link, qd(j));
end
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
paycap.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/paycap.m
| 2,622 |
utf_8
|
ea961f604dbe3edd92ea5316e85fdd55
|
%SerialLink.PAYCAP Static payload capacity of a robot
%
% [WMAX,J] = R.paycap(Q, W, F, TLIM) returns the maximum permissible
% payload wrench WMAX (1x6) applied at the end-effector, and the index of
% the joint J which hits its force/torque limit at that wrench. Q (1xN) is
% the manipulator pose, W the payload wrench (1x6), F the wrench reference
% frame (either '0' or 'e') and TLIM (2xN) is a matrix of joint
% forces/torques (first row is maximum, second row minimum).
%
% Trajectory operation::
%
% In the case Q is MxN then WMAX is Mx6 and J is Mx1 where the rows are the
% results at the pose given by corresponding row of Q.
%
% Notes::
% - Wrench vector and Jacobian must be from the same reference frame
% - Tool transforms are taken into consideration for F = 'e'.
%
% Author::
% Bryan Moutrie
%
% See also SerialLink.pay, SerialLink.gravjac, SerialLink.gravload.
% Copyright (C) Bryan Moutrie, 2013-2015
% Licensed under the GNU Lesser General Public License
% see full file for full statement
%
% LICENSE STATEMENT:
%
% This file is part of pHRIWARE.
%
% pHRIWARE 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.
%
% pHRIWARE 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 General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with pHRIWARE. If not, see <http://www.gnu.org/licenses/>.
function [wM, j] = paycap(robot, q, w, f, tauR)
if robot.fast
tauB = robot.gravload(q);
tauP = robot.rne(q, zeros(size(q)), zeros(size(q)), [0; 0; 0], unit(w));
else switch f
case '0'
[tauB, J] = gravjac(robot, q);
tauP = robot.pay(unit(w), J);
case {'n', 'e'}
tauB = gravjac(robot, q);
tauP = robot.pay(unit(w), q, 'e');
end
end
M = tauP > 0;
m = ~M;
TAUm = ones(size(tauB));
TAUM = ones(size(tauB));
for c = 1:robot.n
TAUM(:,c) = tauR(1,c);
TAUm(:,c) = tauR(2,c);
end
WM = zeros(size(tauB));
WM(M) = (TAUM(M) - tauB(M)) ./ tauP(M);
WM(m) = (TAUm(m) - tauB(m)) ./ tauP(m);
WM(isinf(WM)) = Inf; % Makes -Inf values Inf
[wM, j] = min(WM,[],2);
end
function u = unit(v)
u = v/norm(v);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
gencoords.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/gencoords.m
| 1,518 |
utf_8
|
cd6af91af514831c29cb5821e5915971
|
%SerialLink.gencoords Vector of symbolic generalized coordinates
%
% Q = R.gencoords() is a vector (1xN) of symbols [q1 q2 ... qN].
%
% [Q,QD] = R.gencoords() as above but QD is a vector (1xN) of
% symbols [qd1 qd2 ... qdN].
%
% [Q,QD,QDD] = R.gencoords() as above but QDD is a vector (1xN) of
% symbols [qdd1 qdd2 ... qddN].
%
% See also SerialLink.genforces.
% 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 [q,qd,qdd] = gencoords(r)
if nargout > 0
for j=1:r.n
q(j) = sym( sprintf('q%d', j), 'real' );
end
end
if nargout > 1
for j=1:r.n
qd(j) = sym( sprintf('qd%d', j), 'real' );
end
end
if nargout > 2
for j=1:r.n
qdd(j) = sym( sprintf('qdd%d', j), 'real' );
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
animate.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/animate.m
| 6,154 |
utf_8
|
dc17434a47ea0147748069dcb9dc3b44
|
%SerialLink.animate Update a robot animation
%
% R.animate(q) updates an existing animation for the robot R. This will have
% been created using R.plot(). Updates graphical instances of this robot in all figures.
%
% Notes::
% - Called by plot() and plot3d() to actually move the arm models.
% - Used for Simulink robot animation.
%
% See also SerialLink.plot.
% 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 animate(robot, qq)
if nargin < 3
handles = findobj('Tag', robot.name);
end
links = robot.links;
N = robot.n;
% get handle of any existing graphical robots of same name
% one may have just been created above
handles = findobj('Tag', robot.name);
% MAIN DISPLAY/ANIMATION LOOP
while true
% animate over all instances of this robot in different axes
for q=qq' % for all configurations in trajectory
q = q';
for handle=handles'
h = get(handle, 'UserData');
% now draw it for a pose q
if robot.mdh
% modified DH case
T = robot.base;
vert = T.t';
for L=1:N
if robot.links(L).isprismatic()
% scale the box representing the prismatic joint
% it is based at the origin and extends in z-direction
if q(L) > 0
set(h.pjoint(L), 'Matrix', diag([1 1 q(L) 1]));
else
% if length is zero the matrix is singular and MATLAB complains
%error('Prismatic length must be > 0');
end
end
T = T * links(L).A(q(L));
set(h.link(L), 'Matrix', T.T);
vert = [vert; T.t'];
end
% update the transform for link N+1 (the tool)
T = T * robot.tool;
if length(h.link) > N
set(h.link(N+1), 'Matrix', T.T);
end
vert = [vert; T.t'];
else
% standard DH case
T = robot.base;
vert = T.t';
for L=1:N
% for all N links
if robot.links(L).isprismatic()
% scale the box representing the prismatic joint
% it is based at the origin and extends in z-direction
assert( q(L) >= 0, 'Prismatic joint length must be >= 0'); % link lengths must be positive
% if scale factor is zero the matrix is singular and MATLAB complains
% so we make it no smaller than eps
set(h.pjoint(L), 'Matrix', diag([1 1 max(eps, q(L)) 1]));
end
% now set the transform for frame {L}, this controls the displayed pose of:
% the pipes associated with link L, that join {L} back to {L-1}
% (optional) a prismatic joint L, that joins {L} to {L+1}
if h.link(L) ~= 0
% for plot3d, skip any 0 in the handle list
set(h.link(L), 'Matrix', T.T);
end
T = T * links(L).A(q(L));
vert = [vert; T.t'];
end
% update the transform for link N+1 (the tool)
T = T*robot.tool;
if length(h.link) > N
set(h.link(N+1), 'Matrix', T.T);
end
vert = [vert; T.t'];
end
% now draw the shadow
if isfield(h, 'shadow')
set(h.shadow, 'Xdata', vert(:,1), 'Ydata', vert(:,2), ...
'Zdata', h.floorlevel*ones(size(vert(:,1))));
end
% update the tool tip trail
if isfield(h, 'trail')
T = robot.fkine(q);
robot.trail = [robot.trail; transl(T)];
set(h.trail, 'Xdata', robot.trail(:,1), 'Ydata', robot.trail(:,2), 'Zdata', robot.trail(:,3));
end
% animate the wrist frame
if ~isempty(h.wrist)
trplot(T, 'handle', h.wrist);
end
% add a frame to the movie
if ~isempty(h.robot.movie)
h.robot.movie.add();
end
if h.robot.delay > 0
pause(h.robot.delay);
drawnow
end
h.q = q;
set(handle, 'UserData', h);
end
end
if ~h.robot.loop
break;
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
perturb.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/perturb.m
| 1,629 |
utf_8
|
d39527df13f484d5f4ccbc649550de00
|
%SerialLink.perturb Perturb robot parameters
%
% RP = R.perturb(P) is a new robot object in which the dynamic parameters (link
% mass and inertia) have been perturbed. The perturbation is multiplicative so
% that values are multiplied by random numbers in the interval (1-P) to (1+P).
% The name string of the perturbed robot is prefixed by 'P/'.
%
% Useful for investigating the robustness of various model-based control
% schemes. For example to vary parameters in the range +/- 10 percent is:
% r2 = p560.perturb(0.1);
%
% See also SerialLink.rne.
% 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 r2 = perturb(r, p)
if nargin == 1
p = 0.1; % 10 percent disturb by default
end
r2 = SerialLink(r);
links = r2.links;
for i=1:r.n
s = (2*rand-1)*p + 1;
links(i).m = links(i).m * s;
s = (2*rand-1)*p + 1;
links(i).I = links(i).I * s;
end
r2.name = ['P/' r.name];
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
cinertia.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/cinertia.m
| 1,323 |
utf_8
|
a7665a413c93fb41a1e4abab02293da4
|
%SerialLink.cinertia Cartesian inertia matrix
%
% M = R.cinertia(Q) is the NxN Cartesian (operational space) inertia matrix which relates
% Cartesian force/torque to Cartesian acceleration at the joint configuration Q, and N
% is the number of robot joints.
%
% See also SerialLink.inertia, SerialLink.rne.
% MOD HISTORY
% 4/99 add object support
% $Log: not supported by cvs2svn $
% $Revision: 1.2 $
% 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 Mx = cinertia(robot, q)
J = jacob0(robot, q);
Ji = inv(J); %#ok<*MINV>
M = inertia(robot, q);
Mx = Ji' * M * Ji;
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
fkine.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/fkine.m
| 2,840 |
utf_8
|
d75ad4a564c0204ce1a2ad0a0f3f0aae
|
%SerialLink.fkine Forward kinematics
%
% T = R.fkine(Q, OPTIONS) is the pose of the robot end-effector as an SE3
% object for the joint configuration Q (1xN).
%
% If Q is a matrix (KxN) the rows are interpreted as the generalized joint
% coordinates for a sequence of points along a trajectory. Q(i,j) is the
% j'th joint parameter for the i'th trajectory point. In this case T is a
% an array of SE3 objects (K) where the subscript is the index along the path.
%
% [T,ALL] = R.fkine(Q) as above but ALL (N) is a vector of SE3 objects describing
% the pose of the link frames 1 to N.
%
% Options::
% 'deg' Assume that revolute joint coordinates are in degrees not
% radians
%
% Note::
% - The robot's base or tool transform, if present, are incorporated into the
% result.
% - Joint offsets, if defined, are added to Q before the forward kinematics are
% computed.
% - If the result is symbolic then each element is simplified.
%
% See also SerialLink.ikine, SerialLink.ikine6s.
% 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 [t,allt] = fkine(robot, q, varargin)
%
% evaluate fkine for each point on a trajectory of
% theta_i or q_i data
%
n = robot.n;
opt.deg = false;
opt = tb_optparse(opt, varargin);
if opt.deg
% in degrees mode, scale the columns corresponding to revolute axes
q = robot.todegrees(q);
end
if nargout > 1
allt(n) = SE3;
end
L = robot.links;
if numel(q) == n
% single configuration
t = SE3(robot.base);
for i=1:n
t = t * L(i).A(q(i));
if nargout > 1
allt(i) = t; % intermediate transformations
end
end
t = t * SE3(robot.tool);
else
if numcols(q) ~= n
error('q must have %d columns', n)
end
t(numrows(q)) = SE3; % preallocate storage
for k=1:numrows(q) % for each trajectory point
qk = q(k,:);
tt = SE3(robot.base);
for i=1:n
tt = tt * L(i).A(qk(i));
end
t(k) = tt * SE3(robot.tool);
end
end
if issym(t)
t = simplify(t);
else
t = trnorm(t);
end
%robot.T = t;
%robot.notify('Moved');
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
rne.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/rne.m
| 4,484 |
utf_8
|
c1a1aa9c85b860f820356e2d28c49999
|
%SerialLink.rne Inverse dynamics
%
% TAU = R.rne(Q, QD, QDD, OPTIONS) is the joint torque required for the
% robot R to achieve the specified joint position Q (1xN), velocity QD
% (1xN) and acceleration QDD (1xN), where N is the number of robot joints.
%
% TAU = R.rne(X, OPTIONS) as above where X=[Q,QD,QDD] (1x3N).
%
% [TAU,WBASE] = R.rne(X, GRAV, FEXT) as above but the extra output is the
% wrench on the base.
%
% Options::
% 'gravity',G specify gravity acceleration (default [0,0,9.81])
% 'fext',W specify wrench acting on the end-effector W=[Fx Fy Fz Mx My Mz]
% 'slow' do not use MEX file
%
% Trajectory operation::
%
% If Q,QD and QDD (MxN), or X (Mx3N) are matrices with M rows representing a
% trajectory then TAU (MxN) is a matrix with rows corresponding to each trajectory
% step.
%
% MEX file operation::
% This algorithm is relatively slow, and a MEX file can provide better
% performance. The MEX file is executed if:
% - the 'slow' option is not given, and
% - the robot is not symbolic, and
% - the SerialLink property fast is true, and
% - the MEX file frne.mexXXX exists in the subfolder rvctools/robot/mex.
%
% Notes::
% - The torque computed contains a contribution due to armature
% inertia and joint friction.
% - See the README file in the mex folder for details on how to configure
% MEX-file operation.
% - The M-file is a wrapper which calls either RNE_DH or RNE_MDH depending on
% the kinematic conventions used by the robot object, or the MEX file.
% - If a model has no dynamic parameters set the result is zero.
%
% See also SerialLink.accel, SerialLink.gravload, SerialLink.inertia.
% TODO:
% fix base transform
%
% verified against MAPLE code, which is verified by examples
%
% 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 varargout = rne(robot, varargin)
% allow more descriptive arguments
opt.gravity = [];
opt.fext = [];
opt.slow = false;
[opt,args] = tb_optparse(opt, varargin);
narg0 = length(args);
if ~isempty(opt.gravity)
assert( isvec(opt.gravity, 3), 'RTB:rne:badarg', 'gravity must be a 3-vector');
args = [args opt.gravity(:)];
end
if ~isempty(opt.fext)
assert( isvec(opt.fext, 6), 'RTB:rne:badarg', 'external force must be a 6-vector');
if length(args) == 3
args = [args robot.gravity];
end
args = [args opt.fext];
end
if robot.fast && ~opt.slow && (nargout < 2) && ~robot.issym() && ~any(cellfun( @(x) isa(x, 'sym'), args))
% use the MEX-file implementation if:
% * the fast property is set at constructor time
% * slow override not set
% * base wrench not requested
% * robot has no symbolic parameters
% * joint state has no symbolic values
%
% the mex-file handles DH and MDH variants
% the MEX file doesn't handle base rotation, so we need to hack the gravity
% vector instead. It lives in the 4th element of args.
if ~robot.base.isidentity()
% ok, a non-identity transform, we need to fix it
if length(args) == narg0
grav = robot.gravity; % no gravity option provided, take default
else
grav = args{narg0+1}; % else take value from option processed above
end
args{narg0+1} = robot.base.R' * grav; % and put it in the argument list
end
[varargout{1:nargout}] = frne(robot, args{:});
else
% use the M-file implementation
if robot.mdh == 0
[varargout{1:nargout}] = rne_dh(robot, args{:});
else
[varargout{1:nargout}] = rne_mdh(robot, args{:});
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
gravjac.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/gravjac.m
| 4,489 |
utf_8
|
8b40fc1de2d91ced27fe467747bdc502
|
%SerialLink.GRAVJAC Fast gravity load and Jacobian
%
% [TAU,JAC0] = R.gravjac(Q) is the generalised joint force/torques due to
% gravity TAU (1xN) and the manipulator Jacobian in the base frame JAC0 (6xN) for
% robot pose Q (1xN), where N is the number of robot joints.
%
% [TAU,JAC0] = R.gravjac(Q,GRAV) as above but gravitational acceleration is
% given explicitly by GRAV (3x1).
%
% Trajectory operation::
%
% If Q is MxN where N is the number of robot joints then a trajectory is
% assumed where each row of Q corresponds to a robot configuration. TAU
% (MxN) is the generalised joint torque, each row corresponding to an input
% pose, and JAC0 (6xNxM) where each plane is a Jacobian corresponding to an
% input pose.
%
% Notes::
% - The gravity vector is defined by the SerialLink property if not explicitly given.
% - Does not use inverse dynamics function RNE.
% - Faster than computing gravity and Jacobian separately.
%
% Author::
% Bryan Moutrie
%
% See also SerialLink.pay, SerialLink, SerialLink.gravload, SerialLink.jacob0.
% Copyright (C) Bryan Moutrie, 2013-2015
% Licensed under the GNU Lesser General Public License
% see full file for full statement
%
% LICENSE STATEMENT:
%
% This file is part of pHRIWARE.
%
% pHRIWARE 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.
%
% pHRIWARE 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 General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with pHRIWARE. If not, see <http://www.gnu.org/licenses/>.
%
function [tauB, J] = gravjac(robot, q, grav)
n = robot.n;
revolute = [robot.links(:).isrevolute];
if ~robot.mdh
baseAxis = robot.base(1:3,3);
baseOrigin = robot.base(1:3,4);
end
poses = size(q, 1);
tauB = zeros(poses, n);
if nargout == 2, J = zeros(6, robot.n, poses); end
% Forces
force = zeros(3,n);
if nargin < 3, grav = robot.gravity; end
for joint = 1: n
force(:,joint) = robot.links(joint).m * grav;
end
% Centre of masses (local frames)
r = zeros(4,n);
for joint = 1: n
r(:,joint) = [robot.links(joint).r'; 1];
end
com_arr = zeros(3, n);
for pose = 1: poses
[Te, T] = robot.fkine(q(pose,:));
jointOrigins = squeeze(T(1:3,4,:));
jointAxes = squeeze(T(1:3,3,:));
if ~robot.mdh
jointOrigins = [baseOrigin, jointOrigins(:,1:end-1)];
jointAxes = [baseAxis, jointAxes(:,1:end-1)];
end
% Backwards recursion
for joint = n: -1: 1
com = T(:,:,joint) * r(:,joint); % C.o.M. in world frame, homog
com_arr(:,joint) = com(1:3); % Add it to the distal others
t = 0;
for link = joint: n % for all links distal to it
if revolute(joint)
d = com_arr(:,link) - jointOrigins(:,joint);
t = t + cross3(d, force(:,link));
% Though r x F would give the applied torque and not the
% reaction torque, the gravity vector is nominally in the
% positive z direction, not negative, hence the force is
% the reaction force
else
t = t + force(:,link); %force on prismatic joint
end
end
tauB(pose,joint) = t' * jointAxes(:,joint);
end
if nargout == 2
J(:,:,pose) = makeJ(jointOrigins,jointAxes,Te(1:3,4),revolute);
end
end
end
function J = makeJ(O,A,e,r)
J(4:6,:) = A;
for j = 1:length(r)
if r(j)
J(1:3,j) = cross3(A(:,j),e-O(:,j));
else
J(:,j) = J([4 5 6 1 2 3],j); %J(1:3,:) = 0;
end
end
end
function c = cross3(a,b)
c(3,1) = a(1)*b(2) - a(2)*b(1);
c(1,1) = a(2)*b(3) - a(3)*b(2);
c(2,1) = a(3)*b(1) - a(1)*b(3);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
teach.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/teach.m
| 4,150 |
utf_8
|
d6f494b5ce61d77a158c7e55471f16fc
|
%SerialLink.teach Graphical teach pendant
%
% Allow the user to "drive" a graphical robot using a graphical slider
% panel.
%
% R.teach(OPTIONS) adds a slider panel to a current robot plot.
%
% R.teach(Q, OPTIONS) as above but the robot joint angles are set to Q (1xN).
%
%
% Options::
% 'eul' Display tool orientation in Euler angles (default)
% 'rpy' Display tool orientation in roll/pitch/yaw angles
% 'approach' Display tool orientation as approach vector (z-axis)
% '[no]deg' Display angles in degrees (default true)
% 'callback',CB Set a callback function, called with robot object and
% joint angle vector: CB(R, Q)
%
% Example::
%
% To display the velocity ellipsoid for a Puma 560
%
% p560.teach('callback', @(r,q) r.vellipse(q));
%
% GUI::
% - The specified callback function is invoked every time the joint configuration changes.
% the joint coordinate vector.
% - The Quit (red X) button removes the teach panel from the robot plot.
%
% Notes::
% - If the robot is displayed in several windows, only one has the
% teach panel added.
% - All currently displayed robots move as the sliders are adjusted.
% - The slider limits are derived from the joint limit properties. If not
% set then for
% - a revolute joint they are assumed to be [-pi, +pi]
% - a prismatic joint they are assumed unknown and an error occurs.
%
% See also SerialLink.plot, SerialLink.getpos.
% 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
% a ton of handles and parameters created by this function are stashed in
% a structure which is passed into all callbacks
function teach(robot, varargin)
%---- handle options
opt.deg = true;
opt.orientation = {'rpy', 'rpy/zyx', 'rpy/xyz', 'eul', 'approach'};
opt.d_2d = false;
opt.callback = [];
opt.record = [];
[opt,args] = tb_optparse(opt, varargin);
% get the joint coordinates if given
q = [];
if isempty(args)
% no joint angles passed, assume all zeros
q = zeros(1, robot.n);
% set any prismatic joints to the minimum value
for j=find(robot.links.isprismatic)
q(j) = robot.links(j).qlim(1);
end
else
% joint angles passed
if isnumeric(args{1})
q = args{1};
args = args(2:end);
end
end
%---- get the current robot state
% check to see if there are any graphical robots of this name
rhandles = findobj('Tag', robot.name); % find the graphical element of this name
if isempty(rhandles)
% no robot, plot one so long as joint coordinates were given
assert( ~isempty(q), 'RTB:teach:badarg', 'No joint coordinates provided');
robot.plot(q, args{:});
else
% graphical robot already exists
% get the info from its Userdata
info = get(rhandles(1), 'UserData');
% the handle contains current joint angles (set by plot)
if isempty(q) && ~isempty(info.q)
% if no joint coordinates given get from the graphical model
q = info.q;
else
% joint coordiantes were given, make them current
robot.plot(q, args{:});
end
end
assert( ~isempty(q), 'RTB:teach:badarg', 'No joint coordinates provided');
RTBPlot.install_teach_panel(robot.name, robot, q, opt)
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
maniplty.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/maniplty.m
| 5,488 |
utf_8
|
6dc8d1e4cd47b12bd3577edd006e419a
|
%SerialLink.MANIPLTY Manipulability measure
%
% M = R.maniplty(Q, OPTIONS) is the manipulability index (scalar) for the
% robot at the joint configuration Q (1xN) where N is the number of robot
% joints. It indicates dexterity, that is, how isotropic the robot's
% motion is with respect to the 6 degrees of Cartesian motion. The measure
% is high when the manipulator is capable of equal motion in all directions
% and low when the manipulator is close to a singularity.
%
% If Q is a matrix (MxN) then M (Mx1) is a vector of manipulability
% indices for each joint configuration specified by a row of Q.
%
% [M,CI] = R.maniplty(Q, OPTIONS) as above, but for the case of the Asada
% measure returns the Cartesian inertia matrix CI.
%
% R.maniplty(Q) displays the translational and rotational manipulability.
%
% Two measures can be computed:
% - Yoshikawa's manipulability measure is based on the shape of the velocity
% ellipsoid and depends only on kinematic parameters (default).
% - Asada's manipulability measure is based on the shape of the acceleration
% ellipsoid which in turn is a function of the Cartesian inertia matrix and
% the dynamic parameters. The scalar measure computed here is the ratio of
% the smallest/largest ellipsoid axis. Ideally the ellipsoid would be
% spherical, giving a ratio of 1, but in practice will be less than 1.
%
% Options::
% 'trans' manipulability for transational motion only (default)
% 'rot' manipulability for rotational motion only
% 'all' manipulability for all motions
% 'dof',D D is a vector (1x6) with non-zero elements if the
% corresponding DOF is to be included for manipulability
% 'yoshikawa' use Yoshikawa algorithm (default)
% 'asada' use Asada algorithm
%
% Notes::
% - The 'all' option includes rotational and translational dexterity, but
% this involves adding different units. It can be more useful to look at the
% translational and rotational manipulability separately.
% - Examples in the RVC book (1st edition) can be replicated by using the 'all' option
%
% References::
%
% - Analysis and control of robot manipulators with redundancy,
% T. Yoshikawa,
% Robotics Research: The First International Symposium (M. Brady and R. Paul, eds.),
% pp. 735-747, The MIT press, 1984.
% - A geometrical representation of manipulator dynamics and its application to
% arm design,
% H. Asada,
% Journal of Dynamic Systems, Measurement, and Control,
% vol. 105, p. 131, 1983.
% - Robotics, Vision & Control, P. Corke, Springer 2011.
%
% See also SerialLink.inertia, SerialLink.jacob0.
% 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
%TODO
% return the ellipsoid?
function [w,mx] = maniplty(robot, q, varargin)
opt.method = {'yoshikawa', 'asada'};
opt.axes = {'all', 'trans', 'rot'};
opt.dof = [];
opt = tb_optparse(opt, varargin);
if nargout == 0
opt.axes = 'trans';
mt = maniplty(robot, q, 'setopt', opt);
opt.axes = 'rot';
mr = maniplty(robot, q, 'setopt', opt);
for i=1:numrows(mt)
fprintf('Manipulability: translation %g, rotation %g\n', mt(i), mr(i));
end
return;
end
if isempty(opt.dof)
switch opt.axes
case 'trans'
dof = [1 1 1 0 0 0];
case 'rot'
dof = [0 0 0 1 1 1];
case 'all'
dof = [1 1 1 1 1 1];
end
else
dof = opt.dof;
end
opt.dof = logical(dof);
if strcmp(opt.method, 'yoshikawa')
w = zeros(numrows(q),1);
for i=1:numrows(q)
w(i) = yoshi(robot, q(i,:), opt);
end
elseif strcmp(opt.method, 'asada')
w = zeros(numrows(q),1);
if nargout > 1
dof = sum(opt.dof);
MX = zeros(dof,dof,numrows(q));
for i=1:numrows(q)
[ww,mm] = asada(robot, q(i,:), opt);
w(i) = ww;
MX(:,:,i) = mm;
end
else
for i=1:numrows(q)
w(i) = asada(robot, q(i,:), opt);
end
end
end
if nargout > 1
mx = MX;
end
function m = yoshi(robot, q, opt)
J = robot.jacob0(q);
J = J(opt.dof,:);
m2 = det(J * J');
m2 = max(0, m2); % clip it to positive
m = sqrt(m2);
function [m, mx] = asada(robot, q, opt)
J = robot.jacob0(q);
if rank(J) < 6
warning('robot is in degenerate configuration')
m = 0;
return;
end
Ji = pinv(J);
M = robot.inertia(q);
Mx = Ji' * M * Ji;
d = find(opt.dof);
Mx = Mx(d,d);
e = eig(Mx);
m = min(e) / max(e);
if nargout > 1
mx = Mx;
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
inertia.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/inertia.m
| 2,008 |
utf_8
|
f3f737784c846fc85e9a5b02736fe80c
|
%SerialLink.INERTIA Manipulator inertia matrix
%
% I = R.inertia(Q) is the symmetric joint inertia matrix (NxN) which relates
% joint torque to joint acceleration for the robot at joint configuration Q.
%
% If Q is a matrix (KxN), each row is interpretted as a joint state
% vector, and the result is a 3d-matrix (NxNxK) where each plane corresponds
% to the inertia for the corresponding row of Q.
%
% Notes::
% - The diagonal elements I(J,J) are the inertia seen by joint actuator J.
% - The off-diagonal elements I(J,K) are coupling inertias that relate
% acceleration on joint J to force/torque on joint K.
% - The diagonal terms include the motor inertia reflected through the gear
% ratio.
%
% See also SerialLink.RNE, SerialLink.CINERTIA, SerialLink.ITORQUE.
% 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 M = inertia(robot, q)
if numcols(q) ~= robot.n
error('q must have %d columns', robot.n);
end
if numrows(q) > 1
M = [];
for i=1:numrows(q)
M = cat(3, M, robot.inertia(q(i,:)));
end
return
end
n = robot.n;
if numel(q) == robot.n
q = q(:).';
end
M = zeros(n,n,0);
for Q = q.'
m = rne(robot, ones(n,1)*Q.', zeros(n,n), eye(n), 'gravity', [0 0 0]);
M = cat(3, M, m);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
fdyn.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/fdyn.m
| 5,073 |
utf_8
|
a400da6da911640f9610ea979364170f
|
%SerialLink.fdyn Integrate forward dynamics
%
% [T,Q,QD] = R.fdyn(TMAX, FTFUN) integrates the dynamics of the robot over
% the time interval 0 to TMAX and returns vectors of time T (Kx1), joint
% position Q (KxN) and joint velocity QD (KxN). The initial joint position
% and velocity are zero. The torque applied to the joints is computed by
% the user-supplied control function FTFUN:
%
% TAU = FTFUN(ROBOT, T, Q, QD)
%
% where TAU (1xN) is the joint torques to be applied at this time instant,
% ROBOT is the robot object being simulated, T is the current time, and Q
% (1xN) and QD (1xN) are the manipulator joint coordinate and velocity
% state respectively.
%
% [TI,Q,QD] = R.fdyn(T, FTFUN, Q0, QD0) as above but allows the initial
% joint position Q0 (1xN) and velocity QD0 (1x) to be specified.
%
% [T,Q,QD] = R.fdyn(T1, FTFUN, Q0, QD0, ARG1, ARG2, ...) allows optional
% arguments to be passed through to the user-supplied control function:
%
% TAU = FTFUN(ROBOT, T, Q, QD, ARG1, ARG2, ...)
%
% Example 1: to apply zero joint torque to the robot without Coulomb friction:
%
% [t,q] = robot.nofriction().fdyn(5, @my_torque_function);
%
% function tau = my_torque_function(robot, t, q)
% tau = zeros(1, robot.n);
% end
%
% Example 2: as above, but using a lambda function
%
% [t,q] = robot.nofriction().fdyn(5, @(robot, t, q, qd) zeros(1, robot.n) );
%
%
% Example 3: the robot is controlled by a PD controller. We first define
% a function to compute the control which has additional parameters for
% the setpoint and control gains (qstar, P, D)
%
% function tau = myfunc(q, qd, qstar, P, D)
% tau = (qstar-q)*P + qd*D; % P, D are 6x6
% end
%
% and then integrate the robot dynamics with the control:
%
% [t,q] = robot.fdyn(10, @(robot, t, q, qd) myfunc(q, qd, qstar, P, D) );
%
% where the lambda function ignores the passed values of robot and t but
% adds qstar, P and D to argument list for myfunc.
%
% Note::
% - This function performs poorly with non-linear joint friction, such as
% Coulomb friction. The R.nofriction() method can be used to set this
% friction to zero.
% - If FTFUN is not specified, or is given as [], then zero torque
% is applied to the manipulator joints.
% - The MATLAB builtin integration function ode45() is used.
%
% See also SerialLink.accel, SerialLink.nofriction, SerialLink.rne, ode45.
% 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 [t, q, qd] = fdyn(robot, t1, torqfun, q0, qd0, varargin)
% check the Matlab version, since ode45 syntax has changed
if verLessThan('matlab', '7')
error('fdyn now requires MATLAB version >= 7');
end
n = robot.n;
if nargin == 2
torqfun = [];
q0 = zeros(1,n);
qd0 = zeros(1,n);
elseif nargin == 3
q0 = zeros(1,n);
qd0 = zeros(1,n);
elseif nargin == 4
qd0 = zeros(1,n);
end
assert(isempty(torqfun) || isa(torqfun,'function_handle') , 'RTB:fdyn:badarg', 'must pass a function handle or []');
% concatenate q and qd into the initial state vector
q0 = [q0(:); qd0(:)];
[t,y] = ode45(@fdyn2, [0 t1], q0, [], robot, torqfun, varargin{:});
q = y(:,1:n);
qd = y(:,n+1:2*n);
end
%FDYN2 private function called by FDYN
%
% XDD = FDYN2(T, X, FLAG, ROBOT, TORQUEFUN)
%
% Called by FDYN to evaluate the robot velocity and acceleration for
% forward dynamics. T is the current time, X = [Q QD] is the state vector,
% ROBOT is the object being integrated, and TORQUEFUN is the string name of
% the function to compute joint torques and called as
%
% TAU = TORQUEFUN(ROBOT, T, X, VARARGIN)
%
% if not given zero joint torques are assumed.
%
% The result is XDD = [QD QDD].
function xd = fdyn2(t, x, robot, torqfun, varargin)
n = robot.n;
q = x(1:n)';
qd = x(n+1:2*n)';
% evaluate the torque function if one is given
if isa(torqfun, 'function_handle')
tau = torqfun(robot, t, q, qd, varargin{:});
tau = tau(:)';
assert(isreal(tau) && length(tau) == n, 'rtb:fdyn:badretval', 'torque function must return vector with N real elements');
else
tau = zeros(1,n);
end
qdd = robot.accel(x(1:n,1)', x(n+1:2*n,1)', tau);
xd = [x(n+1:2*n,1); qdd];
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
fellipse.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/fellipse.m
| 3,069 |
utf_8
|
d87897de30852a78a8ed05f0b51612ab
|
%SerialLink.fellipse Force ellipsoid for seriallink manipulator
%
% R.fellipse(Q, OPTIONS) displays the force ellipsoid for the
% robot R at pose Q. The ellipsoid is centered at the tool tip position.
%
% Options::
% '2d' Ellipse for translational xy motion, for planar manipulator
% 'trans' Ellipsoid for translational motion (default)
% 'rot' Ellipsoid for rotational motion
%
% Display options as per plot_ellipse to control ellipsoid face and edge
% color and transparency.
%
% Example::
% To interactively update the force ellipsoid while using sliders
% to change the robot's pose:
% robot.teach('callback', @(r,q) r.fellipse(q))
%
% Notes::
% - The ellipsoid is tagged with the name of the robot prepended to
% ".fellipse".
% - Calling the function with a different pose will update the ellipsoid.
%
% See also SerialLink.jacob0, SerialLink.vellipse, plot_ellipse.
% 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 fellipse(robot, q, varargin)
name = [robot.name '.fellipse'];
e = findobj('Tag', name);
if isempty(q)
delete(e);
return;
end
opt.mode = {'trans', 'rot', '2d'};
opt.deg = false;
[opt,args] = tb_optparse(opt, varargin);
if opt.deg
% in degrees mode, scale the columns corresponding to revolute axes
q = robot.todegrees(q);
end
if robot.n == 2
opt.mode = '2d';
end
J = robot.jacob0(q);
switch opt.mode
case'2d'
J = J(1:2,1:2);
case 'trans'
J = J(1:3,:);
case 'rot'
J = J(4:6,:);
end
JJ = J*J';
if det(JJ) < 100*eps
warning('RTB:fellipse:badval', 'Jacobian is singular, ellipse cannot be drawn')
return
end
N = inv(JJ);
t = transl(robot.fkine(q));
switch opt.mode
case '2d'
if isempty(e)
h = plot_ellipse(N, t(1:2), 'edgecolor', 'r', 'Tag', name, args{:});
else
plot_ellipse(N, t(1:2), 'alter', e);
end
otherwise
if isempty(e)
h = plot_ellipse(N, t(1:3), 'edgecolor', 'k', 'fillcolor', 'r', 'alpha', 0.5, 'Tag', name, args{:});
else
plot_ellipse(N, t(1:3), 'alter', e);
end
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
trchain.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/@SerialLink/trchain.m
| 4,515 |
utf_8
|
b601af947d862aed84aa7ed6597c15fc
|
%SERIALLINK.TRCHAIN Convert to elementary transform sequence
%
% S = R.TRCHAIN(OPTIONS) is a sequence of elementary transforms that describe the
% kinematics of the serial link robot arm. The string S comprises a number
% of tokens of the form X(ARG) where X is one of Tx, Ty, Tz, Rx, Ry, or Rz.
% ARG is a joint variable, or a constant angle or length dimension.
%
% For example:
% >> mdl_puma560
% >> p560.trchain
% ans =
% Rz(q1)Rx(90)Rz(q2)Tx(0.431800)Rz(q3)Tz(0.150050)Tx(0.020300)Rx(-90)
% Rz(q4)Tz(0.431800)Rx(90)Rz(q5)Rx(-90)Rz(q6)
%
% Options::
% '[no]deg' Express angles in degrees rather than radians (default deg)
% 'sym' Replace length parameters by symbolic values L1, L2 etc.
%
% See also trchain, trotx, troty, trotz, transl, DHFactor.
% 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 = trchain(robot, varargin)
opt.sym = false;
opt.deg = true;
opt = tb_optparse(opt, varargin);
if opt.deg
conv = 180/pi;
else
conv = 1;
end
s = '';
varcount = 1;
for j=1:robot.n
L = robot.links(j);
if robot.ismdh()
% Method for modified DH parameters
% Append Tx(a)
if L.a ~= 0
if opt.sym
s = append(s, 'Tx(L%d)', varcount);
varcount = varcount+1;
else
s = append(s, 'Tx(%g)', L.a);
end
end
% Append Rx(alpha)
if L.alpha ~= 0
s = append(s, 'Rx(%g)', (L.alpha*conv));
end
if L.isrevolute()
% Append Tz(d)
if L.d ~= 0
if opt.sym
s = append(s, 'Tz(L%d)', varcount);
varcount = varcount+1;
else
s = append(s, 'Tz(%g)', L.d);
end
end
% Append Rz(q)
s = append(s, 'Rz(q%d)', j);
else
% Append Rz(theta)
if L.theta ~= 0
s = append(s, 'Rz(%g)', (L.alpha*conv));
end
% Append Tz(q)
s = append(s, 'Tz(q%d)', j);
end
else
% Method for standard DH parameters
if L.isrevolute()
% Append Rz(q)
s = append(s, 'Rz(q%d)', j);
% Append Tz(d)
if L.d ~= 0
if opt.sym
s = append(s, 'Tz(L%d)', varcount);
varcount = varcount+1;
else
s = append(s, 'Tz(%g)', L.d);
end
end
else
% Append Rz(theta)
if L.theta ~= 0
s = append(s, 'Rz(%g)', (L.alpha*conv));
end
% Append Tz(q)
s = append(s, 'Tz(q%d)', j);
end
% Append Tx(a)
if L.a ~= 0
if opt.sym
s = append(s, 'Tx(L%d)', varcount);
varcount = varcount+1;
else
s = append(s, 'Tx(%g)', L.a);
end
end
% Append Rx(alpha)
if L.alpha ~= 0
s = append(s, 'Rx(%g)', (L.alpha*conv));
end
end
end
end
function s = append(s, fmt, j)
s = strcat(s, sprintf(fmt, j));
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
dxdemo.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/demos/dxdemo.m
| 4,414 |
utf_8
|
a12f5f38fda2788e7906ad3d546bd4fd
|
%DXDEMO Demonstrate distance transform planner using animation
%
% MORPHDEMO(IM, SE, OPTIONS) displays an animation to show the principles
% of the mathematical morphology operations dilation or erosion. Two
% windows are displayed side by side, input binary image on the left and
% output image on the right. The structuring element moves over the input
% image and is colored red if the result is zero, else blue. Pixels in
% the output image are initially all grey but change to black or white
% as the structuring element moves.
%
% OUT = MORPHDEMO(IM, SE, OPTIONS) as above but returns the output image.
%
% Options::
% 'dilate' Perform morphological dilation
% 'erode' Perform morphological erosion
% 'delay' Time between animation frames (default 0.5s)
% 'scale',S Scale factor for output image (default 64)
% 'movie',M Write image frames to the folder M
%
% Notes::
% - This is meant for small images, say 10x10 pixels.
%
% See also IMORPH, IDILATE, IERODE.
function out = dxdemo(map, goal, varargin)
opt.delay = 0;
opt.movie = [];
opt.scale = 64;
opt.metric = {'euclidean', 'manhattan'};
opt = tb_optparse(opt, varargin);
set(gcf, 'Position', [90 435 1355 520])
clf
goal = [4 8];
start = [7 2];
opt.metric = 'euclidean';
opt.movie = [];%'dxform2.mp4'
opt.delay = 0;
% make a simple map
occgrid = zeros(10,10);
occgrid(4:6,3:7) = 1;
%occgrid(7:8,7) = 1; % extra bit
cost0 = occgrid;
cost0(cost0==1) = NaN;
cost = cost0;
cost(cost0==0) = Inf;
cost(goal(2), goal(1)) = 0;
if ~isempty(opt.movie)
anim = Animate(opt.movie);
end
if ~isempty(opt.movie)
anim.add();
end
switch opt.metric
case 'cityblock'
m = [inf 1 inf
1 0 1
inf 1 inf];
case 'euclidean'
r2 = sqrt(2);
m = [r2 1 r2
1 0 1
r2 1 r2];
otherwise
error('unknown distance metric');
end
iteration = 0;
ninf = 0;
n2 = 1; % half width
n22 = 1.5;
newcost = inf(size(cost));
title('Wavefront path planning simulation');
while true
iteration = iteration+1;
maxval = max(max(cost(isfinite(cost))));
subplot(121)
showpixels(cost, 'contrast', maxval*0.7, 'fmt', '%.2g', 'cscale', [0 maxval+2], 'fontsize', 20, 'nancolor', 'nohideinf', 'infsymbol', 'nohidenan', 'infcolor')
xlabel('x', 'FontSize', 20); ylabel('y', 'FontSize', 20);
hpatch1 = patch(1, 1, 'y', 'FaceAlpha', 0.5);
for r=n2+1:numrows(cost)-n2
for c=n2+1:numcols(cost)-n2
win = cost(r-n2:r+n2, c-n2:c+n2);
if isnan(cost(r,c))
newcost(r,c) = NaN;
else
newcost(r,c) = min(min(win+m));
end
% animate the patch
hpatch1.XData = [c-n22 c+n22 c+n22 c-n22];
hpatch1.YData = [r-n22 r-n22 r+n22 r+n22];
subplot(122)
cla
showpixels(newcost, 'contrast', maxval*0.7, 'fmt', '%.2g', 'cscale', [0 maxval+2], 'fontsize', 20, 'nancolor', 'nohideinf', 'infsymbol', 'nohidenan', 'infcolor')
xlabel('x', 'FontSize', 20); ylabel('y', 'FontSize', 20)
hpatch2 = patch([c-0.5 c+0.5 c+0.5 c-0.5], [r-0.5 r-0.5 r+0.5 r+0.5], 'y', 'FaceAlpha', 0.5);
if ~isempty(opt.movie)
anim.add();
end
if opt.delay == 0
drawnow
else
pause(opt.delay);
end
end
end
cost = newcost;
ninfnow = sum(sum( isinf(cost(2:end-1,2:end-1)) )) % current number of Infs
if ninfnow == 0 || ninfnow == ninf
% stop if the number of Infs left in the map had stopped reducing
% it may never get to zero if there are unreachable cells in the map
break;
end
ninf = ninfnow;
if ~isempty(opt.movie)
anim.close();
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
check.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/mex/check.m
| 2,355 |
utf_8
|
687f3f98ff0462cae7415c80c3caebf3
|
function check
fprintf('***************************************************************\n')
fprintf('************************ Puma 560 *****************************\n')
fprintf('***************************************************************\n')
clear
mdl_puma560
mdl_puma560akb
if exist('rne') == 3
error('need to remove rne.mex file from @SerialLink dir');
end
check1(p560, p560m);
fprintf('\n***************************************************************\n')
fprintf('********************** Stanford arm ***************************\n')
fprintf('***************************************************************\n')
clear
mdl_stanford
stanfordm % non standard model shipped in this folder
check1(stanf, stanm);
end
function check1(rdh, rmdh)
%CHECK script to compare M-file and MEX-file versions of RNE
% load the model and remove non-linear friction
rdh = nofriction(rdh, 'coulomb');
rmdh = nofriction(rdh, 'coulomb');
% number of trials
n = 10;
fprintf('************************ normal case *****************************\n')
args = {};
fprintf('DH: ')
check2(rdh, n, args);
fprintf('MDH: ')
check2(rmdh, n, args);
fprintf('************************ no gravity *****************************\n')
args = {[0 0 0]};
fprintf('DH: ')
check2(rdh, n, args);
fprintf('MDH: ')
check2(rmdh, n, args);
fprintf('************************ ext force *****************************\n')
args = {[0 0 9.81], [10 10 10 10 10 10]'};
fprintf('DH: ')
check2(rdh, n, args);
fprintf('MDH: ')
check2(rmdh, n, args);
end
%CHECK2 script to compare M-file and MEX-file versions of RNE
function check2(robot, n, args)
robot = nofriction(robot, 'coulomb');
% create random points in state space
q = rand(n, 6);
qd = rand(n, 6);
qdd = rand(n, 6);
% test M-file
robot.fast = 0;
tic;
tau = rne(robot, q, qd, qdd, args{:});
t = toc;
% test MEX-file
robot.fast = 1;
tic;
tau_f = rne(robot, q, qd, qdd, args{:});
t_f = toc;
% print comparative results
fprintf('Speedup is %10.0f, worst case error is %f\n', ...
t/t_f, max(max(abs(tau-tau_f))));
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
move.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/interfaces/@Create/move.m
| 3,671 |
utf_8
|
79fa5d2956cbcc99182a784ce925b457
|
function move(robot, speed, angvel, varargin);
%travelDist(serPort, roombaSpeed, distance)
%Moves the Create the distance entered in meters. Positive distances move the
%Create foward, negative distances move the Create backwards.
%roombaSpeed should be between 0.025 and 0.5 m/s
% By; Joel Esposito, US Naval Academy, 2011
opt.distance = [];
opt.angle = [];
opt.time = [];
opt.event = [];
opt = tb_optparse(opt, varargin);
% enforce some limits
if (speed < 0) %Speed given by user shouldn't be negative
disp('WARNING: Speed inputted is negative. Should be positive. Taking the absolute value');
speed = abs(speed);
end
robot.flush();
if ~all(isnan([opt.distance opt.angle opt.time opt.event]))
% we have a limit defined
if ~isempty(opt.distance)
robot.write([152 9]);
if (opt.distance < 0)
%Definition of SetFwdVelRAdius Roomba, speed has to be negative to go backwards.
% Takes care of this case. User shouldn't worry about negative speeds
speed = -speed;
end
SetFwdVelAngVelCreate(robot, speed, angvel);
robot.write([156]);
robot.fwrite(opt.distance*1000, 'int16');
elseif ~isempty(opt.angle)
robot.write([152 9]);
SetFwdVelAngVelCreate(robot, speed, angvel);
robot.write([157]);
robot.fwrite(opt.distance, 'int16');
elseif ~isempty(opt.time)
robot.write([152 14]);
SetFwdVelAngVelCreate(robot, speed, angvel);
robot.write([155 opt.time*10]);
elseif ~isempty(opt.event)
robot.write([152 14]);
SetFwdVelAngVelCreate(robot, speed, angvel);
robot.write([158 opt.event]);
end
% tell it to stop moving
SetFwdVelAngVelCreate(robot, 0, 0);
robot.write([142 1]); % return a sensor value
pause(robot.delay)
robot.write([153]); % play the script
% wait for motion to finish
disp('waiting');
while( robot.serPort.BytesAvailable() ==0)
%disp('waiting to finish')
pause(robot.delay)
end
pause(robot.delay)
else
% no limit, constant velocity forever
% set robot moving
SetFwdVelAngVelCreate(robot, speed, angvel);
end
pause(robot.delay)
end
function [] = SetFwdVelAngVelCreate(robot, FwdVel, AngVel )
%[] = SetFwdVelAngVelCreate(serPort, FwdVel, AngVel )
% Specify forward velocity in meters/ sec
% [-0.5, 0.5]. Specify Angular Velocity in rad/sec. Negative velocity is backward/Clockwise. Caps overflow.
% Note that the wheel speeds are capped at .5 meters per second. So it is possible to
% specify speeds that cannot be acheived. Warning is displayed.
% Only works with Create I think...not Roomba
% By; Joel Esposito, US Naval Academy, 2011
robot.flush();
d = 0.258; % wheel baseline
wheelVel = inv([.5 .5; 1/d -1/d])*[FwdVel; AngVel];
rightWheelVel = min( max(1000* wheelVel(1), -500) , 500);
leftWheelVel = min( max(1000* wheelVel(2), -500) , 500);
if ( abs(rightWheelVel) ==500) | ( abs(leftWheelVel) ==500)
disp('Warning: desired velocity combination exceeds limits')
end
%[leftWheelVel rightWheelVel]
robot.write([145]);
robot.fwrite(rightWheelVel, 'int16');
robot.fwrite(leftWheelVel, 'int16');
pause(robot.delay)
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
Num_Keypad_backnovibe.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/interfaces/@Create/Num_Keypad_backnovibe.m
| 12,578 |
utf_8
|
7e71977ac697d6139c1bdb60444f6bea
|
function varargout = RobotGuiControl(varargin)
%varargout = Num_Keypad_backnovibe(varargin)
%Large Forward Arrow-Moves Roomba forward 10cm
%Small Forward Arrow-Moves Roomba forward 5cm
%Back Arrow-Moves Roomba backward 5cm
%Large Left Arrow-Turns Roomba 15 degrees left
%Small Left Arrow-Turns Roomba 5 degrees left
%Large Right Arrow-Turns Roomba 15 degrees right
%Small Right Arrow-Turns Roomba 5 degrees right
% Description: Keypad with No Feedback. Also, creates
% a global variable called 'list', which contains all the numeric presses,
% NUM_KEYPAD_BACKNOVIBE M-file for Num_Keypad_backnovibe.fig
% NUM_KEYPAD_BACKNOVIBE, by itself, creates a new NUM_KEYPAD_BACKNOVIBE or raises the existing
% singleton*.
% H = NUM_KEYPAD_BACKNOVIBE returns the handle to a new NUM_KEYPAD_BACKNOVIBE or the handle to
% the existing singleton*.
%
% NUM_KEYPAD_BACKNOVIBE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NUM_KEYPAD_BACKNOVIBE.M with the given input arguments.
%
% NUM_KEYPAD_BACKNOVIBE('Property','Value',...) creates a new NUM_KEYPAD_BACKNOVIBE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Num_Keypad_backnovibe_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Num_Keypad_backnovibe_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% % Begin initialization code - DO NOT EDIT
%BY; Joel Esposito, US Naval Academy, 2011
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Num_Keypad_backnovibe_OpeningFcn, ...
'gui_OutputFcn', @Num_Keypad_backnovibe_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Num_Keypad_backnovibe is made visible.
function RobotGuiControl_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Num_Keypad_backnovibe (see VARARGIN)
% Choose default command line output for Num_Keypad_backnovibe
%Global Variables and Startup Processes
% -------------------------------------------------------------------------
% START COPY!
%--------------------------------------------------------------------------
% Cleaning up old ports
serPort = varargin{1};
global a
a = instrfind();
if ~isempty(a)
fclose(a);
pause(1);
delete(a);
pause(1);
end
global ser
% serial port for vibration
% serial port for sending characters
ser = RoombaInit(serPort);
%logging
global keyPresses startTime elapsedTime
keyPresses = [0 0];
startTime = [];
elapsedTime = [];
% speeds and angles
global sV sD bV bD sW sA bW bA
sV = .1; sD = 0.05; % vel in m/s angles in deg W is angluar speed but in m/s?
bV = .2; bD = 0.1;
sW = .05; sA = 5;
bW = .1; bA = 15;
global moving movingTest
movingTest = 1;
moving=0;
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
%--------------------------
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 2];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
travelDist(ser, sV, -sD);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 3];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
%--------------------------
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 4];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, bW, bA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 5];
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
travelDist(ser, sV, sD);
moving=0;
end
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 6];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, bW, -bA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 7];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, sW, sA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 8];
%--------
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
travelDist(ser, bV, bD);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 9];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, sW, -sA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton_back.
function pushbutton_back_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_back (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%--------
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
% --- Executes on button press in pushbutton_del.
function pushbutton_del_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_del (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%--------
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
% --- Executes on button press in pushbutton_enter.
function pushbutton_enter_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_enter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
global NegVibe NegTime PosVibe PosTime
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
else
elapsedTime = toc(startTime);
fprintf('Sec: %f, Keystrokes: %d, NegPresses: %d \n ', [elapsedTime keyPresses(1) keyPresses(2)]);
end
%--------------------------------------------------------------------------
% END COPY
%-------------------------------------------------------------------------
% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list .];
%--------
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses = keyPresses +1;
if isempty(startTime)
startTime = tic;
end
% UIWAIT makes Num_Keypad_backnovibe wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = RobotGuiControl_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%global keyPresses elapsedTime
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
teach.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/interfaces/@Create/teach.m
| 12,494 |
utf_8
|
bde6f61bbfda699e08b8d7e428a6f4ba
|
function varargout = RobotGuiControl(varargin)
%varargout = RobotGuiControl(varargin)
%Large Forward Arrow-Moves Roomba forward 10cm
%Small Forward Arrow-Moves Roomba forward 5cm
%Back Arrow-Moves Roomba backward 5cm
%Large Left Arrow-Turns Roomba 15 degrees left
%Small Left Arrow-Turns Roomba 5 degrees left
%Large Right Arrow-Turns Roomba 15 degrees right
%Small Right Arrow-Turns Roomba 5 degrees right
% Note, GUI can be used from touchscreen mobile device by making remote
% desktop connection from mobile device to PC running MTIC.
% NUM_KEYPAD_BACKNOVIBE M-file for Num_Keypad_backnovibe.fig
% NUM_KEYPAD_BACKNOVIBE, by itself, creates a new NUM_KEYPAD_BACKNOVIBE or raises the existing
% singleton*.
% H = NUM_KEYPAD_BACKNOVIBE returns the handle to a new NUM_KEYPAD_BACKNOVIBE or the handle to
% the existing singleton*.
%
% NUM_KEYPAD_BACKNOVIBE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NUM_KEYPAD_BACKNOVIBE.M with the given input arguments.
%
% NUM_KEYPAD_BACKNOVIBE('Property','Value',...) creates a new NUM_KEYPAD_BACKNOVIBE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Num_Keypad_backnovibe_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Num_Keypad_backnovibe_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% % Begin initialization code - DO NOT EDIT
%BY; Joel Esposito, US Naval Academy, 2011
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RobotGuiControl_OpeningFcn, ...
'gui_OutputFcn', @RobotGuiControl_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Num_Keypad_backnovibe is made visible.
function RobotGuiControl_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Num_Keypad_backnovibe (see VARARGIN)
% Choose default command line output for Num_Keypad_backnovibe
%Global Variables and Startup Processes
% -------------------------------------------------------------------------
% START COPY!
%--------------------------------------------------------------------------
% Cleaning up old ports
serPort = varargin{1};
global a
a = instrfind();
if ~isempty(a)
fclose(a);
pause(1);
delete(a);
pause(1);
end
global ser
% serial port for vibration
% serial port for sending characters
ser = RoombaInit(serPort);
%logging
global keyPresses startTime elapsedTime
keyPresses = [0 0];
startTime = [];
elapsedTime = [];
% speeds and angles
global sV sD bV bD sW sA bW bA
sV = .1; sD = 0.05; % vel in m/s angles in deg W is angluar speed but in m/s?
bV = .2; bD = 0.1;
sW = .05; sA = 5;
bW = .1; bA = 15;
global moving movingTest
movingTest = 1;
moving=0;
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
%--------------------------
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 2];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
travelDist(ser, sV, -sD);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 3];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
%--------------------------
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 4];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, bW, bA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 5];
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
travelDist(ser, sV, sD);
moving=0;
end
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 6];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, bW, -bA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 7];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, sW, sA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 8];
%--------
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
travelDist(ser, bV, bD);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list 9];
%------------------------COPY TO ALL OTHERS
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
end
global moving movingTest
if (movingTest ==0)||(moving ==0)
moving=1;
turnAngle(ser, sW, -sA);
moving=0;
end
%--------------------------
% --- Executes on button press in pushbutton_back.
function pushbutton_back_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_back (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%--------
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
% --- Executes on button press in pushbutton_del.
function pushbutton_del_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_del (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%--------
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
keyPresses(2) = keyPresses(2) +1;
if isempty(startTime)
startTime = tic;
end
% --- Executes on button press in pushbutton_enter.
function pushbutton_enter_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_enter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses(1) = keyPresses(1) +1;
if isempty(startTime)
startTime = tic;
else
elapsedTime = toc(startTime);
fprintf('Sec: %f, Keystrokes: %d \n ', [elapsedTime keyPresses(1) ]);
end
%--------------------------------------------------------------------------
% END COPY
%-------------------------------------------------------------------------
% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global list
% list=[list .];
%--------
global ser keyPresses startTime elapsedTime
global sV sD bV bD sW sA bW bA
keyPresses = keyPresses +1;
if isempty(startTime)
startTime = tic;
end
% UIWAIT makes Num_Keypad_backnovibe wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = RobotGuiControl_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%global keyPresses elapsedTime
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
VREP_arm.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/interfaces/VREP/VREP_arm.m
| 12,872 |
utf_8
|
f2d3f587eedac1bfd221fb9000c4cc09
|
%VREP_arm Mirror of V-REP robot arm object
%
% Mirror objects are MATLAB objects that reflect the state of objects in
% the V-REP environment. Methods allow the V-REP state to be examined or
% changed.
%
% This is a concrete class, derived from VREP_mirror, for all V-REP robot
% arm objects and allows access to joint variables.
%
% Methods throw exception if an error occurs.
%
% Example::
% vrep = VREP();
% arm = vrep.arm('IRB140');
% q = arm.getq();
% arm.setq(zeros(1,6));
% arm.setpose(T); % set pose of base
%
% Methods::
%
% getq get joint coordinates
% setq set joint coordinates
% setjointmode set joint control parameters
% animate animate a joint coordinate trajectory
% teach graphical teach pendant
%
% Superclass methods (VREP_obj)::
% getpos get position of object
% setpos set position of object
% getorient get orientation of object
% setorient set orientation of object
% getpose get pose of object given
% setpose set pose of object
%
% can be used to set/get the pose of the robot base.
%
% Superclass methods (VREP_mirror)::
% getname get object name
%-
% setparam_bool set object boolean parameter
% setparam_int set object integer parameter
% setparam_float set object float parameter
%
% getparam_bool get object boolean parameter
% getparam_int get object integer parameter
% getparam_float get object float parameter
%
% Properties::
% n Number of joints
%
% See also VREP_mirror, VREP_obj, VREP_arm, VREP_camera, VREP_hokuyo.
% Copyright (C) 1993-2015, 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
classdef VREP_arm < VREP_obj
properties(GetAccess=public, SetAccess=protected)
q
joint % VREP joint object handles
n % number of joints
end
methods
function arm = VREP_arm(vrep, name, varargin)
%VREP_arm.VREP_arm Create a robot arm mirror object
%
% ARM = VREP_arm(NAME, OPTIONS) is a mirror object that corresponds to the
% robot arm named NAME in the V-REP environment.
%
% Options::
% 'fmt',F Specify format for joint object names (default '%s_joint%d')
%
% Notes::
% - The number of joints is found by searching for objects
% with names systematically derived from the root object name, by
% default named NAME_N where N is the joint number starting at 0.
%
% See also VREP.arm.
h = vrep.gethandle(name);
if h == 0
error('no such object as %s in the scene', name);
end
arm = arm@VREP_obj(vrep, name);
opt.fmt = '%s_joint%d';
opt = tb_optparse(opt, varargin);
arm.name = name;
% find all the _joint objects, we don't know how many joints so we
% keep going till we get an error
j = 1;
while true
[h,s] = vrep.gethandle(opt.fmt, name, j);
if s ~= 0
break
end
arm.joint(j) = h;
j = j+1;
end
arm.n = j - 1;
% set all joints to passive mode
% for j=1:arm.n
% arm.vrep.simxSetJointMode(arm.client, arm.joint(j), arm.vrep.sim_jointmode_passive, arm.vrep.simx_opmode_oneshot_wait);
% end
end
function q = getq(arm)
%VREP_arm.getq Get joint angles of V-REP robot
%
% ARM.getq() is the vector of joint angles (1xN) from the corresponding
% robot arm in the V-REP simulation.
%
% See also VREP_arm.setq.
for j=1:arm.n
q(j) = arm.vrep.getjoint(arm.joint(j));
end
end
function setq(arm, q)
%VREP_arm.setq Set joint angles of V-REP robot
%
% ARM.setq(Q) sets the joint angles of the corresponding
% robot arm in the V-REP simulation to Q (1xN).
%
% See also VREP_arm.getq.
for j=1:arm.n
arm.vrep.setjoint(arm.joint(j), q(j));
end
end
function setqt(arm, q)
%VREP_arm.setq Set joint angles of V-REP robot
%
% ARM.setq(Q) sets the joint angles of the corresponding
% robot arm in the V-REP simulation to Q (1xN).
for j=1:arm.n
arm.vrep.setjointtarget(arm.joint(j), q(j));
end
end
function setjointmode(arm, motor, control)
%VREP_arm.setjointmode Set joint mode
%
% ARM.setjointmode(M, C) sets the motor enable M (0 or 1) and motor control
% C (0 or 1) parameters for all joints of this robot arm.
for j=1:arm.n
arm.vrep.setobjparam_int(arm.joint(j), 2000, 1); %motor enable
arm.vrep.setobjparam_int(arm.joint(j), 2001, 1); %motor control enable
end
end
function animate(arm, qt, varargin)
%VREP_arm.setq Animate V-REP robot
%
% R.animate(QT, OPTIONS) animates the corresponding V-REP robot with
% configurations taken from consecutive rows of QT (MxN) which represents
% an M-point trajectory and N is the number of robot joints.
%
% Options::
% 'delay',D Delay (s) betwen frames for animation (default 0.1)
% 'fps',fps Number of frames per second for display, inverse of 'delay' option
% '[no]loop' Loop over the trajectory forever
%
% See also SerialLink.plot.
opt.delay = 0.1;
opt.fps = [];
opt.loop = false;
opt = tb_optparse(opt, varargin);
if ~isempty(opt.fps)
opt.delay = 1/opt.fps;
end
while true
for i=1:numrows(qt)
arm.setq(qt(i,:));
pause(opt.delay);
end
if ~opt.loop
break;
end
end
end
function teach(obj, varargin)
%VREP_arm.teach Graphical teach pendant
%
% R.teach(OPTIONS) drive a V-REP robot by means of a graphical slider panel.
%
% Options::
% 'degrees' Display angles in degrees (default radians)
% 'q0',q Set initial joint coordinates
%
%
% Notes::
% - The slider limits are all assumed to be [-pi, +pi]
%
% See also SerialLink.plot.
n = obj.n;
%-------------------------------
% parameters for teach panel
bgcol = [135 206 250]/255; % background color
height = 1/(n+2); % height of slider rows
%-------------------------------
opt.degrees = false;
opt.q0 = [];
% TODO: options for rpy, or eul angle display
opt = tb_optparse(opt, varargin);
% drivebot(r, q)
% drivebot(r, 'deg')
if isempty(opt.q0)
q = obj.getq();
else
q = opt.q0;
end
% set up scale factor, from actual limits in radians/metres to display units
qscale = ones(n,1);
for j=1:n
if opt.degrees && L.isrevolute
qscale(j) = 180/pi;
end
qlim(j,:) = [-pi pi];
end
handles.qscale = qscale;
panel = figure(...
'BusyAction', 'cancel', ...
'HandleVisibility', 'off', ...
'Color', bgcol);
pos = get(panel, 'Position');
pos(3:4) = [300 400];
set(panel, 'Position', pos);
set(panel,'MenuBar','none')
set(panel, 'name', 'Teach');
delete( get(panel, 'Children') )
%---- now make the sliders
for j=1:n
% slider label
uicontrol(panel, 'Style', 'text', ...
'Units', 'normalized', ...
'BackgroundColor', bgcol, ...
'Position', [0 height*(n-j) 0.15 height], ...
'FontUnits', 'normalized', ...
'FontSize', 0.5, ...
'String', sprintf('q%d', j));
% slider itself
q(j) = max( qlim(j,1), min( qlim(j,2), q(j) ) ); % clip to range
handles.slider(j) = uicontrol(panel, 'Style', 'slider', ...
'Units', 'normalized', ...
'Position', [0.15 height*(n-j) 0.65 height], ...
'Min', qlim(j,1), ...
'Max', qlim(j,2), ...
'Value', q(j), ...
'Tag', sprintf('Slider%d', j));
% text box showing slider value, also editable
handles.edit(j) = uicontrol(panel, 'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [0.80 height*(n-j)+.01 0.20 height*0.9], ...
'BackgroundColor', bgcol, ...
'String', num2str(qscale(j)*q(j), 3), ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'Tag', sprintf('Edit%d', j));
end
%---- robot name text box
uicontrol(panel, 'Style', 'text', ...
'Units', 'normalized', ...
'FontUnits', 'normalized', ...
'FontSize', 1, ...
'HorizontalAlignment', 'center', ...
'Position', [0.05 1-height*1.5 0.9 height], ...
'BackgroundColor', 'white', ...
'String', obj.name);
handles.arm = obj;
% now assign the callbacks
for j=1:n
% text edit box
set(handles.edit(j), ...
'Interruptible', 'off', ...
'Callback', @(src,event)teach_callback(j, handles, src));
% slider
set(handles.slider(j), ...
'Interruptible', 'off', ...
'BusyAction', 'queue', ...
'Callback', @(src,event)teach_callback(j, handles, src));
end
end
end
end
function teach_callback(j, handles, src)
% called on changes to a slider or to the edit box showing joint coordinate
%
% src the object that caused the event
% name name of the robot
% j the joint index concerned (1..N)
% slider true if the
qscale = handles.qscale;
switch get(src, 'Style')
case 'slider'
% slider changed, get value and reflect it to edit box
newval = get(src, 'Value');
set(handles.edit(j), 'String', num2str(qscale(j)*newval));
case 'edit'
% edit box changed, get value and reflect it to slider
newval = str2double(get(src, 'String')) / qscale(j);
set(handles.slider(j), 'Value', newval);
end
%fprintf('newval %d %f\n', j, newval);
handles.arm.vrep.setjoint(handles.arm.joint(j), newval);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
walking.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/examples/walking.m
| 4,704 |
utf_8
|
415446e79beb2da9251d7463e6ad652b
|
% set the dimensions of the two leg links
% 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 walking(varargin)
opt.niterations = 500;
opt.movie = [];
opt = tb_optparse(opt, varargin);
L1 = 0.1; L2 = 0.1;
fprintf('create leg model\n');
% create the leg links based on DH parameters
% theta d a alpha
links(1) = Link([ 0 0 0 pi/2 ], 'standard');
links(2) = Link([ 0 0 L1 0 ], 'standard');
links(3) = Link([ 0 0 -L2 0 ], 'standard');
% now create a robot to represent a single leg
leg = SerialLink(links, 'name', 'leg', 'offset', [pi/2 0 -pi/2]);
% define the key parameters of the gait trajectory, walking in the
% x-direction
xf = 5; xb = -xf; % forward and backward limits for foot on ground
y = 5; % distance of foot from body along y-axis
zu = 2; zd = 5; % height of foot when up and down
% define the rectangular path taken by the foot
segments = [xf y zd; xb y zd; xb y zu; xf y zu] * 0.01;
% build the gait. the points are:
% 1 start of walking stroke
% 2 end of walking stroke
% 3 end of foot raise
% 4 foot raised and forward
%
% The segments times are :
% 1->2 3s
% 2->3 0.5s
% 3->4 1s
% 4->1 0.5ss
%
% A total of 4s, of which 3s is walking and 1s is reset. At 0.01s sample
% time this is exactly 400 steps long.
%
% We use a finite acceleration time to get a nice smooth path, which means
% that the foot never actually goes through any of these points. This
% makes setting the initial robot pose and velocity difficult.
%
% Intead we create a longer cyclic path: 1, 2, 3, 4, 1, 2, 3, 4. The
% first 1->2 segment includes the initial ramp up, and the final 3->4
% has the slow down. However the middle 2->3->4->1 is smooth cyclic
% motion so we "cut it out" and use it.
fprintf('create trajectory\n');
segments = [segments; segments];
tseg = [3 0.25 0.5 0.25]';
tseg = [1; tseg; tseg];
x = mstraj(segments, [], tseg, segments(1,:), 0.01, 0.1);
% pull out the cycle
fprintf('inverse kinematics (this will take a while)...');
xcycle = x(100:500,:);
qcycle = leg.ikine( transl(xcycle), 'mask', [1 1 1 0 0 0] );
% dimensions of the robot's rectangular body, width and height, the legs
% are at each corner.
W = 0.1; L = 0.2;
% a bit of optimization. We use a lot of plotting options to
% make the animation fast: turn off annotations like wrist axes, ground
% shadow, joint axes, no smooth shading. Rather than parse the switches
% each cycle we pre-digest them here into a plotopt struct.
% plotopt = leg.plot({'noraise', 'nobase', 'noshadow', ...
% 'nowrist', 'nojaxes'});
% plotopt = leg.plot({'noraise', 'norender', 'nobase', 'noshadow', ...
% 'nowrist', 'nojaxes', 'ortho'});
fprintf('\nanimate\n');
plotopt = {'noraise', 'nobase', 'noshadow', 'nowrist', 'nojaxes', 'delay', 0};
% create 4 leg robots. Each is a clone of the leg robot we built above,
% has a unique name, and a base transform to represent it's position
% on the body of the walking robot.
legs(1) = SerialLink(leg, 'name', 'leg1');
legs(2) = SerialLink(leg, 'name', 'leg2', 'base', transl(-L, 0, 0));
legs(3) = SerialLink(leg, 'name', 'leg3', 'base', transl(-L, -W, 0)*trotz(pi));
legs(4) = SerialLink(leg, 'name', 'leg4', 'base', transl(0, -W, 0)*trotz(pi));
% create a fixed size axis for the robot, and set z positive downward
clf; axis([-0.3 0.1 -0.2 0.2 -0.15 0.05]); set(gca,'Zdir', 'reverse')
hold on
% draw the robot's body
patch([0 -L -L 0], [0 0 -W -W], [0 0 0 0], ...
'FaceColor', 'r', 'FaceAlpha', 0.5)
% instantiate each robot in the axes
for i=1:4
legs(i).plot(qcycle(1,:), plotopt{:});
end
hold off
% walk!
k = 1;
A = Animate(opt.movie);
for i=1:opt.niterations
legs(1).animate( gait(qcycle, k, 0, 0));
legs(2).animate( gait(qcycle, k, 100, 0));
legs(3).animate( gait(qcycle, k, 200, 1));
legs(4).animate( gait(qcycle, k, 300, 1));
drawnow
k = k+1;
A.add();
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
sensorfield.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/examples/sensorfield.m
| 884 |
utf_8
|
97e07ff1557dbc0f620859d66506f495
|
% 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 sensor = sensorfield(x, y)
xc = 60; yc = 90;
sensor = 200 ./ ((x-xc).^2 + (y-yc).^2 + 200);
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
gait.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/examples/gait.m
| 949 |
utf_8
|
43edd6a553ff1f0cbfebbc706ff37f88
|
% 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 q = gait(cycle, k, offset, flip)
k = mod(k+offset-1, numrows(cycle)) + 1;
q = cycle(k,:);
if flip
q(1) = -q(1); % for left-side legs
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
braitenberg.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/examples/braitenberg.m
| 2,400 |
utf_8
|
37f654774804c3ca95e847c6191036b9
|
% 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 p = braitenberg(world, robot)
% these are coordinates (x,y)
% display the world, obstacle, robot and target
image(world/max(world(:))*100)
colormap(gray);
set(gca, 'Ydir', 'normal');
xlabel('x');
ylabel('y');
hold on
if nargin < 2
disp('Click on a start point');
[x,y] = ginput(1);
robot = [x y];
end
if length(robot) == 2
T = transl( [robot 0] );
else
T = transl( [robot(1:2) 0] ) * trotz(robot(3));
end
p = [];
sensorOffset = 2;
forwardStep = 1.0;
while 1
% read the left and right sensor
leftSensor = sensorRead(world, T, transl(0, -sensorOffset, 0));
rightSensor = sensorRead(world, T, transl(0, sensorOffset, 0));
% change our heading based on the ratio of the sensors
dth = rightSensor / leftSensor - 1;
% bad sensor reading means we fell off the world
if isnan(dth)
break
end
% update the robot's pose
dT = trotz(dth) * transl(forwardStep, 0, 0);
T = T * dT;
% display the robot's position
xyz = transl( T ); % get position
rpy = tr2rpy( T ); % get heading angle
plot(xyz(1), xyz(2), 'g.');
p = [p; xyz(1:2)' rpy(3)];
pause(0.1);
if numrows(p) > 150
break;
end
end
hold off
end
% return the sensor reading for the given robot pose and relative pose
% of the sensor.
function s = sensorRead(field, robot, Tsens)
xyz = transl( robot * Tsens );
s = interp2(field, xyz(1), xyz(2));
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
SerialLinkTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/SerialLinkTest.m
| 30,524 |
utf_8
|
6fa420d1b0d296cd2ce087b11325acd5
|
%% This is for testing the SerialLink functions in the robotics Toolbox
function tests = SerialLinkTest
tests = functiontests(localfunctions);
clc
end
function setupOnce(tc)
mdl_puma560;
tc.TestData.p560 = p560;
mdl_planar2
tc.TestData.p2 = p2;
mdl_puma560akb
tc.TestData.p560m = p560m;
mdl_stanford
tc.TestData.stanf = stanf;
end
function teardownOnce(tc)
close all
end
function SerialLink_test(tc)
% test making a robot from links
L(1)=Link([1 1 1 1 1]);
L(2)=Link([0 1 0 1 0]);
R1 = SerialLink(L,'name','robot1','comment', 'test robot','manufacturer', 'test',...
'base', eye(4,4), 'tool', eye(4,4), 'offset', [1 1 0 0 0 0 ] );
% test makin a robot from DH matrix
DH = [pi/2 0 0 1; 0 2 0 0];
R2 = SerialLink(DH,'name','Robot2');
end
function SerialLinkMDH_test(tc)
% minimalistic test of modified DH functionality
% most code is common, need to exercise MDH code in Link and also for
% RNE
mdl_puma560akb
% qr is not set by the script, it clashes with the builtin function QR(tc)
qz = [0 0 0 0 0 0];
T = p560m.fkine(qz);
J = p560m.jacobe(qz);
tau = p560m.rne(qz, qz, qz);
end
function dyn_test(tc)
mdl_puma560
p560.dyn;
mdl_puma560akb
p560m.dyn;
end
% * - compound two robots
function compound_test(tc)
L(1)=Link([1 1 1 1 1]);
L(2)=Link([0 1 0 1 0]);
R1 = SerialLink(L,'name','robot1','comment', 'test robot','manufacturer', 'test',...
'base', eye(4,4), 'tool', eye(4,4), 'offset', [1 1 0 0 0 0 ] );
DH = [pi/2 0 0 1; 0 2 0 0];
R2 = SerialLink(DH,'name','Robot2');
%Test two different compunding situations
R3 = R1*R2;
R4 = R1*R3;
end
%% Kinematic methods
% fkine - forward kinematics
function fkine_test(tc)
% create simple RP robot we can reason about
L(1)=Link([0 2 3 0 0]);
L(2)=Link([0 0 0 0 1]);
R1 = SerialLink(L,'name','robot1','comment', 'test robot','manufacturer', 'test',...
'base', eye(4,4), 'tool', eye(4,4) );
tc.verifyTrue(isa( R1.fkine([0,0]), 'SE3') );
tc.verifyEqual(R1.fkine([0,0]).T, transl(3,0,2), 'absTol',1e-6);
tc.verifyEqual(R1.fkine([pi/2,0]).T, transl(0,3,2)*trotz(pi/2), 'absTol',1e-6);
tc.verifyEqual(R1.fkine([0,1]).T, transl(3,0,3), 'absTol',1e-6);
mdl_puma560
T=p560.fkine( [0 0 0 0 0 0; 0 0.03 -0.0365 0 0 0] );
tc.verifyEqual(length(T), 2, 'SE3' );;
end
function plot_test(tc)
clf
L(1)=Link([1 1 1 1 0]);
L(1).qlim = [-5 5];
L(2)=Link([0 1 0 1 0]);
R1 = SerialLink(L,'name','robot1','comment', 'test robot','manufacturer', 'test',...
'base', eye(4,4), 'tool', eye(4,4), 'offset', [1 1 0 0 0 0 ] );
R1.plot([1 1]);
close all
end
function plot_animate_test(tc)
tc.assumeTrue(ispc || ismac);
fname = fullfile(tempdir, 'puma.mp4');
qt = jtraj(tc.TestData.p560.qz, tc.TestData.p560.qr, 50);
tc.TestData.p560.plot(qt, 'movie', fname);
tc.verifyTrue(exist(fname, 'file') == 2);
delete(fname)
end
function plot3d_test(tc)
clf
tc.TestData.p560.plot3d( tc.TestData.p560.qn );
close(gcf)
end
function teach_test(tc)
tc.TestData.p560.teach();
close all
tc.TestData.p560.teach('eul');
close all
tc.TestData.p560.teach('eul', 'deg');
close all
tc.TestData.p560.teach('rpy');
close all
tc.TestData.p560.teach('rpy/xyz');
close all
tc.TestData.p560.teach('rpy/zyx');
close all
tc.TestData.p560.teach('approach');
close all
tc.TestData.p560.teach('callback', @(r, q) fprintf('hello') );
close all
tc.TestData.p2.teach();
close all
tc.TestData.p2.teach('2d');
close all
figure
figure
tc.TestData.p2.teach([0.2 0.3]);
close all
close all
end
%%--------------------------------------------------------------------------
%inverse kinematics for 6-axis arm with sph.wrist
function ikine6s_puma_test(tc)
% puma case
mdl_puma560;
qn = [0 pi/4 -pi 1 pi/4 0];
T = p560.fkine(qn);
qik = p560.ikine6s(T,'ru');
tc.verifyEqual(p560.fkine(qik).T, T.T, 'absTol', 1e-6);
tc.verifyTrue(qik(2) > 0);
T = p560.fkine(qn);
qik = p560.ikine6s(T,'ld');
tc.verifyEqual(p560.fkine(qik).T, T.T, 'absTol', 1e-6);
tc.verifyTrue(qik(2) < 0);
% error handling
mdl_puma560akb
tc.verifyError( @() p560m.ikine6s(T), 'RTB:ikine:notsupported' );
tc.verifyError( @() tc.TestData.p2.ikine6s(T), 'RTB:ikine:notsupported' );
end
function ikine6s_stanford_test(tc)
% stanford arm case
q = [pi/4 pi/4 0.3 pi/4 -pi/4 pi/4];
T = tc.TestData.stanf.fkine(q);
qik = tc.TestData.stanf.ikine6s(T);
tc.verifyEqual(tc.TestData.stanf.fkine(qik).T, T.T, 'absTol', 1e-6);
end
function ikine6s_KR5_test(tc)
% kr5 arm case
mdl_KR5
q = [0 pi/4 -pi 1 pi/4 0];
T = KR5.fkine(q);
qik = KR5.ikine6s(T);
tc.verifyEqual(KR5.fkine(qik).T, T.T, 'absTol', 1e-6);
end
function ikine6s_IRB140_test(tc)
tc.assumeTrue(false); %HACK
% nooffset type
mdl_irb140
q = [0 -3*pi/4 0 0 pi/4 0];
T = irb140.fkine(q);
qik = irb140.ikine6s(T);
tc.verifyEqual(irb140.fkine(qik).T, T.T, 'absTol', 1e-6);
end
function ikine_test(tc)
T = tc.TestData.p560.fkine(tc.TestData.p560.qn);
qik = tc.TestData.p560.ikine(T, [0 0 3 0 0 0]);
T2 = tc.TestData.p560.fkine(qik);
tc.verifyEqual(T.T, T2.T,'absTol',1e-6);
end
function ikunc_optim_test(tc)
T = tc.TestData.p560.fkine(tc.TestData.p560.qn);
qik = tc.TestData.p560.ikunc(T);
T2 = tc.TestData.p560.fkine(qik);
tc.verifyEqual(T.T, T2.T,'absTol',1e-6);
end
function ikcon_optim_test(tc)
tc.assumeTrue(false); %HACK
qn = [0 pi/4 -pi 0 pi/4 0];
T = tc.TestData.p560.fkine(qn);
qik = tc.TestData.p560.ikcon(T);
T2 = tc.TestData.p560.fkine(qik);
tc.verifyEqual(T.T, T2.T,'absTol',1e-6);
end
function ikine_sym_test(tc)
% 2DOF test
p2 = SerialLink(tc.TestData.p2); % clone it
q = p2.ikine_sym(2);
% is the solution sane
tc.verifyLength(q, 2);
tc.verifyTrue(iscell(q));
tc.verifyTrue(isa(q{1}, 'sym'));
tc.verifyLength(q{1}, 2);
tc.verifyTrue(isa(q{2}, 'sym'));
tc.verifyLength(q{1}, 2);
% process the solutions
q1 = subs(q{1}, {'tx', 'ty'}, {1,1}); % convert to numeric
sol = eval(q1)';
q2 = subs(q{2}, {'tx', 'ty', 'q1'}, {1,1, q1(1)});
x = eval(q2); % first solution
sol(1,2) = x(1);
q2 = subs(q{2}, {'tx', 'ty', 'q1'}, {1,1, q1(2)}); % second solution
x = eval(q2);
sol(2,2) = x(1);
% check the FK is good
tc.verifyEqual(transl(tc.TestData.p2.fkine(sol(1,:))), [1 1 0]);
tc.verifyEqual(transl(tc.TestData.p2.fkine(sol(2,:))), [1 1 0]);
tc.verifyError( @() tc.TestData.p2.ikine_sym(4), 'RTB:ikine_sym:badarg');
end
function ikine_sym2_test(tc)
tc.assumeTrue(false); %HACK
% 3DOF test
% create robot arm with no offset (IRB140 style)
robot = SerialLink([0 0.5 0 pi/2; 0 0 0.5 0; 0 0 0.5 0])
test_sym_ik(robot)
% create robot arm with offset (Puma560 style)
robot = SerialLink(tc.TestData.p560.links(1:3));
robot = SerialLink(robot); % clone it
test_sym_ik(robot)
function test_sym_ik(robot)
% test all 8 solutions are good
q = robot.ikine_sym(3);
% process the solutions
T = robot.fkine([0.2, 0.3, 0.4]); % choose joint angles
pe = num2cell(T.t');
q1 = subs(q{1}, {'tx', 'ty', 'tz'}, pe); % convert to numeric
qik = [];
ss = [];
for s1=1:2
try
sol1 = eval(q1(s1));
catch
fprintf('** q1(%d) eval failure\n', s1);
end
q2 = subs(q{2}, {'tx', 'ty', 'tz', 'q1'}, [pe q1(s1)]);
for s2=1:2
try
sol2 = eval(q2(s2));
catch
fprintf('** q2(%d) eval failure\n', s2);
continue;
end
q3 = subs(q{3}, {'tx', 'ty', 'tz', 'q1', 'q2'}, [pe q1(s1), q2(s2)]);
for s3=1:2
try
sol3 = eval(q3(s3));
qik = [qik; sol1 sol2 sol3];
ss = [ss; s1 s2 s3];
catch
fprintf('** q3(%d) eval failure\n', s3);
end
end
end
end
% check the FK is good, zero residual
nn = [];
for qq=qik'
nn = [nn; norm(transl(robot.fkine(qq')-T))];
end
tc.verifyEqual(sum(nn), 0, 'absTol', 1e-6);
end
end
%%--------------------------------------------------------------------------
function jacob0_test(tc)
function J = jacob0_approx(robot, q, d)
e = eye(robot.n);
T0 = robot.fkine(q);
R0 = t2r(T0);
J = [];
for i=1:robot.n
Ji = (robot.fkine(q + e(i,:)*d) - T0) / d;
J = [J [Ji(1:3,4); vex(Ji(1:3,1:3)*R0')]];
end
end
% implictly tests jacobe
qz = [0 1 0 0 2 0];
qn = [0 pi/4 -pi 1 pi/4 0];
out = tc.TestData.p560.jacob0(qz);
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
tc.verifyEqual(tc.TestData.p560.jacob0(qz), jacob0_approx(tc.TestData.p560, qz, 1e-8), 'absTol', 1e-4);
tc.verifyEqual(tc.TestData.p560.jacob0(qn), jacob0_approx(tc.TestData.p560, qn, 1e-8), 'absTol', 1e-4);
expected_out = jacob0_approx(tc.TestData.p560, qn, 1e-8)
out = tc.TestData.p560.jacob0(qn*180/pi, 'deg');
tc.verifyEqual(out,expected_out,'absTol',1e-4);
out = tc.TestData.p560.jacob0(qn, 'rpy');
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
out = tc.TestData.p560.jacob0(qn, 'eul');
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
out = tc.TestData.p560.jacob0(qn, 'exp');
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
out = tc.TestData.p560.jacob0(qn, 'trans');
tc.verifyClass(out, 'double');
tc.verifySize(out, [3 6]);
out = tc.TestData.p560.jacob0(qn, 'rot');
tc.verifyClass(out, 'double');
tc.verifySize(out, [3 6]);
tc.verifyEqual(tc.TestData.p560.jacob0(qn), jacob0_approx(tc.TestData.p560, qn, 1e-8), 'absTol', 1e-4);
out = tc.TestData.stanf.jacob0([0 0 0 0 0 0]);
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
tc.verifyEqual(tc.TestData.stanf.jacob0(qn), jacob0_approx(tc.TestData.stanf, qn, 1e-8), 'absTol', 1e-4);
end
function jacobe_test(tc)
function J = jacobe_approx(robot, q, d)
e = eye(robot.n);
T0 = robot.fkine(q);
R0 = t2r(T0);
J = [];
for i=1:robot.n
Ji = (robot.fkine(q + e(i,:)*d) - T0) / d;
J = [J [R0'*Ji(1:3,4); vex(R0'*Ji(1:3,1:3))]];
end
end
qz = [0 1 0 0 2 0];
qn = [0 pi/4 -pi 1 pi/4 0];
out = tc.TestData.p560.jacobe(qz)
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
expected_out = jacobe_approx(tc.TestData.p560, qz, 1e-8)
tc.verifyEqual(out,expected_out,'absTol',1e-4);
out = tc.TestData.p560.jacobe(qz*180/pi, 'deg');
tc.verifyEqual(out,expected_out,'absTol',1e-4);
out = tc.TestData.p560.jacobe(qn);
expected_out = jacobe_approx(tc.TestData.p560, qn, 1e-8)
tc.verifyEqual(out,expected_out,'absTol',1e-4);
out = tc.TestData.p560.jacobe(qn*180/pi, 'deg');
tc.verifyEqual(out,expected_out,'absTol',1e-4);
out = tc.TestData.p560.jacob0(qn, 'rpy');
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
out = tc.TestData.p560.jacob0(qn, 'eul');
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
out = tc.TestData.p560.jacob0(qn, 'exp');
tc.verifyClass(out, 'double');
tc.verifySize(out, [6 6]);
out = tc.TestData.p560.jacob0(qn, 'trans');
tc.verifyClass(out, 'double');
tc.verifySize(out, [3 6]);
out = tc.TestData.p560.jacob0(qn, 'rot');
tc.verifyClass(out, 'double');
tc.verifySize(out, [3 6]);
tc.verifyWarning( @() tc.TestData.p560.jacobn(qn), 'RTB:SerialLink:deprecated');
end
function maniplty_test(tc)
mdl_puma560;
q = [0 pi/4 -pi 1 pi/4 0];
tc.verifyEqual(p560.maniplty(q), 0.0786, 'absTol',1e-4);
tc.verifyEqual(p560.maniplty(q, 'trans'), 0.1112, 'absTol',1e-4);
tc.verifyEqual(p560.maniplty(q, 'rot'), 2.5936, 'absTol',1e-4);
tc.verifyEqual(p560.maniplty(q, 'asada', 'trans'), 0.2733, 'absTol',1e-4);
end
function jacob_dot_test(tc)
tc.assumeTrue(false); %HACK
function Jdqd = jacob_dot_approx(robot, q, qd, d)
e = eye(robot.n);
J0 = robot.jacob0(q);
Jdqd = zeros(6,1);
for i=1:robot.n
Ji = (robot.jacob0(q + e(i,:)*d) - J0) / d;
Jdqd = Jdqd + Ji * qd(i);
end
end
q = rand(1,6);
qd = rand(1,6);
jacob_dot_approx(tc.TestData.p560, q, qd, 1e-8)*qd'
tc.TestData.p560.jacob_dot(q, qd)
end
%% Dynamics methods
function rne_test(tc)
% use something simple we can reason about
mdl_twolink
g = twolink.gravity(3);
qz = [0 0]; % need this to get around a MATLAB bug passing values from a script
% different poses
Q = twolink.rne([0 0], qz, qz, 'slow');
tc.verifyEqual(Q, g*[2 0.5], 'absTol', 1e-6);
Q = twolink.rne([0 pi/2], qz, qz);
tc.verifyEqual(Q, g*[1.5 0], 'absTol', 1e-6);
Q = twolink.rne([pi/2 0], qz, qz);
tc.verifyEqual(Q, g*[0 0], 'absTol', 1e-6);
% change gravity
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 0]);
tc.verifyEqual(Q, g*[0 0], 'absTol', 1e-6);
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 0]');
tc.verifyEqual(Q, g*[0 0], 'absTol', 1e-6);
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 0]);
tc.verifyEqual(Q, g*[0 0], 'absTol', 1e-6);
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 -g]);
tc.verifyEqual(Q, g*[-2 -0.5], 'absTol', 1e-6);
% add an external force in end-effector frame
% y-axis is vertically upward
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 0], 'fext', [1 0 0 0 0 0]);
tc.verifyEqual(Q, [0 0], 'absTol', 1e-6);
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 0], 'fext', [0 1 0 0 0 0]);
tc.verifyEqual(Q, [2 1], 'absTol', 1e-6);
Q = twolink.rne([0 0], qz, qz, 'gravity', [0 0 0], 'fext', [0 0 1 0 0 0]);
tc.verifyEqual(Q, [0 0], 'absTol', 1e-6);
% test the [q qd qdd] case
Q1 = twolink.rne([1 2], [3 4], [5 6]);
Q2 = twolink.rne([1 2 3 4 5 6]);
tc.verifyEqual(Q1, Q2, 'absTol', 1e-6);
% test the matrix input case
Q1 = twolink.rne([1 2], [3 4], [5 6]);
Q2 = twolink.rne([5 6], [1 2], [3 4]);
Q3 = twolink.rne([3 4], [5 6], [1 2]);
Q4 = twolink.rne([1 2; 5 6; 3 4], [3 4; 1 2; 5 6], [5 6; 3 4; 1 2]);
tc.verifyEqual([Q1; Q2; Q3], Q4, 'absTol', 1e-6);
% probably should do a robot with a prismatic axis (or two)
end
function rne_mdh_test(tc)
q = rand(1,6);
tc.TestData.p560m.rne(q, q, q);
end
% accel - forward dynamics
function accel_test(tc)
qd = 0.5 * [1 1 1 1 1 1];
qz = [0 1 0 0 2 0];
Q = tc.TestData.p560.rne(tc.TestData.p560.qn, qz, qz);
out = tc.TestData.p560.accel(qz, qd, Q);
expected_out = [ -9.3397 4.9666 1.6095 -5.4305 5.9885 -2.1228]';
tc.verifyEqual(out, expected_out,'absTol',1e-4);
out = tc.TestData.p560.accel([qz, qd,Q]);
tc.verifyEqual(out, expected_out,'absTol',1e-4);
out = tc.TestData.p560.accel([qz, qd,Q]');
tc.verifyEqual(out,expected_out,'absTol',1e-4);
qd = [0.1 0.1 0.1 0.1 0.1 0.1;0.2 0.2 0.2 0.2 0.2 0.2];
qz = [0 1 0 0 2 0;0 0.5 0 0 1 0];
qd1 = [0.1 0.1 0.1 0.1 0.1 0.1];
qd2 = [0.2 0.2 0.2 0.2 0.2 0.2];
qz1 = [0 1 0 0 2 0];
qz2 = [0 0.5 0 0 1 0];
qn1 = [0 pi/4 -pi 1 pi/4 0];
qn2 = [0 pi/2 -pi 1 pi/2 0];
Q1 = tc.TestData.p560.rne(qn1,qz1,qz1);
Q2 = tc.TestData.p560.rne(qn2,qz2,qz2);
q3 = [Q1;Q2];
out = tc.TestData.p560.accel(qz, qd,q3);
expected_out = [
-8.2760 5.8119 3.1487 -4.6392 6.9558 -1.6774
-8.3467 -4.8514 6.0575 -4.9232 3.1244 -1.7861 ];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
tc.verifyError( @() tc.TestData.p560.accel(), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( [ 1 2]), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( qz, qz, qd1), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( qz, qd1, qd1), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( [1 2], qd1, qd1), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( qz1, [1 2], qd1), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( qz1, qz1, [1 2]), 'RTB:accel:badarg');
tc.verifyError( @() tc.TestData.p560.accel( [ 1 2]), 'RTB:accel:badarg');
end
% cinertia - Cartesian manipulator inertia matrix
function cinertia_test(tc)
mdl_puma560;
qn = [0 pi/4 -pi 1 pi/4 0];
out = p560.cinertia(qn);
expected_out = [18.0741 -2.2763 -8.8446 -0.0283 0.7541 -0.4015
-2.2763 11.2461 1.7238 -0.0750 0.2214 -0.4733
-8.8446 1.7238 14.1135 -0.0300 0.7525 -0.4032
-0.0283 -0.0750 -0.0300 0.1377 -0.0171 0.0492
0.7541 0.2214 0.7525 -0.0171 0.4612 -0.2461
-0.4015 -0.4733 -0.4032 0.0492 -0.2461 0.3457];
tc.verifyEqual(out,expected_out,'absTol',1e-4);;
end
% coriolis - centripetal/coriolis torque
function coriolis_test(tc)
mdl_puma560;
qd = 0.5 * [1 1 1 1 1 1];
qn = [0 pi/4 -pi 1 pi/4 0];
out = p560.coriolis(qn, qd);
expected_out = [
-0.1336 -0.6458 0.0845 0.0005 -0.0008 0.0000
0.3136 0.1922 0.3851 -0.0018 -0.0007 0.0000
-0.1803 -0.1934 -0.0005 -0.0009 -0.0014 0.0000
0.0007 0.0008 0.0003 0.0001 0.0003 -0.0000
-0.0004 0.0005 0.0005 -0.0003 -0.0000 -0.0000
0.0000 0.0000 0.0000 -0.0000 0.0000 0
];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
qd = [0.1 0.1 0.1 0.1 0.1 0.1;0.2 0.2 0.2 0.2 0.2 0.2];
qn = [0 pi/4 -pi 1 pi/4 0; 0 pi/2 -pi 1 pi/2 0];
out = p560.coriolis(qn, qd);
expected_out(:,:,1) = [
-0.0267 -0.1292 0.0169 0.0001 -0.0002 0.0000
0.0627 0.0384 0.0770 -0.0004 -0.0001 0.0000
-0.0361 -0.0387 -0.0001 -0.0002 -0.0003 0.0000
0.0001 0.0002 0.0001 0.0000 0.0001 -0.0000
-0.0001 0.0001 0.0001 -0.0001 -0.0000 -0.0000
0.0000 0.0000 0.0000 -0.0000 0.0000 0
];
expected_out(:,:,2) = [
-0.0715 -0.1242 -0.0534 0.0008 -0.0001 -0.0000
0.0731 0.0765 0.1535 -0.0009 -0.0007 0.0000
-0.0023 -0.0772 -0.0003 -0.0004 -0.0007 0.0000
0.0004 0.0006 0.0003 0.0000 0.0002 -0.0000
0.0002 0.0004 0.0004 -0.0002 0.0000 0.0000
-0.0000 0.0000 0.0000 -0.0000 -0.0000 0
];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
end
function gravload_test(tc)
qn = [0 pi/4 -pi 1 pi/4 0];
out = tc.TestData.p560.gravload(qn);
expected_out = [-0.0000 31.6334 6.0286 -0.0119 0.0218 0];
tc.verifyEqual(out, expected_out, 'absTol',1e-4);
qn = [0 pi/4 -pi 1 pi/4 0; 0 pi/2 -pi 1 pi/2 0];
out = tc.TestData.p560.gravload(qn);
expected_out = [-0.0000 31.6334 6.0286 -0.0119 0.0218 0
0.0000 7.7198 8.7439 -0.0238 -0.0000 0];
tc.verifyEqual(out, expected_out, 'absTol', 1e-4);
% zero gravity
out = tc.TestData.p560.gravload(tc.TestData.p560.qn, [0 0 0]);
tc.verifyEqual(out, [0 0 0 0 0 0], 'absTol', 1e-4);
tc.verifyError( @() tc.TestData.p560.gravload([1 2 3]), 'RTB:SerialLink:gravload:badarg' );
end
function inertia_test(tc)
mdl_puma560;
qn = [0 pi/4 -pi 1 pi/4 0];
out = p560.inertia(qn);
expected_out = [3.6591 -0.4042 0.1013 -0.0021 -0.0015 -0.0000
-0.4042 4.4128 0.3504 -0.0008 0.0017 0.0000
0.1013 0.3504 0.9377 -0.0008 0.0008 0.0000
-0.0021 -0.0008 -0.0008 0.1925 0.0000 0.0000
-0.0015 0.0017 0.0008 0.0000 0.1713 0.0000
-0.0000 0.0000 0.0000 0.0000 0.0000 0.1941];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
qn = [0 pi/4 -pi 1 pi/4 0; 0 pi/2 -pi 1 pi/2 0];
out = p560.inertia(qn);
expected_out(:,:,1) = [3.6591 -0.4042 0.1013 -0.0021 -0.0015 -0.0000
-0.4042 4.4128 0.3504 -0.0008 0.0017 0.0000
0.1013 0.3504 0.9377 -0.0008 0.0008 0.0000
-0.0021 -0.0008 -0.0008 0.1925 0.0000 0.0000
-0.0015 0.0017 0.0008 0.0000 0.1713 0.0000
-0.0000 0.0000 0.0000 0.0000 0.0000 0.1941];
expected_out(:,:,2) = [2.6621 -0.6880 0.0035 -0.0007 -0.0010 0.0000
-0.6880 4.4114 0.3487 -0.0010 0.0015 0.0000
0.0035 0.3487 0.9359 -0.0010 0.0003 0.0000
-0.0007 -0.0010 -0.0010 0.1926 0.0000 0.0000
-0.0010 0.0015 0.0003 0.0000 0.1713 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.1941];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
end
function dynamic_component_test(tc)
% test that inertial components
q = rand(1,6);
qd = rand(1,6);
qdd = rand(1,6);
robot = tc.TestData.p560.nofriction('all');
I = robot.inertia(q);
C = robot.coriolis(q, qd);
g = robot.gravload(q)';
tau = robot.rne(q, qd, qdd)';
tc.verifyEqual(norm(I*qdd'+C*qd'+g-tau), 0, 'absTol', 1e-8);
end
% itorque - inertia torque
function itorque_test(tc)
mdl_puma560;
qn = [0 pi/4 -pi 1 pi/4 0];
qdd = 0.5 * [1 1 1 1 1 1];
out = p560.itorque(qn,qdd);
expected_out = [1.6763 2.1799 0.6947 0.0944 0.0861 0.0971];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
% rne - inverse dynamics
end
function rne2_test(tc)
mdl_puma560;
qz = [0 1 0 0 2 0];
qn = [0 pi/4 -pi 1 pi/4 0];
out = p560.rne(qn,qz,qz);
expected_out = [-0.9748 59.1306 5.9889 -0.0108 1.8872 0.0001];
tc.verifyEqual(out,expected_out,'absTol',1e-4);
pnf = p560.nofriction('all');
q = rand(1,6);
qd = rand(1,6);
qdd = rand(1,6);
tau1 = pnf.rne(q,qd,qdd);
tau2 = pnf.inertia(q)*qdd' +pnf.coriolis(q,qd)*qd' + pnf.gravload(q)';
tc.verifyEqual(tau1', tau2, 'absTol', 1e-6);
end
% fdyn - forward dynamics
function fdyn_test(tc)
mdl_puma560;
qn = [0 pi/4 -pi 1 pi/4 0];
qd = 0.5 * [1 1 1 1 1 1];
qdo = [0 0 0 0 0 0];
T = 0.0001;
p560 = p560.nofriction();
[TI,Q,QD] = p560.fdyn(T, @(r,t,q,qd) zeros(1,6), qn, qdo);
end
function nofriction_test(tc)
mdl_puma560;
verifyFalse(tc, p560.links(3).B == 0);
verifyFalse(tc, all(p560.links(3).Tc == 0) );
nf = p560.nofriction();
verifyFalse(tc, nf.links(3).B == 0);
tc.verifyTrue( all(nf.links(3).Tc == 0) );
mdl_puma560;
nf = p560.nofriction('all');
tc.verifyTrue( nf.links(3).B == 0);
tc.verifyTrue( all(nf.links(3).Tc == 0) );
end
function jtraj_test(tc)
mdl_puma560
qz = [0 0 0 0 0 0];
qr = [0 pi/2 -pi/2 0 0 0];
T1 = p560.fkine(qz);
T2 = p560.fkine(qr);
qt = p560.jtraj(T1, T2, 50, 'r');
tc.verifyEqual( size(qt), [50 6]);
%tc.verifyEqual(qt(1,:), qz, 'abstol', 1e-10);
%tc.verifyEqual(qt(end,:), qr, 'abstol', 1e-10);
end
function edit_test(tc)
robot = SerialLink(tc.TestData.p560);
robot.edit()
table = findobj('Type', 'uitable');
table.Data(1,2) = 7;
button = findobj('String', 'Save')
f = button.Callback{1};
f(button, [], table);
tc.verifyEqual(robot.links(1).d, 7);
close(gcf)
robot.edit('dyn')
table = findobj('Type', 'uitable');
table.Data(1,9) = 7;
button = findobj('String', 'Save')
f = button.Callback{1};
f(button, [], table);
tc.verifyEqual(robot.links(1).m, 7);
close(gcf)
end
function ellipse_test(tc)
tc.TestData.p560.plot( tc.TestData.p560.qn );
tc.TestData.p560.fellipse( tc.TestData.p560.qn );
tc.TestData.p560.fellipse( tc.TestData.p560.qn, 'trans' );
tc.TestData.p560.fellipse( tc.TestData.p560.qn, 'rot' );
clf
tc.TestData.p560.fellipse( tc.TestData.p560.qn, '2d' );
close(gcf)
tc.TestData.p560.plot( tc.TestData.p560.qn );
tc.TestData.p560.vellipse( tc.TestData.p560.qn );
tc.TestData.p560.vellipse( tc.TestData.p560.qn, 'trans' );
tc.TestData.p560.vellipse( tc.TestData.p560.qn, 'rot' );
clf
tc.TestData.p560.fellipse( tc.TestData.p560.qn, '2d' );
close(gcf)
end
function dh_mdh_test(tc)
tc.verifyTrue(tc.TestData.p560.isdh)
tc.verifyFalse(tc.TestData.p560.ismdh)
tc.verifyClass(tc.TestData.p560.isdh, 'logical')
tc.verifyClass(tc.TestData.p560.ismdh, 'logical')
tc.verifyFalse(tc.TestData.p560m.isdh)
tc.verifyTrue(tc.TestData.p560m.ismdh)
p560m = tc.TestData.p560.MDH;
tc.verifyTrue(isa(p560m, 'SerialLink'));
tc.verifyEqual(p560m.n, 6);
tc.verifyTrue(p560m.ismdh);
p560 = tc.TestData.p560m.DH;
tc.verifyTrue(isa(p560, 'SerialLink'));
tc.verifyEqual(p560.n, 6);
tc.verifyTrue(p560.isdh);
p560m = tc.TestData.p560.MDH;
p560 = p560m.DH; % should be the same robot
T1 = tc.TestData.p560.fkine(tc.TestData.p560.qn);
T2 = p560.fkine(tc.TestData.p560.qn);
tc.verifyEqual(T1, T2);
end
function twists_test(tc)
[tw,T0] = tc.TestData.p560.twists(tc.TestData.p560.qz);
tc.verifyClass(tw, 'Twist');
tc.verifyLength(tw, 6);
tc.verifyClass(T0, 'SE3');
tc.verifyLength(T0, 1);
tc.verifyEqual( double(prod( [tw.exp(tc.TestData.p560.qn) T0] )), ...
double(tc.TestData.p560.fkine(tc.TestData.p560.qn)), ...
'absTol', 1e-6);
end
function predicates_test(tc)
% isdh
x = tc.TestData.p560.isdh
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
x = tc.TestData.p560m.isdh
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyFalse(x);
% ismdh
x = tc.TestData.p560.ismdh
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyFalse(x);
x = tc.TestData.p560m.ismdh
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
% isspherical
x = tc.TestData.p560.isspherical
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
x = tc.TestData.p560.isspherical
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
% isprismatic
x = tc.TestData.stanf.isprismatic
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 6); tc.verifyEqual(x, logical([0 0 1 0 0 0]));
% isrevolute
x = tc.TestData.stanf.isrevolute
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 6); tc.verifyEqual(x, ~logical([0 0 1 0 0 0]));
% issym
x = tc.TestData.p560.issym
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyFalse(x);
mdl_twolink_sym;
x = twolink.issym
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
% isconfig
x = tc.TestData.p560.isconfig('RRRRRR');
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
x = tc.TestData.p560.isconfig('RRPRRR');
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyFalse(x);
x = tc.TestData.stanf.isconfig('RRRRRR');
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyFalse(x);
x = tc.TestData.stanf.isconfig('RRPRRR');
tc.verifyClass(x, 'logical'); tc.verifyLength(x, 1); tc.verifyTrue(x);
% islimit
x = tc.TestData.p560.islimit([0 0 0 0 0 0]);
tc.verifyClass(x, 'double'); tc.verifySize(x, [6 2]);
tc.verifyEqual(x, zeros(6,2));
x = tc.TestData.p560.islimit([0 10 0 0 0 0]);
tc.verifyClass(x, 'double'); tc.verifySize(x, [6 2]);
tc.verifyEqual(x, [0 1 0 0 0 0]'*[1 1]);
end
function test_get(tc)
x = tc.TestData.p560.d;
tc.verifyClass(x, 'double'); tc.verifyLength(x, 6);
tc.verifyEqual(x, [0 0 0.15005 0.4318 0 0], 'absTol', 1e-6);
x = tc.TestData.p560.a;
tc.verifyClass(x, 'double'); tc.verifyLength(x, 6);
tc.verifyEqual(x, [0 0.4318 0.0203 0 0 0], 'absTol', 1e-6);
x = tc.TestData.p560.alpha;
tc.verifyClass(x, 'double'); tc.verifyLength(x, 6);
tc.verifyEqual(x, [1 0 -1 1 -1 0]*pi/2, 'absTol', 1e-6);
x = tc.TestData.p560.theta;
tc.verifyClass(x, 'double'); tc.verifyLength(x, 0);
end
function mat2str_test(tc)
mdl_twolink_sym;
twolink
end
function rad_deg_test(tc)
q = [1 2 3 4 5 6];
q2 = tc.TestData.p560.todegrees(q);
tc.verifyEqual(q*180/pi, q2);
q2 = tc.TestData.p560.toradians(q);
tc.verifyEqual(q*pi/180, q2);
q2 = tc.TestData.stanf.todegrees(q);
qq = q*180/pi;
qq(3) = q(3);
tc.verifyEqual(qq, q2);
q2 = tc.TestData.stanf.toradians(q);
qq = q*pi/180;
qq(3) = q(3);
tc.verifyEqual(qq, q2);
end
function trchain_test(tc)
% TODO need to test return values here
s = tc.TestData.p560.trchain();
tc.verifyClass(s, 'char');
s = tc.TestData.p560m.trchain();
tc.verifyClass(s, 'char');
end
function jointdynamics_test(tc)
jd = tc.TestData.p560.jointdynamics( zeros(1,6), zeros(1,6));
tc.verifySize(jd, [1 6]);
tc.verifyClass(jd, 'tf');
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
SerialLinkModelsTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/SerialLinkModelsTest.m
| 1,696 |
utf_8
|
fa5bede9b9eb3d60c3e67db66c9fd7ff
|
%% This is for testing the SerialLink models in the robotics Toolboxg
function tests = SerialLinkModelsTest
tests = functiontests(localfunctions);
end
function models_test(tc)
models
names = models();
verifyTrue(tc, iscell(names) );
models('6dof')
names = models('6dof');
verifyTrue(tc, iscell(names) );
end
function all_models_test(tc)
all = models();
for model = all'
try
eval( [model{1} ';'] );
catch
verifyFail(tc, sprintf('model %s failed to load', model{1}) );
end
% find all the SerialLink objects
vars = whos;
k = find( cellfun(@(s) strcmp(s,'SerialLink'), {vars.class}) );
if isempty(k)
verifyFail(tc, sprintf('no SerialLink models loaded by %s', model{1}) );
end
for kk = k
clear(vars(kk).name)
end
% if exist('qz', 'var') ~= 1
% verifyFail(tc, sprintf('model %s doesn''t set qz', model{1}));
% end
clear qz
end
end
function query_test(tc)
names = models('6dof');
for model = names'
% attempt to load the model
try
eval( [model{1} ';'] );
catch
verifyFail(tc, 'model %s failed', model{1});
end
% find the number of DOF in the model
vars = whos;
k = find( cellfun(@(s) strcmp(s,'SerialLink'), {vars.class}) );
if ~isempty(k)
if eval( [vars(k).name '.n'] ) ~= 6
verifyFail(tc, 'query failed');
end
end
clear(vars(k).name)
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
PlanTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/PlanTest.m
| 8,305 |
utf_8
|
5be43c22100201e1aff4290dc8814bd2
|
function tests = PlanTest
tests = functiontests(localfunctions);
end
function setupOnce(tc)
clc
load map1 % load map
tc.TestData.map = map;
tc.TestData.goal = [50 30];
tc.TestData.start = [20 10];
end
function teardownOnce(tc)
close all
end
function bug2_test(tc)
nav = Bug2(tc.TestData.map);
tc.verifyInstanceOf(nav, 'Bug2');
s = nav.char();
verifyTrue(tc, ischar(s) );
nav.plot();
p = nav.query(tc.TestData.start, tc.TestData.goal);
tc.verifyTrue(size(p,2) == 2, 'plan must have 2 columns');
tc.verifyEqual(p(1,:), tc.TestData.start, 'start point must be on path');
tc.verifyEqual(p(end,:), tc.TestData.goal, 'goal point must be on path');
tc.verifyFalse( any( nav.isoccupied(p') ), 'path must have no occupied cells');
nav.plot()
nav.plot(p);
tc.assumeTrue(ispc || ismac); % FILTER video generation for Travis
fname = fullfile(tempdir, 'bug.mp4');
p = nav.query(tc.TestData.start, tc.TestData.goal, 'animate', 'movie', fname);
tc.verifyTrue(exist(fname, 'file') == 2);
delete(fname);
tc.verifyError( @() nav.plan(), 'RTB:Bug2:badcall');
map = zeros(10,10);
map(3:7,3:7) = 1;
map(4:6,4:6) = 0;
nav = Bug2(map);
tc.verifyError( @() nav.query([5 5], [2 2]), 'RTB:bug2:noplan');
end
function dxform_test(tc)
nav = DXform(tc.TestData.map);
tc.verifyInstanceOf(nav, 'DXform');
s = nav.char();
verifyTrue(tc, ischar(s) );
nav.plot();
nav.plan(tc.TestData.goal);
nav.plot();
nav.plan(tc.TestData.goal, 'animate');
p = nav.query(tc.TestData.start);
tc.verifyTrue(size(p,2) == 2, 'plan must have 2 columns');
tc.verifyEqual(p(1,:), tc.TestData.start, 'start point must be on path');
tc.verifyEqual(p(end,:), tc.TestData.goal, 'goal point must be on path');
tc.verifyFalse( any( nav.isoccupied(p') ), 'path must have no occupied cells');
nav.query(tc.TestData.start, 'animate');
nav.plot();
nav.plot(p);
nav.plot3d();
nav.plot3d(p);
end
function distancexform_test(tc)
map = zeros(10,10);
map(4:6,4:6) =1;
%args= {'verbose'}
args = {};
dx1 = distancexform(map, [5 8], 'fast', 'noipt', args{:});
tc.verifyClass(dx1, 'double');
tc.verifyEqual(dx1(8,5), 0);
tc.verifyTrue(all(all(isnan(dx1(map==1)))));
i=sub2ind(size(dx1), 8, 5);
tc.verifyTrue(all(dx1(i+[-11 -10 -9 -1 1 11 10 9])) > 0);
tc.verifySize(dx1, size(map));
dx2 = distancexform(map, [5 8], 'nofast', 'ipt', args{:});
tc.verifyClass(dx1, 'double');
tc.verifySize(dx1, size(map));
dx3 = distancexform(map, [5 8], 'nofast', 'noipt', args{:});
tc.verifyClass(dx1, 'double');
tc.verifySize(dx1, size(map));
tc.verifyEqual(dx1, dx2, 'absTol', 1e-6, 'MEX ~= bwdist');
tc.verifyEqual(dx1, dx3, 'MEX ~= MATLAB');
dx1 = distancexform(map, [5 8], 'cityblock', 'fast', 'noipt', args{:});
tc.verifyClass(dx1, 'double');
tc.verifyTrue(all(all(isnan(dx1(map==1)))));
i=sub2ind(size(dx1), 8, 5);
tc.verifyTrue(all(dx1(i+[-11 -10 -9 -1 1 11 10 9])) > 0);
tc.verifySize(dx1, size(map));
dx2 = distancexform(map, [5 8], 'cityblock', 'nofast', 'ipt', args{:});
tc.verifyClass(dx1, 'double');
tc.verifySize(dx1, size(map));
dx3 = distancexform(map, [5 8], 'cityblock', 'nofast', 'noipt', args{:});
tc.verifyClass(dx1, 'double');
tc.verifySize(dx1, size(map));
tc.verifyEqual(dx1, dx2, 'absTol', 1e-6, 'MEX ~= bwdist');
tc.verifyEqual(dx1, dx3, 'MEX ~= MATLAB');
dx1 = distancexform(map, [5 8], 'cityblock', 'animate');
dx1 = distancexform(map, [5 8], 'cityblock', 'animate', 'delay', 0.1);
tc.assumeTrue(ispc || ismac); % FILTER video generation for Travis
fname = fullfile(tempdir, 'bug.mp4');
dx1 = distancexform(map, [5 8], 'cityblock', 'animate', 'movie', fname);
tc.verifyTrue(exist(fname, 'file') == 2);
delete(fname)
end
function dstar_test(tc)
% create a planner
nav = Dstar(tc.TestData.map, 'quiet');
tc.verifyInstanceOf(nav, 'Dstar');
s = nav.char();
verifyTrue(tc, ischar(s) );
nav.plot();
% plan path to goal
nav.plan(tc.TestData.goal);
nav.plan(tc.TestData.goal, 'animate');
% execute it
p = nav.query(tc.TestData.start);
tc.verifyTrue(size(p,2) == 2, 'plan must have 2 columns');
tc.verifyEqual(p(1,:), tc.TestData.start, 'start point must be on path');
tc.verifyEqual(p(end,:), tc.TestData.goal, 'goal point must be on path');
tc.verifyFalse( any( nav.isoccupied(p') ), 'path must have no occupied cells');
nav.query(tc.TestData.start, 'animate');
nav.plot();
nav.plot(p);
% add a swamp
for r=78:85
for c=12:45
nav.modify_cost([c;r], 2);
end
end
% replan
nav.plan();
% show new path
nav.query(tc.TestData.start);
p = nav.query(tc.TestData.start);
tc.verifyTrue(size(p,2) == 2, 'plan must have 2 columns');
tc.verifyEqual(p(1,:), tc.TestData.start, 'start point must be on path');
tc.verifyEqual(p(end,:), tc.TestData.goal, 'goal point must be on path');
tc.verifyFalse( any( nav.isoccupied(p') ), 'path must have no occupied cells');
nav.plot(p);
nav.modify_cost([12 45; 78 85], 2);
nav.modify_cost([12 13 14; 78 79 80], [2 3 4]);
end
function prm_test(tc)
randinit
nav = PRM(tc.TestData.map);
tc.verifyInstanceOf(nav, 'PRM');
s = nav.char();
verifyTrue(tc, ischar(s) );
nav.plot();
nav.plan();
nav.plot();
p = nav.query(tc.TestData.start, tc.TestData.goal);
tc.verifyTrue(size(p,2) == 2, 'plan must have 2 columns');
tc.verifyEqual(p(1,:), tc.TestData.start, 'start point must be on path');
tc.verifyEqual(p(end,:), tc.TestData.goal, 'goal point must be on path');
tc.verifyFalse( any( nav.isoccupied(p') ), 'path must have no occupied cells');
nav.query(tc.TestData.start, tc.TestData.goal);
nav.plot(p);
end
function lattice_test(tc)
nav = Lattice();
tc.verifyInstanceOf(nav, 'Lattice');
nav.plan('iterations', 8);
nav.plot()
start = [1 2 pi/2]; goal = [2 -2 0];
p = nav.query( start, goal );
verifyEqual(tc, size(p,1), 7);
tc.verifyTrue(size(p,2) == 3, 'plan must have 3 columns');
tc.verifyEqual(p(1,:), start, 'AbsTol', 1e-10, 'start point must be on path');
tc.verifyEqual(p(end,:), goal, 'AbsTol', 1e-10, 'goal point must be on path');
nav.plot
nav.plan('cost', [1 10 10])
p = nav.query( start, goal );
verifyEqual(tc, size(p,1), 9);
tc.verifyTrue(size(p,2) == 3, 'plan must have 3 columns');
tc.verifyEqual(p(1,:), start, 'AbsTol', 1e-10, 'start point must be on path');
tc.verifyEqual(p(end,:), goal, 'AbsTol', 1e-10, 'goal point must be on path');
load road
nav = Lattice(road, 'grid', 5, 'root', [50 50 0])
nav.plan();
start = [30 45 0]; goal = [50 20 0];
p = nav.query(start, goal);
tc.verifyTrue(size(p,2) == 3, 'plan must have 3 columns');
tc.verifyEqual(p(1,:), start, 'AbsTol', 1e-10, 'start point must be on path');
tc.verifyEqual(p(end,:), goal, 'AbsTol', 1e-10, 'goal point must be on path');
tc.verifyFalse( any( nav.isoccupied(p(:,1:2)') ), 'path must have no occupied cells');
end
function rrt_test(tc)
randinit
car = Bicycle('steermax', 0.5);
%nav = RRT(car, 'goal', goal, 'range', 5);
nav = RRT(car, 'npoints', 400);
tc.verifyInstanceOf(nav, 'RRT');
s = nav.char();
nav.plan();
nav.plot();
start = [0 0 0]; goal = [0 2 0];
p = nav.query(start, goal);
tc.verifyTrue(size(p,2) == 3, 'plan must have 3 columns');
tc.verifyFalse( any( nav.isoccupied(p(:,1:2)') ), 'path must have no occupied cells');
% bigger example with obstacle
load road
randinit
nav = RRT(car, road, 'npoints', 1000, 'root', [50 22 0], 'simtime', 4);
nav.plan();
p = nav.query([40 45 0], [50 22 0]);
tc.verifyTrue(size(p,2) == 3, 'plan must have 3 columns');
tc.verifyFalse( any( nav.isoccupied(p(:,1:2)') ), 'path must have no occupied cells');
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
TrajectoryTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/TrajectoryTest.m
| 18,301 |
utf_8
|
14958af0af35aba994d574bf2bf54caa
|
%% This is for testing the Trajectory Generation functions in the robotics Toolbox
function tests = TrajectoryTest
tests = functiontests(localfunctions);
clc
end
function teardownOnce(tc)
close all
end
function tpoly_test(tc)
s1 = 1;
s2 = 2;
%% no boundary conditions
tpoly(s1, s2, 11);
s = tpoly(s1, s2, 11);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
[s,sd] = tpoly(s1, s2, 11);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(s >= 0)); % velocity is >= 0
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
[s,sd,sdd] = tpoly(s1, s2, 11);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(sd >= -10*eps)); % velocity is >= 0
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
tc.verifyEqual(sdd(1), 0, 'absTol',1e-10); % acceleration
tc.verifyEqual(sdd(6), 0, 'absTol',1e-10);
tc.verifyEqual(sdd(end), 0, 'absTol',1e-10);
tc.verifyEqual(sum(sdd), 0, 'absTol',1e-10);
%% time vector version
t = linspace(0, 1, 11);
tpoly(s1, s2, t);
s = tpoly(s1, s2, t);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
[s,sd] = tpoly(s1, s2, t);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(s >= 0)); % velocity is >= 0
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
[s,sd,sdd] = tpoly(s1, s2, t);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(sd >= 0)); % velocity is >= 0
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
tc.verifyEqual(sdd(1), 0, 'absTol',1e-10); % acceleration
tc.verifyEqual(sdd(6), 0, 'absTol',1e-10);
tc.verifyEqual(sdd(end), 0, 'absTol',1e-10);
tc.verifyEqual(sum(sdd), 0, 'absTol',1e-10);
%% boundary conditions
[s,sd,sdd] = tpoly(s1, s2, 11, -1, 1);
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyEqual(sd(1), -1, 'absTol',1e-10);
tc.verifyEqual(sd(end), 1, 'absTol',1e-10);
tc.verifyEqual(sdd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sdd(end), 0, 'absTol',1e-10);
%% plot version
tpoly(s1, s2, 11, -1, 1);
end
function lspb_test(tc)
s1 = 1;
s2 = 2;
%% no boundary conditions
lspb(s1, s2, 11);
s = lspb(s1, s2, 11);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
[s,sd] = lspb(s1, s2, 11);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(s >= 0)); % velocity is >= 0
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
[s,sd,sdd] = lspb(s1, s2, 11);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(sd >= 0)); % velocity is >= 0
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
tc.verifyEqual(sum(sdd), 0, 'absTol',1e-10);
%% time vector version
t = linspace(0, 1, 11);
lspb(s1, s2, t);
s = lspb(s1, s2, t);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
[s,sd] = lspb(s1, s2, t);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(s >= 0)); % velocity is >= 0
tc.verifyEqual(s(6), 1.5, 'absTol',1e-10);
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
[s,sd,sdd] = lspb(s1, s2, t);
tc.verifyTrue(all(diff(s) > 0)); % output is monotonic
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyTrue(all(sd >= 0)); % velocity is >= 0
tc.verifyEqual(sd(1), 0, 'absTol',1e-10);
tc.verifyEqual(sd(end), 0, 'absTol',1e-10);
tc.verifyEqual(sum(sdd), 0, 'absTol',1e-10);
%% specify velocity
[s,sd,sdd] = lspb(s1, s2, 11,0.2);
tc.verifyEqual(s(1), s1, 'absTol',1e-10);
tc.verifyEqual(s(end), s2, 'absTol',1e-10);
tc.verifyEqual(sd(6), 0.2, 'absTol',1e-10);
%% plot version
lspb(s1, s2, 11);
end
% ctraj - Cartesian trajectory
function ctraj_test(tc)
% unit testing ctraj with T0 and T1 and N
T0 = transl(1,2,3);
T1 = transl(-1,-2,-3)*trotx(pi);
T = ctraj(T0, T1, 3);
tc.verifyEqual(size(T,3), 3);
tc.verifyEqual(T(:,:,1), T0, 'abstol', 1e-10);
tc.verifyEqual(T(:,:,2), trotx(pi/2), 'abstol', 1e-10);
tc.verifyEqual(T(:,:,3), T1, 'abstol', 1e-10);
% unit testing ctraj with T0 and T1 and S(i)
T = ctraj(T0, T1, [1 0 0.5]);
tc.verifyEqual(size(T,3), 3);
tc.verifyEqual(T(:,:,1), T1, 'abstol', 1e-10);
tc.verifyEqual(T(:,:,3), trotx(pi/2), 'abstol', 1e-10);
tc.verifyEqual(T(:,:,2), T0, 'abstol', 1e-10);
end
% jtraj - joint space trajectory
function jtraj_test(tc)
% unit testing jtraj with
q1 = [1 2 3 4 5 6];
q2 = -q1;
q = jtraj(q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
[q,qd] = jtraj(q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
[q,qd,qdd] = jtraj(q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(qdd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(end,:), zeros(1,6), 'abstol', 1e-10);
%% with a time vector
t = linspace(0, 1, 11);
q = jtraj(q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
[q,qd] = jtraj(q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
[q,qd,qdd] = jtraj(q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(qdd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(end,:), zeros(1,6), 'abstol', 1e-10);
%% test with boundary conditions
qone = ones(1,6);
[q,qd,qdd] = jtraj(q1,q2,11, -qone, qone);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), -qone, 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), qone, 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(qdd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(end,:), zeros(1,6), 'abstol', 1e-10);
end
% mtraj - multi-axis trajectory for arbitrary function
function mtraj_tpoly_test(tc)
q1 = [1 2 3 4 5 6];
q2 = -q1;
q = mtraj(@tpoly, q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
[q,qd] = mtraj(@tpoly, q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
[q,qd,qdd] = mtraj(@tpoly, q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(qdd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(end,:), zeros(1,6), 'abstol', 1e-10);
%% with a time vector
t = linspace(0, 1, 11);
q = mtraj(@tpoly, q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
[q,qd] = mtraj(@tpoly, q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
[q,qd,qdd] = mtraj(@tpoly, q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(qdd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qdd(end,:), zeros(1,6), 'abstol', 1e-10);
end
function mtraj_lspb_test(tc)
q1 = [1 2 3 4 5 6];
q2 = -q1;
q = mtraj(@lspb, q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
[q,qd] = mtraj(@lspb, q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
[q,qd,qdd] = mtraj(@lspb, q1,q2,11);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(sum(qdd), zeros(1,6), 'abstol', 1e-10);
%% with a time vector
t = linspace(0, 1, 11);
q = mtraj(@lspb, q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
[q,qd] = mtraj(@lspb, q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
[q,qd,qdd] = mtraj(@lspb, q1,q2,t);
tc.verifyEqual(size(q,1), 11);
tc.verifyEqual(size(q,2), 6);
tc.verifyEqual(q(1,:), q1, 'abstol', 1e-10);
tc.verifyEqual(q(end,:), q2, 'abstol', 1e-10);
tc.verifyEqual(q(6,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qd,1), 11);
tc.verifyEqual(size(qd,2), 6);
tc.verifyEqual(qd(1,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(qd(end,:), zeros(1,6), 'abstol', 1e-10);
tc.verifyEqual(size(qdd,1), 11);
tc.verifyEqual(size(qdd,2), 6);
tc.verifyEqual(sum(qdd), zeros(1,6), 'abstol', 1e-10);
end
% mstraj - multi-axis multi-segment trajectory
function mstraj_test(tc)
via = [4 1; 4 4; 5 2; 2 5];
%Test with QDMAX
out = mstraj(via, [ 2 1 ],[],[4 1],1,1);
expected_out = [4.0000 1.0000
4.0000 1.7500
4.0000 2.5000
4.0000 3.2500
4.3333 3.3333
4.6667 2.6667
4.2500 2.7500
3.5000 3.5000
2.7500 4.2500
2.0000 5.0000];
verifyEqual(tc, out,expected_out ,'absTol',1e-4);
% test plotting
mstraj(via, [ 2 1 ],[],[4 1],1,1);
%Test with QO
out = mstraj(via, [],[2 1 3 4],[4 1],1,1);
expected_out = [4.0000 1.0000
4.0000 4.0000
4.3333 3.3333
4.6667 2.6667
4.2500 2.7500
3.5000 3.5000
2.7500 4.2500
2.0000 5.0000];
verifyEqual(tc, out,expected_out ,'absTol',1e-4);
%Test with QO
out = mstraj(via, [],[1 2 3 4],via(1,:),1,1);
expected_out = [4.0000 1.0000
4.0000 2.5000
4.3333 3.3333
4.6667 2.6667
4.2500 2.7500
3.5000 3.5000
2.7500 4.2500
2.0000 5.0000];
verifyEqual(tc, out,expected_out ,'absTol',1e-4);
[out,t] = mstraj(via, [],[1 2 3 4],via(1,:),1,1);
verifyEqual(tc, size(t,1), size(out,1));
verifyEqual(tc, size(t,2), 1);
[out,t,info] = mstraj(via, [],[1 2 3 4],via(1,:),1,1);
verifyEqual(tc, size(t,1), size(out,1));
verifyEqual(tc, size(t,2), 1);
verifyEqual(tc, length(info), size(via,1)+1);
verifyTrue(tc, isa(info, 'struct'));
end
% qplot - plot joint angle trajectories
function qplot_test(tc)
s = linspace(0, 1, 100)';
qz = [0 0 0 0 0 0]; qr = [1 2 3 4 5 6];
q = (1-s)*qz + s*qr;
clf
qplot(s*20,q);
qplot(q);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
NavigationTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/NavigationTest.m
| 2,674 |
utf_8
|
fa1ee2e963da90466512c91e59044f9e
|
% test the Navigation abstract superclass
function tests = NavigationTest
tests = functiontests(localfunctions);
end
function map_test(tc)
map = zeros(10,10);
map(2,3) = 1;
nav = Bug2(map); % we can't instantiate Navigation because it's abstract
%% test isoccupied method
% row vector
tc.verifyTrue( nav.isoccupied([3,2]) );
tc.verifyFalse( nav.isoccupied([3,3]) );
% column vector
tc.verifyTrue( nav.isoccupied([3,2]') );
tc.verifyFalse( nav.isoccupied([3,3]') );
% separate args
tc.verifyTrue( nav.isoccupied(3,2) );
tc.verifyFalse( nav.isoccupied(3,3) );
% out of bound
tc.verifyTrue( nav.isoccupied([20 20]) );
% multiple points
tc.verifyEqual( nav.isoccupied([3 2; 20 20; 3 3]'), [true true false] );
tc.verifyEqual( nav.isoccupied([3 20 3], [2 20 3]), [true true false] );
tc.verifyEqual( nav.isoccupied([3 20 3]', [2 20 3]), [true true false] );
tc.verifyEqual( nav.isoccupied([3 20 3], [2 20 3]'), [true true false] );
tc.verifyEqual( nav.isoccupied([3 20 3]', [2 20 3]'), [true true false] );
%% test inflation option
nav = Bug2(map, 'inflate', 1);
tc.verifyTrue( nav.isoccupied([3,2]) );
tc.verifyTrue( nav.isoccupied([3,3]) );
tc.verifyFalse( nav.isoccupied([3,4]) );
end
function maptype_test(tc)
%% logical map
map = zeros(10,10, 'logical');
map(2,3) = true;
nav = Bug2(map); % we can't instantiate Navigation because it's abstract
tc.verifyTrue( nav.isoccupied([3,2]) );
tc.verifyFalse( nav.isoccupied([3,3]) );
%% uint8 map
map = zeros(10,10, 'uint8');
map(2,3) = 1;
nav = Bug2(map); % we can't instantiate Navigation because it's abstract
tc.verifyTrue( nav.isoccupied([3,2]) );
tc.verifyFalse( nav.isoccupied([3,3]) );
end
function rand_test(tc)
nav = Bug2(); % we can't instantiate Navigation because it's abstract
%% test random number generator
r = nav.randn;
tc.verifySize(r, [1 1]);
tc.verifyInstanceOf(r, 'double');
r = nav.randn(2,2);
tc.verifySize(r, [2 2]);
end
function randi_test(tc)
nav = Bug2(); % we can't instantiate Navigation because it's abstract
%% test integer random number generator
r = nav.randi(10);
tc.verifySize(r, [1 1]);
tc.verifyEqual(r, floor(r)); % is it an integer value
tc.verifyInstanceOf(r, 'double');
r = nav.randi(10, 2,2);
tc.verifySize(r, [2 2]);
tc.verifyEqual(r, floor(r));
% check range
r = nav.randi(10, 100,1);
tc.verifyTrue(min(r) >= 1);
tc.verifyTrue(max(r) <= 10);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
LinkTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/LinkTest.m
| 21,983 |
utf_8
|
cebe5d2fc8d7db771204d971accbdde7
|
%% This is for testing the Link functions in the robotics Toolbox
function tests = LinkTest
tests = functiontests(localfunctions);
end
function constructor_classic_dh_test(tc)
L = Link();
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 0);
tc.verifyEqual(L.d, 0);
tc.verifyEqual(L.a, 0);
tc.verifyEqual(L.alpha, 0);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'R');
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
L = Link([1 2 3 4]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'R');
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
L = Link([1 2 3 4 1]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
L = Link([1 2 3 4 1 5]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 5);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
L = Link([1 2 3 4 1 5], 'standard');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 5);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
verifyError(tc, @() Link(1), 'RTB:Link:badarg');
verifyError(tc, @() Link([1 2 3]), 'RTB:Link:badarg');
% dynamics standard revolute
L = Link([1 2 3 4 0 6:19 -20]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'R');
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
tc.verifyEqual(L.m, 6);
tc.verifyEqual(L.r, [7:9]);
tc.verifyEqual(diag(L.I)', [10:12]);
tc.verifyEqual(diag(L.I,1)', [13:14]);
tc.verifyEqual(diag(L.I,2), 15);
tc.verifyEqual(L.Jm, 16);
tc.verifyEqual(L.G, 17);
tc.verifyEqual(L.B, 18);
tc.verifyEqual(L.Tc, [19 -20]);
% dynamics standard prismatic
L = Link([1 2 3 4 1 6:19 -20]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
tc.verifyEqual(L.m, 6);
tc.verifyEqual(L.r, [7:9]);
tc.verifyEqual(diag(L.I)', [10:12]);
tc.verifyEqual(diag(L.I,1)', [13:14]);
tc.verifyEqual(diag(L.I,2), 15);
tc.verifyEqual(L.Jm, 16);
tc.verifyEqual(L.G, 17);
tc.verifyEqual(L.B, 18);
tc.verifyEqual(L.Tc, [19 -20]);
end
function constructor_classic_mdh_test(tc)
% L = Link('modified');
% tc.verifyTrue( isa(L, 'Link') );
% tc.verifyEqual(L.theta, 0);
% tc.verifyEqual(L.d, 0);
% tc.verifyEqual(L.a, 0);
% tc.verifyEqual(L.alpha, 0);
% tc.verifyEqual(L.offset, 0);
% tc.verifyEqual(L.type, 'R');
% tc.verifyTrue(isrevolute(L));
% tc.verifyFalse(isprismatic(L));
% tc.verifyEqual(L.mdh, 1);
L = Link([1 2 3 4], 'modified');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'R');
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
L = Link([1 2 3 4 1], 'modified');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
L = Link([1 2 3 4 1 5], 'modified');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.d, 2);
tc.verifyEqual(L.a, 3);
tc.verifyEqual(L.alpha, 4);
tc.verifyEqual(L.offset, 5);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
end
function constructor_test(tc)
% standard revolute
L = Link('d', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
% standard revolute
L = Link('d', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31], 'revolute', 'standard');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
% standard prismatic
L = Link('theta', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31], 'prismatic');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
% modified revolute
L = Link('d', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31], 'modified');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
% modified prismatic
L = Link('theta', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31], 'modified', 'prismatic');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
verifyError(tc, @() Link('theta', 1, 'd', 2), 'RTB:Link:badarg');
% symbolic
L = Link('d', 1, 'a', 2, 'alpha', 3, 'sym');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyTrue(L.issym);
tc.verifyTrue(isa(L.d, 'sym'));
tc.verifyTrue(eval(L.d == 1));
tc.verifyTrue(isa(L.a, 'sym'));
tc.verifyTrue(eval(L.a == 2));
tc.verifyTrue(isa(L.alpha, 'sym'));
tc.verifyTrue(eval(L.alpha == 3));
L = Link('theta', 1, 'a', 2, 'alpha', 3, 'sym');
tc.verifyTrue( isa(L, 'Link') );
tc.verifyTrue(L.issym);
tc.verifyTrue(isa(L.theta, 'sym'));
tc.verifyTrue(eval(L.theta == 1));
tc.verifyTrue(isa(L.a, 'sym'));
tc.verifyTrue(eval(L.a == 2));
tc.verifyTrue(isa(L.alpha, 'sym'));
tc.verifyTrue(eval(L.alpha == 3));
end
%% test the convenience subclasses
function constructor_revolute_test(tc)
L = Revolute();
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 0);
tc.verifyEqual(L.a, 0);
tc.verifyEqual(L.alpha, 0);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'R');
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
L = Revolute('d', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
tc.verifyEqual(L.type, 'R');
end
function constructor_prismatic_test(tc)
L = Prismatic();
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 0);
tc.verifyEqual(L.a, 0);
tc.verifyEqual(L.alpha, 0);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
L = Prismatic('theta', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 0);
end
function constructor_revolute_mdh_test(tc)
L = RevoluteMDH();
tc.verifyTrue( isa(L, 'Link') );
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 0);
tc.verifyEqual(L.a, 0);
tc.verifyEqual(L.alpha, 0);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'R');
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
L = RevoluteMDH('d', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.d, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyTrue(isrevolute(L));
tc.verifyFalse(isprismatic(L));
tc.verifyEqual(L.type, 'R');
tc.verifyEqual(L.mdh, 1);
end
function constructor_prismatic_mdh_test(tc)
L = PrismaticMDH();
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 0);
tc.verifyEqual(L.a, 0);
tc.verifyEqual(L.alpha, 0);
tc.verifyEqual(L.offset, 0);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
L = PrismaticMDH('theta', 1, 'a', 2, 'alpha', 3, 'B', 4, 'm', 5, 'G', 6, 'Jm', 7, 'Tc', [8 -9], ...
'r', [10 11 12], 'I', [21:26], 'qlim', [30 31]);
tc.verifyTrue( isa(L, 'Link') );
tc.verifyFalse(L.issym);
tc.verifyEqual(L.theta, 1);
tc.verifyEqual(L.a, 2);
tc.verifyEqual(L.alpha, 3);
tc.verifyEqual(L.B, 4);
tc.verifyEqual(L.m, 5);
tc.verifyEqual(L.G, 6);
tc.verifyEqual(L.Jm, 7);
tc.verifyEqual(L.Tc, [8 -9]);
tc.verifyEqual(L.r, [10 11 12]);
tc.verifyEqual(diag(L.I)', [21:23]);
tc.verifyEqual(diag(L.I,1)', [24:25]);
tc.verifyEqual(diag(L.I,2), 26);
tc.verifyEqual(L.qlim, [30 31]);
tc.verifyEqual(L.type, 'P');
tc.verifyFalse(isrevolute(L));
tc.verifyTrue(isprismatic(L));
tc.verifyEqual(L.mdh, 1);
end
%% construct a robot link object
function Link_test(tc)
%create a 2 link arm with Link
L(1)=Link([1 1 1 1 1]);
s = L(1).char;
L(1).dyn;
L(2)=Link([0 1 0 1 0]);
s = L.char;
L.display;
% dyn display link dynamic parameters
L.dyn;
% Methods::
% A return link transform (A) matrix
%Transforms for link 1
verifyEqual(tc, L(1).A(0.5).T, ...
[0.5403 -0.4546 0.7081 0.5403
0.8415 0.2919 -0.4546 0.8415
0 0.8415 0.5403 0.5000
0 0 0 1.0000], ...
'absTol',1e-4);
verifyEqual(tc, L(1).A(0).T, ...
[0.5403 -0.4546 0.7081 0.5403
0.8415 0.2919 -0.4546 0.8415
0 0.8415 0.5403 0
0 0 0 1.0000], ...
'absTol',1e-4);
%Transforms for link 2
verifyEqual(tc, L(2).A(0.5).T, ...
[0.8776 -0.2590 0.4034 0
0.4794 0.4742 -0.7385 0
0 0.8415 0.5403 1.0000
0 0 0 1.0000], ...
'absTol',1e-4);
verifyEqual(tc, L(2).A(0).T, ...
[1.0000 0 0 0
0 0.5403 -0.8415 0
0 0.8415 0.5403 1.0000
0 0 0 1.0000], ...
'absTol',1e-4);
% RP return joint type: 'R' or 'P'
verifyEqual(tc, L.type, 'PR');
% islimit true if joint exceeds soft limit
L(2).qlim = [-1 1];
verifyEqual(tc, L(2).islimit(0), 0);
verifyEqual(tc, L(2).islimit(3), 1);
verifyEqual(tc, L(2).islimit(-2), -1);
% isrevolute true if joint is revolute
verifyFalse(tc, L(1).isrevolute);
verifyTrue(tc, L(2).isrevolute);
% isprismatic true if joint is prismatic
verifyFalse(tc, L(2).isprismatic);
verifyTrue(tc, L(1).isprismatic);
syms a1 m1 c1 Iyy1 b1;
L = Revolute('d', 0, 'a', a1, 'alpha', 0, 'm', m1, 'r', [c1 0 0], 'I', [0 Iyy1 0], 'B', b1, 'G', 1, 'Jm', 0, 'standard');
L
L.dyn
end
function deepcopy_test(tc)
% deep copy test
L = Link([1 2 3 4]);
L2 = Link(L);
verifyEqual(tc, L.a, 3);
verifyEqual(tc, L2.a, 3);
L.a = 10;
verifyEqual(tc, L.a, 10);
verifyEqual(tc, L2.a, 3);
end
function RP_test(tc)
L = Link();
tc.verifyEqual(L.RP, 'R');
tc.verifyWarning( @() L.RP, 'RTB:Link:deprecated');
end
function type_test(tc)
L = [ Revolute() Prismatic() Prismatic() Revolute()];
tc.verifyEqual(L.type, 'RPPR');
end
function set_test(tc)
L = Link([1 1 1 1 1]);
L.r = [1 2 3];
verifyEqual(tc, L.r, [1 2 3]);
L.r = [1 2 3]';
verifyEqual(tc, L.r, [1 2 3]);
L.I = [1, 2, 3];
verifyEqual(tc, L.I, diag([1,2,3]));
L.I = [1, 2, 3, 4, 5, 6];
verifyEqual(tc, L.I, [1 4 6; 4 2 5; 6 5 3]);
A = rand(3,3);
L.I = A'*A; % make a symm matrix
verifyEqual(tc, L.I, A'*A);
L.Tc = 1;
verifyEqual(tc, L.Tc, [1 -1]);
L.Tc = [1 -2];
verifyEqual(tc, L.Tc, [1 -2]);
% all these should all fail
function set_fail1
L = Link;
L.Tc = [-2 1]; % wrong order
end
function set_fail2
L = Link;
L.r = [ 1 2]'; % too short
end
function set_fail3
L = Link;
L.I = 1; % too short
end
function set_fail4
L = Link;
I = diag([1 2 3]);
I(1,2) = 1;
L.I = I; % not symmetric
end
verifyError(tc, @set_fail1, 'RTB:Link:badarg');
verifyError(tc, @set_fail2, 'RTB:Link:badarg');
verifyError(tc, @set_fail3, 'RTB:Link:badarg');
verifyError(tc, @set_fail4, 'RTB:Link:badarg');
end
function viscous_friction_test(tc)
L = Link();
B = 1; G = 2; Tc = 0;
% viscous model
L.G = G;
L.B = B;
L.Tc = Tc;
verifyEqual(tc, L.friction(1), -B*G^2);
verifyEqual(tc, L.friction(-1), B*G^2);
L.G = -G
verifyEqual(tc, L.friction(1), -B*G^2);
verifyEqual(tc, L.friction(-1), B*G^2);
end
function coulomb_friction_test(tc)
L = Link();
B = 0; G = 2; Tc = [2 -3];
% coulomb model
L.G = G
L.B = 0;
L.Tc = Tc;
verifyEqual(tc, L.friction(1), -Tc(1)*G);
verifyEqual(tc, L.friction(-1), -Tc(2)*G);
% check for negative gear ratio
L.G = -G
% coulomb model
L.B = 0;
L.Tc = Tc;
verifyEqual(tc, L.friction(1), -Tc(1)*G);
verifyEqual(tc, L.friction(-1), -Tc(2)*G);
L.Tc = []; % does nothing
verifyEqual(tc, L.friction(1), -Tc(1)*G);
verifyEqual(tc, L.friction(-1), -Tc(2)*G);
%tc.verifyError( @() L.Tc = [1 2 3], 'RTB:Link:badarg');
function wrapper()
L.Tc = [1 2 3]
end
tc.verifyError( @wrapper, 'RTB:Link:badarg');
end
% nofriction remove joint friction
function nofriction_test(tc)
L = Link();
B = 1; G = 2; Tc = [2 -3];
L.B = B;
L.G = G
L.Tc = Tc;
verifyFalse(tc, L.B == 0);
verifyFalse(tc, all(L.Tc == 0) );
Lnf = L.nofriction('all');
verifyTrue(tc, Lnf.B == 0);
verifyTrue(tc, all(Lnf.Tc == 0) );
% check original object unchanged
verifyFalse(tc, L.B == 0);
verifyFalse(tc, all(L.Tc == 0) );
Lnf = L.nofriction('viscous');
verifyTrue(tc, Lnf.B == 0);
verifyFalse(tc, all(Lnf.Tc == 0) );
Lnf = L.nofriction('coulomb');
verifyFalse(tc, Lnf.B == 0);
verifyTrue(tc, all(Lnf.Tc == 0) );
end
function flip_test(tc)
L = Link();
tc.verifyFalse(L.flip);
L = Link('flip');
tc.verifyTrue(L.flip);
end
function A_test(tc)
L = Link([1 2 3 pi/2]);
tc.verifyEqual(L.A(0).T, [1 0 0 3; 0 0 -1 0; 0 1 0 2; 0 0 0 1], 'AbsTol', 1e-10);
tc.verifyEqual(L.A({0}).T, [1 0 0 3; 0 0 -1 0; 0 1 0 2; 0 0 0 1], 'AbsTol', 1e-10);
A = [0 0 1 0; 1 0 0 3; 0 1 0 2; 0 0 0 1];
tc.verifyEqual(L.A(pi/2).T, A, 'AbsTol', 1e-10);
L.flip = true;
tc.verifyEqual(L.A(-pi/2).T, A, 'AbsTol', 1e-10);
end
function char_test(tc)
L = [ Revolute() Prismatic() Prismatic() Revolute()];
s = char(L);
tc.verifyTrue(ischar(s));
tc.verifyEqual(size(s,1), 4);
s = char(L, true);
tc.verifyTrue(ischar(s));
tc.verifyEqual(size(s,1), 4);
L = [ RevoluteMDH() PrismaticMDH() PrismaticMDH() RevoluteMDH()];
s = char(L);
tc.verifyTrue(ischar(s));
tc.verifyEqual(size(s,1), 4);
s = char(L, true);
tc.verifyTrue(ischar(s));
tc.verifyEqual(size(s,1), 4);
end
function plus_test(tc)
R = Revolute()+Prismatic()+Prismatic()+ Revolute();
tc.verifyTrue(isa(R, 'SerialLink'));
tc.verifyEqual(R.n, 4);
tc.verifyEqual(R.config, 'RPPR');
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
DifferentialMotionTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/DifferentialMotionTest.m
| 7,265 |
utf_8
|
8045b2810725df6247d2469193269d26
|
%% This is for testing the Differential Motion functions in the robotics Toolbox
function tests = TransformationsTest
tests = functiontests(localfunctions);
end
%% skew - vector to skew symmetric matrix
function skew_test(tc)
%% 2D case
verifyEqual(tc, skew(2),...
[0 -2; 2 0],'absTol',1e-4);
%% 3D case
% test row and column vectors
verifyEqual(tc, skew([1, 2, 3]'),...
[ 0 -3 2
3 0 -1
-2 1 0],'absTol',1e-4);
verifyEqual(tc, skew([1, 2, 3]),...
[ 0 -3 2
3 0 -1
-2 1 0],'absTol',1e-4);
end
%% vex - skew symmetric matrix to vector
function vex_test(tc)
%% 2D case
verifyEqual(tc, vex([0 -2; 2 0]), 2, 'absTol',1e-4);
%% 3D case
verifyEqual(tc, vex([0, -3, 2; 3, 0, -1; -2, 1, 0]),...
[1; 2; 3],'absTol',1e-4);
% unit testing vex with 3x3 skew matrix
verifyEqual(tc, vex([0 0 0;0 0 0;0 0 0]),...
[0; 0; 0],'absTol',1e-4);
verifyError(tc, @()vex(1),'SMTB:vex:badarg');
verifyError(tc, @()vex(zeros(4,4)),'SMTB:vex:badarg');
% ---------------------------------------------------------------------
% wtrans - transform wrench between frames
% does not exist!!! need to find this function
%----------------------------------------------------------------------
end
%% skewa - augmented vector to skew symmetric matrix
function skewa_test(tc)
%% 2D case
verifyEqual(tc, skewa([1 2 3]),...
[0 -3 1; 3 0 2; 0 0 0],'absTol',1e-4);
%% 3D case
% test row and column vectors
verifyEqual(tc, skewa([1, 2, 3, 4, 5, 6]'),...
[0 -6 5 1; 6 0 -4 2; -5 4 0 3; 0 0 0 0],'absTol',1e-4);
verifyEqual(tc, skewa([1, 2, 3, 4, 5, 6]),...
[0 -6 5 1; 6 0 -4 2; -5 4 0 3; 0 0 0 0],'absTol',1e-4);
verifyError(tc, @()skewa(1),'SMTB:skewa:badarg');
end
%% vexa - augmented skew symmetric matrix to vector
function vexa_test(tc)
%% 2D case
verifyEqual(tc, vexa([0 -3 1; 3 0 2; 0 0 0]), [1 2 3]', 'absTol',1e-4);
%% 3D case
verifyEqual(tc, vexa([0 -6 5 1; 6 0 -4 2; -5 4 0 3; 0 0 0 0]),...
[1 2 3 4 5 6]','absTol',1e-4);
verifyError(tc, @()vexa(1),'SMTB:vexa:badarg');
end
%% Differential motion
% delta2tr - differential motion vector to HT
function delta2tr_test(testCase)
%test with standard numbers
verifyEqual(testCase, delta2tr([0.1 0.2 0.3 0.4 0.5 0.6]),...
[1.0000 -0.6000 0.5000 0.1000
0.6000 1.0000 -0.4000 0.2000
-0.5000 0.4000 1.0000 0.3000
0 0 0 1.0000],'absTol',1e-4);
%test with zeros
verifyEqual(testCase, delta2tr([0 0 0 0 0 0]), eye(4,4),'absTol',1e-4);
%test with scaler input
verifyError(testCase, @()delta2tr(1),'MATLAB:badsubscript');
end
% eul2jac - Euler angles to Jacobian
function eul2jac_test(tc)
% check it works for simple cases
verifyEqual(tc, eul2jac(0, 0, 0), [0 0 0; 0 1 0; 1 0 1]);
verifyEqual(tc, eul2jac( [0, 0, 0]), [0 0 0; 0 1 0; 1 0 1]);
eul = [0.2 0.3 0.4];
% check complex case
verifyEqual(tc, eul2jac( eul(1), eul(2), eul(3)), eul2jac(eul));
%Testing with a scalar number input
verifyError(tc, @()eul2jac(1),'SMTB:eul2jac:badarg');
% test Jacobian against numerical approximation
dth = 1e-6;
R0 = eul2r(eul);
R1 = eul2r(eul + dth*[1 0 0]);
R2 = eul2r(eul + dth*[0 1 0]);
R3 = eul2r(eul + dth*[0 0 1]);
JJ = [ vex((R1-R0)*R0') vex((R2-R0)*R0') vex((R3-R0)*R0')] / dth;
verifyEqual(tc, JJ, eul2jac(eul), 'absTol',1e-4)
end
% rpy2jac - RPY angles to Jacobian
function rpy2jac_test(tc)
% check it works for simple cases
verifyEqual(tc, rpy2jac(0, 0, 0), eye(3,3));
verifyEqual(tc, rpy2jac( [0, 0, 0]), eye(3,3));
% check switches work
verifyEqual(tc, rpy2jac( [0, 0, 0], 'xyz'), [0 0 1; 0 1 0; 1 0 0]);
verifyEqual(tc, rpy2jac( [0, 0, 0], 'zyx'), eye(3,3));
verifyEqual(tc, rpy2jac( [0, 0, 0], 'yxz'), [0 1 0; 0 0 1; 1 0 0]);
rpy = [0.2 0.3 0.4];
% check default
verifyEqual(tc, rpy2jac(rpy), rpy2jac(rpy, 'zyx') );
% check complex case
verifyEqual(tc, rpy2jac( rpy(1), rpy(2), rpy(3)), rpy2jac(rpy));
%Testing with a scalar number input
verifyError(tc, @()rpy2jac(1),'SMTB:rpy2jac:badarg');
% test Jacobian against numerical approximation for 3 different orders
dth = 1e-6;
for oo = {'xyz', 'zyx', 'yxz'}
order = oo{1};
R0 = rpy2r(rpy, order);
R1 = rpy2r(rpy + dth*[1 0 0], order);
R2 = rpy2r(rpy + dth*[0 1 0], order);
R3 = rpy2r(rpy + dth*[0 0 1], order);
JJ = [ vex((R1-R0)*R0') vex((R2-R0)*R0') vex((R3-R0)*R0')] / dth;
verifyEqual(tc, JJ, rpy2jac(rpy, order), 'absTol',1e-4)
end
end
% tr2delta - HT to differential motion vector
function tr2delta_test(tc)
% unit testing tr2delta with a tr matrix
verifyEqual(tc, tr2delta( transl(0.1, 0.2, 0.3) ),...
[0.1000, 0.2000, 0.3000, 0, 0, 0]','absTol',1e-4);
verifyEqual(tc, tr2delta( transl(0.1, 0.2, 0.3), transl(0.2, 0.4, 0.6) ), ...
[0.1000, 0.2000, 0.3000, 0, 0, 0]','absTol',1e-4);
verifyEqual(tc, tr2delta( trotx(0.001) ), ...
[0,0,0, 0.001,0,0]','absTol',1e-4);
verifyEqual(tc, tr2delta( troty(0.001) ), ...
[0,0,0, 0,0.001,0]','absTol',1e-4);
verifyEqual(tc, tr2delta( trotz(0.001) ), ...
[0,0,0, 0,0,0.001]','absTol',1e-4);
verifyEqual(tc, tr2delta( trotx(0.001), trotx(0.002) ), ...
[0,0,0, 0.001,0,0]','absTol',1e-4);
%Testing with a scalar number input
verifyError(tc, @()tr2delta(1),'SMTB:tr2delta:badarg');
verifyError(tc, @()tr2delta( ones(3,3) ),'SMTB:tr2delta:badarg');
end
% tr2jac - HT to Jacobian
function tr2jac_test(tc)
% unit testing tr2jac with homogeneous transform
T = transl(1,2,3);
[R,t] = tr2rt(T);
verifyEqual(tc, tr2jac(T), [R' zeros(3,3); zeros(3,3) R']);
verifyEqual(tc, tr2jac(T, 'samebody'), [R' (skew(t)*R)'; zeros(3,3) R']);
T = transl(1,2,3) * trotx(pi/2) * trotz(pi/2);
[R,t] = tr2rt(T);
verifyEqual(tc, tr2jac(T), [R' zeros(3,3); zeros(3,3) R']);
verifyEqual(tc, tr2jac(T, 'samebody'), [R' (skew(t)*R)'; zeros(3,3) R']);
% test with scalar value
verifyError(tc, @()tr2jac(1),'SMTB:t2r:badarg');
end
function wtrans_test(tc)
v = [1 2 3 4 5 6]';
tc.verifyEqual( wtrans(eye(4,4), v), v, 'abstol', 1e-10 );
tc.verifyEqual( wtrans(trotx(pi/2), v), [1 3 -2 4 6 -5]', 'abstol', 1e-10 );
tc.verifyEqual( wtrans(troty(pi/2), v), [-3 2 1 -6 5 4]', 'abstol', 1e-10 );
tc.verifyEqual( wtrans(trotz(pi/2), v), [2 -1 3 5 -4 6]', 'abstol', 1e-10 );
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
SimulinkTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/SimulinkTest.m
| 2,857 |
utf_8
|
a6cf49d88a3bccec4399020aebe23602
|
%% Test all the Simulink models
function tests = SimulinkTest
tests = functiontests(localfunctions);
end
function setupOnce(testCase)
testCase.TestData.StopTime = 0.5;
end
function teardownOnce(tc)
delete('*.slxc')
bdclose
end
function braitenberg_test(testCase)
sim('sl_braitenberg', testCase.TestData.StopTime);
bdclose all
end
function lanechange_test(testCase)
sim('sl_lanechange', testCase.TestData.StopTime);
bdclose all
end
function pursuit_test(testCase)
sim('sl_pursuit', testCase.TestData.StopTime);
bdclose all
end
function drivepoint_test(testCase)
assignin('base', 'xg', [5 5]);
assignin('base', 'x0', [0 0 pi/2]);
sim('sl_drivepoint', testCase.TestData.StopTime);
bdclose all
end
function driveline_test(testCase)
assignin('base', 'L', [1 -2 4]);
assignin('base', 'x0', [0 -4 pi]);
sim('sl_driveline', testCase.TestData.StopTime);
bdclose all
end
function drivepose_test(testCase)
assignin('base', 'xg', [5 5 pi/2]);
assignin('base', 'x0', [8 5 pi]);
r = sim('sl_drivepose', testCase.TestData.StopTime);
bdclose all
end
function jspace_test(testCase)
mdl_puma560
assignin('base', 'p560', p560);
sim('sl_jspace', testCase.TestData.StopTime);
bdclose all
end
function rrmc_test(testCase)
mdl_puma560
assignin('base', 'p560', p560);
assignin('base', 'qn', qn);
sim('sl_rrmc', testCase.TestData.StopTime);
bdclose all
end
function rrmc2_test(testCase)
mdl_puma560
assignin('base', 'p560', p560);
assignin('base', 'qn', qn);
sim('sl_rrmc2', testCase.TestData.StopTime);
bdclose all
end
function ztorque_test(testCase)
mdl_puma560
p560 = p560.nofriction();
assignin('base', 'p560', p560);
sim('sl_ztorque', testCase.TestData.StopTime);
bdclose all
end
function vlooptest_test(testCase)
sim('vloop_test', testCase.TestData.StopTime);
bdclose all
end
function plooptest_test(testCase)
G = 107.815; % in case not previously set by vloop_test
sim('ploop_test', 1);
bdclose all
end
function ctorque_test(testCase)
mdl_puma560
p560 = p560.nofriction();
assignin('base', 'p560', p560);
sim('sl_ctorque', testCase.TestData.StopTime);
bdclose all
end
function feedforward_test(testCase)
mdl_puma560
p560 = p560.nofriction();
assignin('base', 'p560', p560);
sim('sl_fforward', testCase.TestData.StopTime);
bdclose all
end
function flexlink_test(testCase)
mdl_twolink
assignin('base', 'twolink', twolink);
sim('sl_flex', testCase.TestData.StopTime);
bdclose all
end
function quadcopter_test(testCase)
sim('sl_quadrotor', testCase.TestData.StopTime);
bdclose all
end
function quadcopter_vs_test(testCase)
testCase.assumeTrue( exist('SphericalCamera') == 2 );
sim('sl_quadrotor_vs', testCase.TestData.StopTime/10);
bdclose all
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
DHFactorTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/DHFactorTest.m
| 4,017 |
utf_8
|
6aafc123b008f31b798d1709095eed20
|
function tests = DHFactorTest
tests = functiontests(localfunctions);
clc
end
function constructor1_test(tc)
dh = DHFactor('Tz(L1)');
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'Tz(L1)');
tc.verifyEqual( char(dh.command('R')), 'SerialLink([], ''name'', ''R'', ''base'', eye(4,4), ''tool'', eye(4,4), ''offset'', [])');
dh = DHFactor('Tz(q1)');
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(0, q1, 0, 0)');
tc.verifyEqual( char(dh.command('R')), 'SerialLink([0, 0, 0, 0, 1; ], ''name'', ''R'', ''base'', eye(4,4), ''tool'', eye(4,4), ''offset'', [0 ])');
dh = DHFactor('Rz(q1)');
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, 0, 0, 0)');
tc.verifyEqual( char(dh.command('R')), 'SerialLink([0, 0, 0, 0, 0; ], ''name'', ''R'', ''base'', eye(4,4), ''tool'', eye(4,4), ''offset'', [0 ])');
end
function constructor2_test(tc)
s = 'Tz(L1) Rz(q1) Rx(90) Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, L1, L2, 90)');
s = 'Tz(L1).Rz(q1).Rx(90).Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, L1, L2, 90)');
s = 'Tz(L1)*Rz(q1)*Rx(90)*Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, L1, L2, 90)');
s = 'Tz(-L1) Rz(q1) Rx(90) Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, -L1, L2, 90)');
s = 'Tz(L1) Rz(-q1) Rx(90) Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(-q1, L1, L2, 90)');
s = 'Tz(L1) Rz(q1) Rx(-90) Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, L1, L2, -90)');
s = 'Tz(L1) Rz(q1) Rx(270) Tx(L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(q1, L1, L2, 270)');
s = 'Tz(-L1) Rz(-q1) Rx(90) Tx(-L2)';
dh = DHFactor(s);
tc.verifyClass(dh, 'DHFactor');
tc.verifySize(dh, [1 1]);
tc.verifyEqual( char(dh.tool), 'eye(4,4)');
tc.verifyEqual( char(dh.base), 'eye(4,4)');
tc.verifyEqual( char(dh), 'DH(-q1, -L1, -L2, 90)');
end
function puma560_test(tc)
s = 'Tz(L1) Rz(q1) Ry(q2) Ty(L2) Tz(L3) Ry(q3) Tx(L4) Ty(L5) Tz(L6) Rz(q4) Ry(q5) Rz(q6)';
dh = DHFactor(s);
tc.verifyEqual( char(dh), 'DH(q1, L1, 0, -90).DH(q2+90, 0, -L3, 0).DH(q3-90, L2+L5, L4, 90).DH(q4, L6, 0, -90).DH(q5, 0, 0, 90).DH(q6, 0, 0, 0)');
L1 = 0; L2 = -0.2337; L3 = 0.4318; L4 = 0.0203; L5 = 0.0837; L6 = 0.4318;
R = eval( dh.command('R') );
tc.verifyEqual(R.n, 6);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
VehicleTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/VehicleTest.m
| 7,297 |
utf_8
|
133abe837f10db9ffcfcd6634c19ffc8
|
function tests = VehicleTest
tests = functiontests(localfunctions);
clc
end
function Bicycle_constructor_test(tc)
% default constructor
v = Bicycle();
% display
v
% char
s = v.char()
tc.verifyTrue( ischar(s) );
% all options
v = Bicycle( ...
'steermax', 2, ...
'accelmax', 3, ...
'covar', [1 2;3 4], ...
'speedmax', 5, ...
'L',2.5, ...
'x0', [1 2 3], ...
'dt', 0.5, ...
'rdim', 0.3 ...
);
tc.verifyEqual(v.steermax, 2);
tc.verifyEqual(v.accelmax, 3);
tc.verifyEqual(v.V, [1 2;3 4]);
tc.verifyEqual(v.speedmax, 5);
tc.verifyEqual(v.L, 2.5);
tc.verifyEqual(v.x0, [1 2 3]');
tc.verifyEqual(v.dt, 0.5);
tc.verifyEqual(v.rdim, 0.3);
v.init()
tc.verifyEqual(v.x, [1 2 3]');
end
function Bicycle_deriv_test(tc)
v = Bicycle('steermax', Inf);
xd =v.deriv([], [0 0 0], [1 0]);
tc.verifyEqual( xd, [1 0 0]', 'AbsTol', 1e-6);
xd =v.deriv([], [0 0 pi/2], [1 0]);
tc.verifyEqual( xd, [0 1 0]', 'AbsTol', 1e-6);
xd =v.deriv([], [0 0 0], [0 1]);
tc.verifyEqual( xd, [0 0 0]', 'AbsTol', 1e-6);
xd =v.deriv([], [0 0 0], [1 pi/4]);
tc.verifyEqual( xd, [1 0 1]', 'AbsTol', 1e-6);
v = Bicycle('steermax', pi/4);
xd =v.deriv([], [0 0 0], [1 100]);
tc.verifyEqual( xd, [1 0 1]', 'AbsTol', 1e-6);
v = Bicycle('speedmax', 1, 'steermax', Inf);
xd =v.deriv([], [0 0 0], [100 pi/4]);
tc.verifyEqual( xd, [1 0 1]', 'AbsTol', 1e-6);
v = Bicycle('accelmax', 1);
xd =v.deriv([], [0 0 0], [100 0]);
tc.verifyEqual( xd, [v.dt 0 0]', 'AbsTol', 1e-6);
for i=1:9
xd =v.deriv([], [0 0 0], [100 0]);
end
tc.verifyEqual( xd, [1 0 0]', 'AbsTol', 1e-6);
end
function Bicycle_update_test(tc)
v = Bicycle('dt', 1, 'speedmax', Inf, 'steermax', Inf);
tc.verifyEqual( v.update([1 0]), [1 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.x, [1 0 0]', 'AbsTol', 1e-6);
tc.verifyEqual( v.update([1 0]), [1 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.x, [2 0 0]', 'AbsTol', 1e-6);
tc.verifyEqual( v.update([-2 0]), [2 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.x, [0 0 0]', 'AbsTol', 1e-6);
tc.verifyEqual( size(v.x_hist,1), 3);
v.init();
tc.verifyEqual( size(v.x_hist,1), 0);
tc.verifyEqual( v.update([0 1]), [0 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.update([1 pi/4]), [1 1], 'AbsTol', 1e-6);
end
function Bicycle_f_test(tc)
v = Bicycle('steermax', Inf);
tc.verifyEqual( v.f([0 0 0], [1 0], [0 0]), [1 0 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([2 3 0], [1 0], [0 0]), [3 3 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [0 0], [1 0]), [1 0 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [0 1], [0 0]), [0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [sqrt(2) pi/4], [0 0]), [1 1 pi/4], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [sqrt(2) 0], [0 pi/4]), [1 1 pi/4], 'AbsTol', 1e-6);
end
function Bicycle_jacobian_test(tc)
v = Bicycle('steermax', Inf);
tc.verifyEqual( v.Fx([0 0 0], [0 0]), [1 0 0; 0 1 0; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fx([0 0 0], [2 0]), [1 0 0; 0 1 2; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fx([2 3 0], [2 0]), [1 0 0; 0 1 2; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fx([0 0 0], [3 pi/2]), [1 0 -3; 0 1 0; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([0 0 0], [0 0]), [1 0; 0 0; 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([2 3 0], [0 0]), [1 0; 0 0; 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([0 0 0], [2 3]), [1 0; 0 0; 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([0 0 pi/2], [0 0]), [0 0; 1 0; 0 1], 'AbsTol', 1e-6);
end
function Unicycle_constructor_test(tc)
% default constructor
v = Unicycle();
% display
v
% char
s = v.char()
tc.verifyTrue( ischar(s) );
% all options
v = Bicycle( ...
'accelmax', 3, ...
'covar', [1 2;3 4], ...
'speedmax', 5, ...
'L',2.5, ...
'x0', [1 2 3], ...
'dt', 0.5, ...
'rdim', 0.3 ...
);
tc.verifyEqual(v.accelmax, 3);
tc.verifyEqual(v.V, [1 2;3 4]);
tc.verifyEqual(v.speedmax, 5);
tc.verifyEqual(v.L, 2.5);
tc.verifyEqual(v.x0, [1 2 3]');
tc.verifyEqual(v.dt, 0.5);
tc.verifyEqual(v.rdim, 0.3);
v.init()
tc.verifyEqual(v.x, [1 2 3]');
end
function Unicycle_deriv_test(tc)
v = Unicycle();
xd =v.deriv([], [0 0 0], [1 0]);
tc.verifyEqual( xd, [1 0 0]', 'AbsTol', 1e-6);
xd =v.deriv([], [0 0 pi/2], [1 0]);
tc.verifyEqual( xd, [0 1 0]', 'AbsTol', 1e-6);
xd =v.deriv([], [0 0 0], [0 1]);
tc.verifyEqual( xd, [0 0 1]', 'AbsTol', 1e-6);
xd =v.deriv([], [0 0 0], [1 1]);
tc.verifyEqual( xd, [1 0 1]', 'AbsTol', 1e-6);
v = Unicycle('speedmax', 1);
xd =v.deriv([], [0 0 0], [100 0]);
tc.verifyEqual( xd, [1 0 0]', 'AbsTol', 1e-6);
v = Unicycle('accelmax', 1);
xd =v.deriv([], [0 0 0], [100 0]);
tc.verifyEqual( xd, [v.dt 0 0]', 'AbsTol', 1e-6);
for i=1:9
xd =v.deriv([], [0 0 0], [100 0]);
end
tc.verifyEqual( xd, [1 0 0]', 'AbsTol', 1e-6);
end
function Unicycle_update_test(tc)
v = Unicycle('dt', 1, 'speedmax', Inf);
tc.verifyEqual( v.update([1 0]), [1 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.x, [1 0 0]', 'AbsTol', 1e-6);
tc.verifyEqual( v.update([1 0]), [1 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.x, [2 0 0]', 'AbsTol', 1e-6);
tc.verifyEqual( v.update([-2 0]), [2 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.x, [0 0 0]', 'AbsTol', 1e-6);
tc.verifyEqual( size(v.x_hist,1), 3);
v.init();
tc.verifyEqual( size(v.x_hist,1), 0);
tc.verifyEqual( v.update([0 1]), [0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.update([2 1]), [2 1], 'AbsTol', 1e-6);
end
function Unicycle_f_test(tc)
v = Unicycle();
tc.verifyEqual( v.f([0 0 0], [1 0], [0 0]), [1 0 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([2 3 0], [1 0], [0 0]), [3 3 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [0 0], [1 0]), [1 0 0], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [0 1], [0 0]), [0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [sqrt(2) pi/4], [0 0]), [1 1 pi/4], 'AbsTol', 1e-6);
tc.verifyEqual( v.f([0 0 0], [sqrt(2) 0], [0 pi/4]), [1 1 pi/4], 'AbsTol', 1e-6);
end
function Unicycle_jacobian_test(tc)
v = Unicycle();
tc.verifyEqual( v.Fx([0 0 0], [0 0]), [1 0 0; 0 1 0; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fx([0 0 0], [2 0]), [1 0 0; 0 1 2; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fx([2 3 0], [2 0]), [1 0 0; 0 1 2; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fx([0 0 0], [3 pi/2]), [1 0 -3; 0 1 0; 0 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([0 0 0], [0 0]), [1 0; 0 0; 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([2 3 0], [0 0]), [1 0; 0 0; 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([0 0 0], [2 3]), [1 0; 0 0; 0 1], 'AbsTol', 1e-6);
tc.verifyEqual( v.Fv([0 0 pi/2], [0 0]), [0 0; 1 0; 0 1], 'AbsTol', 1e-6);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
CodeGeneratorTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/CodeGeneratorTest.m
| 25,883 |
utf_8
|
05b04e19e1fc53ea547e7d804d91560c
|
function tests = CodeGeneratorTest
tests = functiontests(localfunctions);
end
function setupOnce(testCase)
% Create a test robot based on the first three links of the Puma 560.
deg = pi/180;
L(1) = Revolute('d', 0, 'a', 0, 'alpha', pi/2, ...
'I', [0, 0.35, 0, 0, 0, 0], ...
'r', [0, 0, 0], ...
'm', 0, ...
'Jm', 200e-6, ...
'G', -62.6111, ...
'B', 1.48e-3, ...
'Tc', [0.395 -0.435], ...
'qlim', [-160 160]*deg );
L(2) = Revolute('d', 0, 'a', 0.4318, 'alpha', 0, ...
'I', [0.13, 0.524, 0.539, 0, 0, 0], ...
'r', [-0.3638, 0.006, 0.2275], ...
'm', 17.4, ...
'Jm', 200e-6, ...
'G', 107.815, ...
'B', .817e-3, ...
'Tc', [0.126 -0.071], ...
'qlim', [-45 225]*deg );
L(3) = Revolute('d', 0.15005, 'a', 0.0203, 'alpha', -pi/2, ...
'I', [0.066, 0.086, 0.0125, 0, 0, 0], ...
'r', [-0.0203, -0.0141, 0.070], ...
'm', 4.8, ...
'Jm', 200e-6, ...
'G', -53.7063, ...
'B', 1.38e-3, ...
'Tc', [0.132, -0.105], ...
'qlim', [-225 45]*deg );
testRob = SerialLink(L, 'name', 'UnitTestRobot');
testCase.TestData.rob = testRob.nofriction('all');
testCase.TestData.nTrials = 1; % number of tests to perform in each subroutine
testCase.TestData.profile = false;
testCase.TestData.cGen = CodeGenerator(testCase.TestData.rob,'default','logfile','cGenUnitTestLog.txt');
testCase.TestData.cGen.verbose = 0;
end
function teardownOnce(testCase)
clear mex
if ~isempty(strfind(path,testCase.TestData.cGen.basepath))
rmpath(testCase.TestData.cGen.basepath)
rmdir(testCase.TestData.cGen.basepath, 's')
delete(testCase.TestData.cGen.logfile);
end
end
%%
function genfkine_test(testCase)
% - test generated forward kinematics code
T = testCase.TestData.cGen.genfkine; % generate symbolic expressions and m-files
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
symQ = testCase.TestData.rob.gencoords;
Q = rand(testCase.TestData.nTrials,specRob.n);
resRTB = rand(4,4,testCase.TestData.nTrials);
resSym = rand(4,4,testCase.TestData.nTrials);
resM = rand(4,4,testCase.TestData.nTrials);
resMEX = rand(4,4,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.fkine(q).T;
resSym(:,:,iTry) = subs(T.T,symQ,q);
resM(:,:,iTry) = specRob.fkine(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'fkine']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'fkine']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resSym, 'absTol', 1e-6);
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodefkine;
testCase.TestData.cGen.genmexfkine;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resMEX(:,:,iTry) = specRob.fkine(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'fkine.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
%%
function genjacobian_test(testCase)
% - test generated differential kinematics code
[J0, Jn] = testCase.TestData.cGen.genjacobian;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
symQ = testCase.TestData.rob.gencoords;
Q = rand(testCase.TestData.nTrials,specRob.n);
resRTB0 = rand(6,specRob.n,testCase.TestData.nTrials);
resSym0 = rand(6,specRob.n,testCase.TestData.nTrials);
resM0 = rand(6,specRob.n,testCase.TestData.nTrials);
resMEX0 = rand(6,specRob.n,testCase.TestData.nTrials);
resRTBn = rand(6,specRob.n,testCase.TestData.nTrials);
resSymn = rand(6,specRob.n,testCase.TestData.nTrials);
resMn = rand(6,specRob.n,testCase.TestData.nTrials);
resMEXn = rand(6,specRob.n,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resRTB0(:,:,iTry) = testCase.TestData.rob.jacob0(q);
resSym0(:,:,iTry) = subs(J0,symQ,q);
resM0(:,:,iTry) = specRob.jacob0(q);
resRTBn(:,:,iTry) = testCase.TestData.rob.jacobe(q);
resSymn(:,:,iTry) = subs(Jn,symQ,q);
resMn(:,:,iTry) = specRob.jacobe(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'jacob0']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'jacob0']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB0, resSym0, 'absTol', 1e-6);
verifyEqual(testCase, resRTB0, resM0, 'absTol', 1e-6);
verifyEqual(testCase, resRTBn, resSymn, 'absTol', 1e-6);
verifyEqual(testCase, resRTBn, resMn, 'absTol', 1e-6);
testCase.TestData.cGen.genccodejacobian;
testCase.TestData.cGen.genmexjacobian;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resMEX0(:,:,iTry) = specRob.jacob0(q);
resMEXn(:,:,iTry) = specRob.jacobe(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'jacob0.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB0, resMEX0, 'absTol', 1e-6);
verifyEqual(testCase, resRTBn, resMEXn, 'absTol', 1e-6);
end
%%
function geninertia_test(testCase)
% - test inertial matrix against numeric version
[I] = testCase.TestData.cGen.geninertia;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
symQ = testCase.TestData.rob.gencoords;
Q = rand(testCase.TestData.nTrials,specRob.n);
resRTB = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
resSym = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
resM = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
resMEX = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.inertia(q);
resSym(:,:,iTry) = subs(I,symQ,q);
resM(:,:,iTry) = specRob.inertia(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'inertia']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'inertia']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resSym, 'absTol', 1e-6);
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodeinertia;
testCase.TestData.cGen.genmexinertia;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resMEX(:,:,iTry) = specRob.inertia(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'inertia.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
function gencoriolis_test(testCase)
% - test coriolis matrix against numeric version
[C] = testCase.TestData.cGen.gencoriolis;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
[symQ symQD] = testCase.TestData.rob.gencoords;
Q = rand(testCase.TestData.nTrials,specRob.n);
QD = rand(testCase.TestData.nTrials,specRob.n);
resRTB = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
resSym = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
resM = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
resMEX = rand(specRob.n,specRob.n,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
qd = QD(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.coriolis(q,qd);
resSym(:,:,iTry) = subs(subs(C,symQ,q),symQD,qd);
resM(:,:,iTry) = specRob.coriolis(q,qd);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'coriolis']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'coriolis']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resSym, 'absTol', 1e-6);
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodecoriolis;
testCase.TestData.cGen.genmexcoriolis;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
qd = QD(iTry,:);
resMEX(:,:,iTry) = specRob.coriolis(q,qd);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'coriolis.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
%%
function gengravload_test(testCase)
% - test vector of gravitational load against numeric version
[g] = testCase.TestData.cGen.gengravload;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
symQ = testCase.TestData.rob.gencoords;
Q = rand(testCase.TestData.nTrials,specRob.n);
resRTB = rand(specRob.n,1,testCase.TestData.nTrials);
resSym = rand(specRob.n,1,testCase.TestData.nTrials);
resM = rand(specRob.n,1,testCase.TestData.nTrials);
resMEX = rand(specRob.n,1,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.gravload(q);
resSym(:,:,iTry) = subs(g,symQ,q);
resM(:,:,iTry) = specRob.gravload(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'gravload']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'gravload']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resSym, 'absTol', 1e-6);
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodegravload;
testCase.TestData.cGen.genmexgravload;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
resMEX(:,:,iTry) = specRob.gravload(q);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'gravload.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
function genfriction_test(testCase)
% - test friction vector against numeric version
[F] = testCase.TestData.cGen.genfriction;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
[~, symQD] = testCase.TestData.rob.gencoords;
QD = rand(testCase.TestData.nTrials,specRob.n);
resRTB = rand(specRob.n,1,testCase.TestData.nTrials);
resSym = rand(specRob.n,1,testCase.TestData.nTrials);
resM = rand(specRob.n,1,testCase.TestData.nTrials);
resMEX = rand(specRob.n,1,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
qd = QD(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.friction(qd);
resSym(:,:,iTry) = subs(F,symQD,qd);
resM(:,:,iTry) = specRob.friction(qd);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'friction']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'friction']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resSym, 'absTol', 1e-6);
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodefriction;
testCase.TestData.cGen.genmexfriction;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
qd = QD(iTry,:);
resMEX(:,:,iTry) = specRob.friction(qd);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'friction.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
function geninvdyn_test(testCase)
% - test inverse dynamics against numeric version
tau = testCase.TestData.cGen.geninvdyn;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
[symQ, symQD, symQDD] = testCase.TestData.rob.gencoords;
Q = rand(testCase.TestData.nTrials,specRob.n);
QD = 0*rand(testCase.TestData.nTrials,specRob.n);
QDD = 0*rand(testCase.TestData.nTrials,specRob.n);
resRTB = rand(specRob.n,1,testCase.TestData.nTrials);
resSym = rand(specRob.n,1,testCase.TestData.nTrials);
resM = rand(specRob.n,1,testCase.TestData.nTrials);
resMEX = rand(specRob.n,1,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
qd = QD(iTry,:);
qdd = QDD(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.rne(q,qd,qdd);
resSym(:,:,iTry) = subs(subs(subs(tau,symQ,q),symQD,qd),symQDD,qdd);
resM(:,:,iTry) = specRob.invdyn(q, qd, qdd);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'rne']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'invdyn']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resSym, 'absTol', 1e-6);
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodeinvdyn;
testCase.TestData.cGen.genmexinvdyn;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
qd = QD(iTry,:);
qdd = QDD(iTry,:);
resMEX(:,:,iTry) = specRob.invdyn(q,qd,qdd);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'invdyn.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
function genfdyn_test(testCase)
% - test forward dynamics against numeric version
IqddSym = testCase.TestData.cGen.genfdyn.';
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
[symQ, symQD] = testCase.TestData.rob.gencoords;
symTau = testCase.TestData.rob.genforces;
Q = rand(testCase.TestData.nTrials,specRob.n);
QD = rand(testCase.TestData.nTrials,specRob.n);
TAU = rand(testCase.TestData.nTrials,specRob.n);
resRTB = zeros(specRob.n,1,testCase.TestData.nTrials);
resSym = zeros(specRob.n,1,testCase.TestData.nTrials);
resM = zeros(specRob.n,1,testCase.TestData.nTrials);
resMEX = zeros(specRob.n,1,testCase.TestData.nTrials);
if testCase.TestData.profile
profile on
end
% test symbolics and generated m-code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
qd = QD(iTry,:);
tau = TAU(iTry,:);
resRTB(:,:,iTry) = testCase.TestData.rob.accel(q,qd,tau);
resSym(:,:,iTry) = subs(subs(subs(IqddSym,symQ,q),symQD,qd),symTau,tau);
resM(:,:,iTry) = specRob.accel(q, qd, tau);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statRTB = getprofilefunctionstats(pstat,['SerialLink',filesep,'accel']);
statSym = getprofilefunctionstats(pstat,['sym',filesep,'subs']);
statM = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'accel']);
profile clear;
end
clear('specRob');
rmpath(testCase.TestData.cGen.basepath)
% assertions so far?
verifyEqual(testCase, resRTB, resM, 'absTol', 1e-6);
testCase.TestData.cGen.genccodefdyn;
testCase.TestData.cGen.genmexfdyn;
addpath(testCase.TestData.cGen.basepath);
specRob = eval(testCase.TestData.cGen.getrobfname);
if testCase.TestData.profile
profile on;
end
% test generated mex code
for iTry = 1:testCase.TestData.nTrials
q = Q(iTry,:);
qd = QD(iTry,:);
tau = TAU(iTry,:);
resMEX(:,:,iTry) = specRob.accel(q,qd,tau);
end
if testCase.TestData.profile
profile off;
pstat = profile('info');
statMEX = getprofilefunctionstats(pstat,[testCase.TestData.cGen.getrobfname,filesep,'accel.',mexext],'mex-function');
tRTB = statRTB.TotalTime/statRTB.NumCalls;
tSym = statSym.TotalTime/statSym.NumCalls;
tM = statM.TotalTime/statM.NumCalls;
tMEX = statMEX.TotalTime/statMEX.NumCalls;
fprintf('RTB function time(testCase): %f\n', tRTB)
fprintf('Sym function time(testCase): %f speedups: %f to RTB\n',tSym, tRTB/tSym);
fprintf('M function time(testCase): %f speedups: %f to RTB, %f to Sym\n',tM, tRTB/tM, tSym/tM);
fprintf('MEX function time(testCase): %f speedups: %f to RTB, %f to Sym, %f to M\n',tMEX, tRTB/tMEX, tSym/tMEX, tM/tMEX);
end
z = abs(resRTB-resMEX);
max(z(:))
verifyEqual(testCase, resRTB, resMEX, 'absTol', 1e-6);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
sl_tripleangleTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/sl_tripleangleTest.m
| 2,599 |
utf_8
|
7b1fccab6fb5e3e055af09dc9217747b
|
% test the Simulink RPY and Euler blocks
% in conjunction with sl_tripleangleTest.m
function tests = sl_tripleangleTest
tests = functiontests(localfunctions);
clc
end
function setupOnce(tc)
sl_tripleangle
end
function teardownOnce(tc)
bdclose
end
function radians_test(tc)
angles = [0.3 0.4 0.5];
seq = 'XYZ';
set_param('sl_tripleangle/a', 'Value', num2str(angles(1)))
set_param('sl_tripleangle/b', 'Value', num2str(angles(2)))
set_param('sl_tripleangle/c', 'Value', num2str(angles(3)))
set_param('sl_tripleangle/rpy2T', 'degrees' ,'off')
set_param('sl_tripleangle/T2rpy', 'degrees' ,'off')
set_param('sl_tripleangle/T2rpy', 'sequence', seq)
set_param('sl_tripleangle/rpy2T', 'sequence', seq)
set_param('sl_tripleangle/eul2T', 'degrees' ,'off')
set_param('sl_tripleangle/T2eul', 'degrees' ,'off')
[~,~,y] = sim('sl_tripleangle');
tc.verifyEqual(y(1,:), [angles angles], 'AbsTol', 1e-10);
seq = 'ZYX';
set_param('sl_tripleangle/T2rpy', 'sequence', seq)
set_param('sl_tripleangle/rpy2T', 'sequence', seq)
[~,~,y] = sim('sl_tripleangle');
tc.verifyEqual(y(1,:), [angles angles], 'AbsTol', 1e-10);
seq = 'YXZ';
set_param('sl_tripleangle/T2rpy', 'sequence', seq)
set_param('sl_tripleangle/rpy2T', 'sequence', seq)
[~,~,y] = sim('sl_tripleangle');
tc.verifyEqual(y(1,:), [angles angles], 'AbsTol', 1e-10);
end
function degrees_test(tc)
% now in degrees
angles = [30 40 50];
seq = 'XYZ';
set_param('sl_tripleangle/a', 'Value', num2str(angles(1)))
set_param('sl_tripleangle/b', 'Value', num2str(angles(2)))
set_param('sl_tripleangle/c', 'Value', num2str(angles(3)))
set_param('sl_tripleangle/rpy2T', 'degrees' ,'on')
set_param('sl_tripleangle/T2rpy', 'degrees' ,'on')
set_param('sl_tripleangle/T2rpy', 'sequence', seq)
set_param('sl_tripleangle/rpy2T', 'sequence', seq)
set_param('sl_tripleangle/eul2T', 'degrees' ,'on')
set_param('sl_tripleangle/T2eul', 'degrees' ,'on')
[~,~,y] = sim('sl_tripleangle');
tc.verifyEqual(y(1,:), [angles angles], 'AbsTol', 1e-10);
seq = 'ZYX';
set_param('sl_tripleangle/T2rpy', 'sequence', seq)
set_param('sl_tripleangle/rpy2T', 'sequence', seq)
[~,~,y] = sim('sl_tripleangle');
tc.verifyEqual(y(1,:), [angles angles], 'AbsTol', 1e-10);
seq = 'YXZ';
set_param('sl_tripleangle/T2rpy', 'sequence', seq)
set_param('sl_tripleangle/rpy2T', 'sequence', seq)
[~,~,y] = sim('sl_tripleangle');
tc.verifyEqual(y(1,:), [angles angles], 'AbsTol', 1e-10);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
ETS3Test.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/ETS3Test.m
| 1,163 |
utf_8
|
cdc2014c04234c88bb7e8546058367e1
|
function tests = ETS3Test
tests = functiontests(localfunctions);
clc
end
function revolute1_test(tc)
import ETS3.*
a1 = 1;
E = Rx('q1') * Tx(a1) * Ry('q2') * Ty(a1) * Rz('q3');
tc.verifyTrue(isa(E, 'ETS3'))
tc.verifySize(E, [1 5])
tc.verifyEqual(E.n, 3) % number of joints
tc.verifyClass(char(E), 'char')
tc.verifyEqual(E.structure, 'RRR');
end
function prismatic_test(tc)
import ETS3.*
a1 = 1;
E = Tx('q1') * Rx(a1) * Ty('q2') * Ry(a1) * Tz('q3');
tc.verifyTrue(isa(E, 'ETS3'))
tc.verifySize(E, [1 5])
tc.verifyEqual(E.n, 3) % number of joints
tc.verifyClass(char(E), 'char')
tc.verifyEqual(E.structure, 'PPP');
end
function fkine_test(tc)
import ETS3.*
a1 = 1;
E = Rx('q1') * Tx(a1) * Ry('q2') * Ty(a1) * Rz('q3');
T = E.fkine([pi/2 pi/2 pi/2]);
tc.verifyClass(T, 'SE3')
tc.verifyEqual(double(T), [0 0 1 1; 0 -1 0 0; 1 0 0 1; 0 0 0 1], 'AbsTol', 1e-12)
end
function plot_test(tc)
import ETS3.*
a1 = 1; a2 = 1;
E = Rx('q1') * Tx(a1) * Ry('q2') * Ty(a1) * Rz('q3');
E.plot([pi/4 -pi/4 pi/4])
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
LocnTest.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/LocnTest.m
| 4,870 |
utf_8
|
bf1993bf5cb0808ccb0a933d4810a032
|
function tests = LocnTest
tests = functiontests(localfunctions);
clc
end
function setupOnce(testCase)
testCase.TestData.Duration = 50;
end
function Vehicle_test(tc)
%%
randinit
V = diag([0.005, 0.5*pi/180].^2);
v = Bicycle('covar', V);
v.add_driver( RandomPath(10) );
v.run(tc.TestData.Duration);
v.plot_xy();
s = v.char();
J = v.Fx(v.x, [.1 .2]);
J = v.Fv(v.x, [.1 .2]);
end
function DeadReckoning_test(tc)
%%
randinit
V = diag([0.005, 0.5*pi/180].^2);
P0 = diag([0.005, 0.005, 0.001].^2);
v = Bicycle('covar', V);
v.add_driver( RandomPath(10) );
s = char(v);
ekf = EKF(v, V, P0);
ekf.run(tc.TestData.Duration);
clf
ekf.plot_xy
hold on
v.plot_xy('r')
grid on
xyzlabel
ekf.plot_ellipse('g')
ekf.plot_P()
end
function MapLocalization_test(tc)
%%
randinit
W = diag([0.1, 1*pi/180].^2);
P0 = diag([0.005, 0.005, 0.001].^2);
V = diag([0.005, 0.5*pi/180].^2);
map = LandmarkMap(20);
map = LandmarkMap(20, 'verbose');
map = LandmarkMap(20, 10, 'verbose');
map = LandmarkMap(20, 10);
s = char(map);
veh = Bicycle('covar', V);
veh.add_driver( RandomPath(10) );
sensor = RangeBearingSensor(veh, map, 'covar', W);
sensor.interval = 5;
ekf = EKF(veh, W, P0, sensor, W, map);
ekf.run(tc.TestData.Duration);
clf
map.plot()
veh.plot_xy('b');
ekf.plot_xy('r');
ekf.plot_ellipse('k')
grid on
xyzlabel
clf
ekf.plot_P()
end
function Mapping_test(tc)
%%
randinit
W = diag([0.1, 1*pi/180].^2);
V = diag([0.005, 0.5*pi/180].^2);
map = LandmarkMap(20, 10);
veh = Bicycle('covar', V);
veh.add_driver( RandomPath(10) );
sensor = RangeBearingSensor(veh, map, 'covar', W);
sensor.interval = 5;
ekf = EKF(veh, [], [], sensor, W, []);
ekf.run(tc.TestData.Duration);
clf
map.plot()
veh.plot_xy('b');
ekf.plot_map('g');
grid on
xyzlabel
%%
verifyEqual(tc, numcols(ekf.landmarks), 20);
end
function SLAM_test(tc)
%%
randinit
W = diag([0.1, 1*pi/180].^2);
P0 = diag([0.005, 0.005, 0.001].^2);
V = diag([0.005, 0.5*pi/180].^2);
map = LandmarkMap(20, 10);
veh = Bicycle(V);
veh.add_driver( RandomPath(10) );
sensor = RangeBearingSensor(veh, map, 'covar', W);
sensor.interval = 1;
ekf = EKF(veh, V, P0, sensor, W, []);
ekf
ekf.verbose = false;
ekf.run(tc.TestData.Duration);
clf
map.plot()
veh.plot_xy('b');
ekf.plot_xy('r');
ekf.plot_ellipse('k')
grid on
xyzlabel
clf
ekf.plot_P()
clf
map.plot();
ekf.plot_map('g');
%%
verifyEqual(tc, numcols(ekf.landmarks), 20);
end
function ParticleFilter_test(tc)
%%
randinit
map = LandmarkMap(20);
W = diag([0.1, 1*pi/180].^2);
v = Bicycle('covar', W);
v.add_driver( RandomPath(10) );
V = diag([0.005, 0.5*pi/180].^2);
sensor = RangeBearingSensor(v, map, 'covar', V);
Q = diag([0.1, 0.1, 1*pi/180]).^2;
L = diag([0.1 0.1]);
pf = ParticleFilter(v, sensor, Q, L, 1000);
pf
pf.run(tc.TestData.Duration);
plot(pf.std)
xlabel('time step')
ylabel('standard deviation')
legend('x', 'y', '\theta')
grid
clf
pf.plot_pdf();
clf
pf.plot_xy();
end
function posegraph_test(tc)
pg = PoseGraph('pg1.g2o')
tc.verifyClass(pg, 'PoseGraph');
tc.verifyEqual(pg.graph.n, 4);
clf
pg.plot()
pg.optimize('animate')
close all
pg = PoseGraph('killian-small.toro')
tc.verifyClass(pg, 'PoseGraph');
tc.verifyEqual(pg.graph.n, 1941);
pg = PoseGraph('killian.g2o', 'laser')
tc.verifyClass(pg, 'PoseGraph');
tc.verifyEqual(pg.graph.n, 3873);
[r,theta] = pg.scan(1);
tc.verifyClass(r, 'double');
tc.verifyLength(r, 180);
tc.verifyClass(theta, 'double');
tc.verifyLength(theta, 180);
[x,y] = pg.scan(1);
tc.verifyClass(x, 'double');
tc.verifyLength(x, 180);
tc.verifyClass(y, 'double');
tc.verifyLength(y, 180);
pose = pg.pose(1);
tc.verifyClass(pose, 'double');
tc.verifySize(pose, [3 1]);
t = pg.time(1);
tc.verifyClass(t, 'double');
tc.verifySize(t, [1 1]);
w = pg.scanmap('ngrid', 3000);
tc.verifyClass(w, 'int32');
tc.verifySize(w, [3000 3000]);
tc.assumeTrue(exist('idisp', 'file')); %REMINDER
clf
pg.plot_occgrid(w);
close all
end
function makemap_test(tc)
tc.assumeTrue(false); %REMINDER
end
function chi2inv_test(tc)
tc.verifyEqual( chi2inv_rtb(0,2), 0);
tc.verifyEqual( chi2inv_rtb(1,2), Inf);
tc.verifyEqual( chi2inv_rtb(3,2), NaN);
tc.verifyError( @() chi2inv_rtb(1,1), 'RTB:chi2inv_rtb:badarg');
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
ETS2Test.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/unit_test/ETS2Test.m
| 1,362 |
utf_8
|
4807c7cbda642f59e8dcd4af08ebb115
|
function tests = ETS2Test
tests = functiontests(localfunctions);
clc
end
function revolute1_test(tc)
import ETS2.*
a1 = 1;
E = Rz('q1') * Tx(a1);
tc.verifyTrue(isa(E, 'ETS2'))
tc.verifySize(E, [1 2])
tc.verifyEqual(E.n, 1) % number of joints
tc.verifyClass(char(E), 'char')
tc.verifyEqual(E.structure, 'R');
end
function revolute2_test(tc)
import ETS2.*
a1 = 1; a2 = 1;
E = Rz('q1') * Tx(a1) * Rz('q2') * Tx(a2);
tc.verifyTrue(isa(E, 'ETS2'))
tc.verifySize(E, [1 4])
tc.verifyEqual(E.n, 2) % number of joints
tc.verifyClass(char(E), 'char')
tc.verifyEqual(E.structure, 'RR');
end
function prismatic_test(tc)
import ETS2.*
a1 = 1;
E = Rz('q1') * Tx(a1) * Tx('q2');
tc.verifyTrue(isa(E, 'ETS2'))
tc.verifySize(E, [1 3])
tc.verifyEqual(E.n, 2) % number of joints
tc.verifyClass(char(E), 'char')
tc.verifyEqual(E.structure, 'RP');
end
function fkine_test(tc)
import ETS2.*
a1 = 1;
E = Rz('q1') * Tx(a1) * Tx('q2');
T = E.fkine([pi/2 1]);
tc.verifyClass(T, 'SE2')
tc.verifyEqual(double(T), [0 -1 0; 1 0 2; 0 0 1], 'AbsTol', 1e-12)
end
function plot_test(tc)
import ETS2.*
a1 = 1; a2 = 1;
E = Rz('q1') * Tx(a1) * Rz('q2') * Tx(a2);
E.plot([pi/4 -pi/4])
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
arrow.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/private/arrow.m
| 55,316 |
utf_8
|
a9fba6cb870e440f70d88c6a4849cb63
|
function [h,yy,zz] = arrow(varargin)
% ARROW Draw a line with an arrowhead.
%
% ARROW(Start,Stop) draws a line with an arrow from Start to Stop (points
% should be vectors of length 2 or 3, or matrices with 2 or 3
% columns), and returns the graphics handle of the arrow(s).
%
% ARROW uses the mouse (click-drag) to create an arrow.
%
% ARROW DEMO & ARROW DEMO2 show 3-D & 2-D demos of the capabilities of ARROW.
%
% ARROW may be called with a normal argument list or a property-based list.
% ARROW(Start,Stop,Length,BaseAngle,TipAngle,Width,Page,CrossDir) is
% the full normal argument list, where all but the Start and Stop
% points are optional. If you need to specify a later argument (e.g.,
% Page) but want default values of earlier ones (e.g., TipAngle),
% pass an empty matrix for the earlier ones (e.g., TipAngle=[]).
%
% ARROW('Property1',PropVal1,'Property2',PropVal2,...) creates arrows with the
% given properties, using default values for any unspecified or given as
% 'default' or NaN. Some properties used for line and patch objects are
% used in a modified fashion, others are passed directly to LINE, PATCH,
% or SET. For a detailed properties explanation, call ARROW PROPERTIES.
%
% Start The starting points. B
% Stop The end points. /|\ ^
% Length Length of the arrowhead in pixels. /|||\ |
% BaseAngle Base angle in degrees (ADE). //|||\\ L|
% TipAngle Tip angle in degrees (ABC). ///|||\\\ e|
% Width Width of the base in pixels. ////|||\\\\ n|
% Page Use hardcopy proportions. /////|D|\\\\\ g|
% CrossDir Vector || to arrowhead plane. //// ||| \\\\ t|
% NormalDir Vector out of arrowhead plane. /// ||| \\\ h|
% Ends Which end has an arrowhead. //<----->|| \\ |
% ObjectHandles Vector of handles to update. / base ||| \ V
% E angle||<-------->C
% ARROW(H,'Prop1',PropVal1,...), where H is a |||tipangle
% vector of handles to previously-created arrows |||
% and/or line objects, will update the previously- |||
% created arrows according to the current view -->|A|<-- width
% and any specified properties, and will convert
% two-point line objects to corresponding arrows. ARROW(H) will update
% the arrows if the current view has changed. Root, figure, or axes
% handles included in H are replaced by all descendant Arrow objects.
%
% A property list can follow any specified normal argument list, e.g.,
% ARROW([1 2 3],[0 0 0],36,'BaseAngle',60) creates an arrow from (1,2,3) to
% the origin, with an arrowhead of length 36 pixels and 60-degree base angle.
%
% The basic arguments or properties can generally be vectorized to create
% multiple arrows with the same call. This is done by passing a property
% with one row per arrow, or, if all arrows are to have the same property
% value, just one row may be specified.
%
% You may want to execute AXIS(AXIS) before calling ARROW so it doesn't change
% the axes on you; ARROW determines the sizes of arrow components BEFORE the
% arrow is plotted, so if ARROW changes axis limits, arrows may be malformed.
%
% This version of ARROW uses features of MATLAB 6.x and is incompatible with
% earlier MATLAB versions (ARROW for MATLAB 4.2c is available separately);
% some problems with perspective plots still exist.
% Copyright (c)1995-2009, Dr. Erik A. Johnson <[email protected]>, 5/20/2009
% http://www.usc.edu/civil_eng/johnsone/
% Revision history:
% 5/20/09 EAJ Fix view direction in (3D) demo.
% 6/26/08 EAJ Replace eval('trycmd','catchcmd') with try, trycmd; catch,
% catchcmd; end; -- break's MATLAB 5 compatibility.
% 8/26/03 EAJ Eliminate OpenGL attempted fix since it didn't fix anyway.
% 11/15/02 EAJ Accomodate how MATLAB 6.5 handles NaN and logicals
% 7/28/02 EAJ Tried (but failed) work-around for MATLAB 6.x / OpenGL bug
% if zero 'Width' or not double-ended
% 11/10/99 EAJ Add logical() to eliminate zero index problem in MATLAB 5.3.
% 11/10/99 EAJ Corrected warning if axis limits changed on multiple axes.
% 11/10/99 EAJ Update e-mail address.
% 2/10/99 EAJ Some documentation updating.
% 2/24/98 EAJ Fixed bug if Start~=Stop but both colinear with viewpoint.
% 8/14/97 EAJ Added workaround for MATLAB 5.1 scalar logical transpose bug.
% 7/21/97 EAJ Fixed a few misc bugs.
% 7/14/97 EAJ Make arrow([],'Prop',...) do nothing (no old handles)
% 6/23/97 EAJ MATLAB 5 compatible version, release.
% 5/27/97 EAJ Added Line Arrows back in. Corrected a few bugs.
% 5/26/97 EAJ Changed missing Start/Stop to mouse-selected arrows.
% 5/19/97 EAJ MATLAB 5 compatible version, beta.
% 4/13/97 EAJ MATLAB 5 compatible version, alpha.
% 1/31/97 EAJ Fixed bug with multiple arrows and unspecified Z coords.
% 12/05/96 EAJ Fixed one more bug with log plots and NormalDir specified
% 10/24/96 EAJ Fixed bug with log plots and NormalDir specified
% 11/13/95 EAJ Corrected handling for 'reverse' axis directions
% 10/06/95 EAJ Corrected occasional conflict with SUBPLOT
% 4/24/95 EAJ A major rewrite.
% Fall 94 EAJ Original code.
% Things to be done:
% - in the arrow_clicks section, prompt by printing to the screen so that
% the user knows what's going on; also make sure the figure is brought
% to the front.
% - segment parsing, computing, and plotting into separate subfunctions
% - change computing from Xform to Camera paradigms
% + this will help especially with 3-D perspective plots
% + if the WarpToFill section works right, remove warning code
% + when perpsective works properly, remove perspective warning code
% - add cell property values and struct property name/values (like get/set)
% - get rid of NaN as the "default" data label
% + perhaps change userdata to a struct and don't include (or leave
% empty) the values specified as default; or use a cell containing
% an empty matrix for a default value
% - add functionality of GET to retrieve current values of ARROW properties
% Many thanks to Keith Rogers <[email protected]> for his many excellent
% suggestions and beta testing. Check out his shareware package MATDRAW
% (at ftp://ftp.mathworks.com/pub/contrib/v5/graphics/matdraw/) -- he has
% permission to distribute ARROW with MATDRAW.
% Permission is granted to distribute ARROW with the toolboxes for the book
% "Solving Solid Mechanics Problems with MATLAB 5", by F. Golnaraghi et al.
% (Prentice Hall, 1999).
% Permission is granted to Dr. Josef Bigun to distribute ARROW with his
% software to reproduce the figures in his image analysis text.
% global variable initialization
global ARROW_PERSP_WARN ARROW_STRETCH_WARN ARROW_AXLIMITS
if isempty(ARROW_PERSP_WARN ), ARROW_PERSP_WARN =1; end;
if isempty(ARROW_STRETCH_WARN), ARROW_STRETCH_WARN=1; end;
% Handle callbacks
if (nargin>0 & isstr(varargin{1}) & strcmp(lower(varargin{1}),'callback')),
arrow_callback(varargin{2:end}); return;
end;
% Are we doing the demo?
c = sprintf('\n');
if (nargin==1 & isstr(varargin{1})),
arg1 = lower(varargin{1});
if strncmp(arg1,'prop',4), arrow_props;
elseif strncmp(arg1,'demo',4)
clf reset
demo_info = arrow_demo;
if ~strncmp(arg1,'demo2',5),
hh=arrow_demo3(demo_info);
else,
hh=arrow_demo2(demo_info);
end;
if (nargout>=1), h=hh; end;
elseif strncmp(arg1,'fixlimits',3),
arrow_fixlimits(ARROW_AXLIMITS);
ARROW_AXLIMITS=[];
elseif strncmp(arg1,'help',4),
disp(help(mfilename));
else,
error([upper(mfilename) ' got an unknown single-argument string ''' deblank(arg1) '''.']);
end;
return;
end;
% Check # of arguments
if (nargout>3), error([upper(mfilename) ' produces at most 3 output arguments.']); end;
% find first property number
firstprop = nargin+1;
for k=1:length(varargin), if ~isnumeric(varargin{k}), firstprop=k; break; end; end;
lastnumeric = firstprop-1;
% check property list
if (firstprop<=nargin),
for k=firstprop:2:nargin,
curarg = varargin{k};
if ~isstr(curarg) | sum(size(curarg)>1)>1,
error([upper(mfilename) ' requires that a property name be a single string.']);
end;
end;
if (rem(nargin-firstprop,2)~=1),
error([upper(mfilename) ' requires that the property ''' ...
varargin{nargin} ''' be paired with a property value.']);
end;
end;
% default output
if (nargout>0), h=[]; end;
if (nargout>1), yy=[]; end;
if (nargout>2), zz=[]; end;
% set values to empty matrices
start = [];
stop = [];
len = [];
baseangle = [];
tipangle = [];
wid = [];
page = [];
crossdir = [];
ends = [];
ax = [];
oldh = [];
ispatch = [];
defstart = [NaN NaN NaN];
defstop = [NaN NaN NaN];
deflen = 16;
defbaseangle = 90;
deftipangle = 16;
defwid = 0;
defpage = 0;
defcrossdir = [NaN NaN NaN];
defends = 1;
defoldh = [];
defispatch = 1;
% The 'Tag' we'll put on our arrows
ArrowTag = 'Arrow';
% check for oldstyle arguments
if (firstprop==2),
% assume arg1 is a set of handles
oldh = varargin{1}(:);
if isempty(oldh), return; end;
elseif (firstprop>9),
error([upper(mfilename) ' takes at most 8 non-property arguments.']);
elseif (firstprop>2),
{start,stop,len,baseangle,tipangle,wid,page,crossdir};
args = [varargin(1:firstprop-1) cell(1,length(ans)-(firstprop-1))];
[start,stop,len,baseangle,tipangle,wid,page,crossdir] = deal(args{:});
end;
% parse property pairs
extraprops={};
for k=firstprop:2:nargin,
prop = varargin{k};
val = varargin{k+1};
prop = [lower(prop(:)') ' '];
if strncmp(prop,'start' ,5), start = val;
elseif strncmp(prop,'stop' ,4), stop = val;
elseif strncmp(prop,'len' ,3), len = val(:);
elseif strncmp(prop,'base' ,4), baseangle = val(:);
elseif strncmp(prop,'tip' ,3), tipangle = val(:);
elseif strncmp(prop,'wid' ,3), wid = val(:);
elseif strncmp(prop,'page' ,4), page = val;
elseif strncmp(prop,'cross' ,5), crossdir = val;
elseif strncmp(prop,'norm' ,4), if (isstr(val)), crossdir=val; else, crossdir=val*sqrt(-1); end;
elseif strncmp(prop,'end' ,3), ends = val;
elseif strncmp(prop,'object',6), oldh = val(:);
elseif strncmp(prop,'handle',6), oldh = val(:);
elseif strncmp(prop,'type' ,4), ispatch = val;
elseif strncmp(prop,'userd' ,5), %ignore it
else,
% make sure it is a valid patch or line property
try
get(0,['DefaultPatch' varargin{k}]);
catch
errstr = lasterr;
try
get(0,['DefaultLine' varargin{k}]);
catch
errstr(1:max(find(errstr==char(13)|errstr==char(10)))) = '';
error([upper(mfilename) ' got ' errstr]);
end
end;
extraprops={extraprops{:},varargin{k},val};
end;
end;
% Check if we got 'default' values
start = arrow_defcheck(start ,defstart ,'Start' );
stop = arrow_defcheck(stop ,defstop ,'Stop' );
len = arrow_defcheck(len ,deflen ,'Length' );
baseangle = arrow_defcheck(baseangle,defbaseangle,'BaseAngle' );
tipangle = arrow_defcheck(tipangle ,deftipangle ,'TipAngle' );
wid = arrow_defcheck(wid ,defwid ,'Width' );
crossdir = arrow_defcheck(crossdir ,defcrossdir ,'CrossDir' );
page = arrow_defcheck(page ,defpage ,'Page' );
ends = arrow_defcheck(ends ,defends ,'' );
oldh = arrow_defcheck(oldh ,[] ,'ObjectHandles');
ispatch = arrow_defcheck(ispatch ,defispatch ,'' );
% check transpose on arguments
[m,n]=size(start ); if any(m==[2 3])&(n==1|n>3), start = start'; end;
[m,n]=size(stop ); if any(m==[2 3])&(n==1|n>3), stop = stop'; end;
[m,n]=size(crossdir); if any(m==[2 3])&(n==1|n>3), crossdir = crossdir'; end;
% convert strings to numbers
if ~isempty(ends) & isstr(ends),
endsorig = ends;
[m,n] = size(ends);
col = lower([ends(:,1:min(3,n)) ones(m,max(0,3-n))*' ']);
ends = NaN*ones(m,1);
oo = ones(1,m);
ii=find(all(col'==['non']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*0; end;
ii=find(all(col'==['sto']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*1; end;
ii=find(all(col'==['sta']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*2; end;
ii=find(all(col'==['bot']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*3; end;
if any(isnan(ends)),
ii = min(find(isnan(ends)));
error([upper(mfilename) ' does not recognize ''' deblank(endsorig(ii,:)) ''' as a valid ''Ends'' value.']);
end;
else,
ends = ends(:);
end;
if ~isempty(ispatch) & isstr(ispatch),
col = lower(ispatch(:,1));
patchchar='p'; linechar='l'; defchar=' ';
mask = col~=patchchar & col~=linechar & col~=defchar;
if any(mask),
error([upper(mfilename) ' does not recognize ''' deblank(ispatch(min(find(mask)),:)) ''' as a valid ''Type'' value.']);
end;
ispatch = (col==patchchar)*1 + (col==linechar)*0 + (col==defchar)*defispatch;
else,
ispatch = ispatch(:);
end;
oldh = oldh(:);
% check object handles
if ~all(ishandle(oldh)), error([upper(mfilename) ' got invalid object handles.']); end;
% expand root, figure, and axes handles
if ~isempty(oldh),
ohtype = get(oldh,'Type');
mask = strcmp(ohtype,'root') | strcmp(ohtype,'figure') | strcmp(ohtype,'axes');
if any(mask),
oldh = num2cell(oldh);
for ii=find(mask)',
oldh(ii) = {findobj(oldh{ii},'Tag',ArrowTag)};
end;
oldh = cat(1,oldh{:});
if isempty(oldh), return; end; % no arrows to modify, so just leave
end;
end;
% largest argument length
[mstart,junk]=size(start); [mstop,junk]=size(stop); [mcrossdir,junk]=size(crossdir);
argsizes = [length(oldh) mstart mstop ...
length(len) length(baseangle) length(tipangle) ...
length(wid) length(page) mcrossdir length(ends) ];
args=['length(ObjectHandle) '; ...
'#rows(Start) '; ...
'#rows(Stop) '; ...
'length(Length) '; ...
'length(BaseAngle) '; ...
'length(TipAngle) '; ...
'length(Width) '; ...
'length(Page) '; ...
'#rows(CrossDir) '; ...
'#rows(Ends) '];
if (any(imag(crossdir(:))~=0)),
args(9,:) = '#rows(NormalDir) ';
end;
if isempty(oldh),
narrows = max(argsizes);
else,
narrows = length(oldh);
end;
if (narrows<=0), narrows=1; end;
% Check size of arguments
ii = find((argsizes~=0)&(argsizes~=1)&(argsizes~=narrows));
if ~isempty(ii),
s = args(ii',:);
while ((size(s,2)>1)&((abs(s(:,size(s,2)))==0)|(abs(s(:,size(s,2)))==abs(' ')))),
s = s(:,1:size(s,2)-1);
end;
s = [ones(length(ii),1)*[upper(mfilename) ' requires that '] s ...
ones(length(ii),1)*[' equal the # of arrows (' num2str(narrows) ').' c]];
s = s';
s = s(:)';
s = s(1:length(s)-1);
error(setstr(s));
end;
% check element length in Start, Stop, and CrossDir
if ~isempty(start),
[m,n] = size(start);
if (n==2),
start = [start NaN*ones(m,1)];
elseif (n~=3),
error([upper(mfilename) ' requires 2- or 3-element Start points.']);
end;
end;
if ~isempty(stop),
[m,n] = size(stop);
if (n==2),
stop = [stop NaN*ones(m,1)];
elseif (n~=3),
error([upper(mfilename) ' requires 2- or 3-element Stop points.']);
end;
end;
if ~isempty(crossdir),
[m,n] = size(crossdir);
if (n<3),
crossdir = [crossdir NaN*ones(m,3-n)];
elseif (n~=3),
if (all(imag(crossdir(:))==0)),
error([upper(mfilename) ' requires 2- or 3-element CrossDir vectors.']);
else,
error([upper(mfilename) ' requires 2- or 3-element NormalDir vectors.']);
end;
end;
end;
% fill empty arguments
if isempty(start ), start = [Inf Inf Inf]; end;
if isempty(stop ), stop = [Inf Inf Inf]; end;
if isempty(len ), len = Inf; end;
if isempty(baseangle ), baseangle = Inf; end;
if isempty(tipangle ), tipangle = Inf; end;
if isempty(wid ), wid = Inf; end;
if isempty(page ), page = Inf; end;
if isempty(crossdir ), crossdir = [Inf Inf Inf]; end;
if isempty(ends ), ends = Inf; end;
if isempty(ispatch ), ispatch = Inf; end;
% expand single-column arguments
o = ones(narrows,1);
if (size(start ,1)==1), start = o * start ; end;
if (size(stop ,1)==1), stop = o * stop ; end;
if (length(len )==1), len = o * len ; end;
if (length(baseangle )==1), baseangle = o * baseangle ; end;
if (length(tipangle )==1), tipangle = o * tipangle ; end;
if (length(wid )==1), wid = o * wid ; end;
if (length(page )==1), page = o * page ; end;
if (size(crossdir ,1)==1), crossdir = o * crossdir ; end;
if (length(ends )==1), ends = o * ends ; end;
if (length(ispatch )==1), ispatch = o * ispatch ; end;
ax = o * gca;
% if we've got handles, get the defaults from the handles
if ~isempty(oldh),
for k=1:narrows,
oh = oldh(k);
ud = get(oh,'UserData');
ax(k) = get(oh,'Parent');
ohtype = get(oh,'Type');
if strcmp(get(oh,'Tag'),ArrowTag), % if it's an arrow already
if isinf(ispatch(k)), ispatch(k)=strcmp(ohtype,'patch'); end;
% arrow UserData format: [start' stop' len base tip wid page crossdir' ends]
start0 = ud(1:3);
stop0 = ud(4:6);
if (isinf(len(k))), len(k) = ud( 7); end;
if (isinf(baseangle(k))), baseangle(k) = ud( 8); end;
if (isinf(tipangle(k))), tipangle(k) = ud( 9); end;
if (isinf(wid(k))), wid(k) = ud(10); end;
if (isinf(page(k))), page(k) = ud(11); end;
if (isinf(crossdir(k,1))), crossdir(k,1) = ud(12); end;
if (isinf(crossdir(k,2))), crossdir(k,2) = ud(13); end;
if (isinf(crossdir(k,3))), crossdir(k,3) = ud(14); end;
if (isinf(ends(k))), ends(k) = ud(15); end;
elseif strcmp(ohtype,'line')|strcmp(ohtype,'patch'), % it's a non-arrow line or patch
convLineToPatch = 1; %set to make arrow patches when converting from lines.
if isinf(ispatch(k)), ispatch(k)=convLineToPatch|strcmp(ohtype,'patch'); end;
x=get(oh,'XData'); x=x(~isnan(x(:))); if isempty(x), x=NaN; end;
y=get(oh,'YData'); y=y(~isnan(y(:))); if isempty(y), y=NaN; end;
z=get(oh,'ZData'); z=z(~isnan(z(:))); if isempty(z), z=NaN; end;
start0 = [x(1) y(1) z(1) ];
stop0 = [x(end) y(end) z(end)];
else,
error([upper(mfilename) ' cannot convert ' ohtype ' objects.']);
end;
ii=find(isinf(start(k,:))); if ~isempty(ii), start(k,ii)=start0(ii); end;
ii=find(isinf(stop( k,:))); if ~isempty(ii), stop( k,ii)=stop0( ii); end;
end;
end;
% convert Inf's to NaN's
start( isinf(start )) = NaN;
stop( isinf(stop )) = NaN;
len( isinf(len )) = NaN;
baseangle( isinf(baseangle)) = NaN;
tipangle( isinf(tipangle )) = NaN;
wid( isinf(wid )) = NaN;
page( isinf(page )) = NaN;
crossdir( isinf(crossdir )) = NaN;
ends( isinf(ends )) = NaN;
ispatch( isinf(ispatch )) = NaN;
% set up the UserData data (here so not corrupted by log10's and such)
ud = [start stop len baseangle tipangle wid page crossdir ends];
% Set Page defaults
page = ~isnan(page) & trueornan(page);
% Get axes limits, range, min; correct for aspect ratio and log scale
axm = zeros(3,narrows);
axr = zeros(3,narrows);
axrev = zeros(3,narrows);
ap = zeros(2,narrows);
xyzlog = zeros(3,narrows);
limmin = zeros(2,narrows);
limrange = zeros(2,narrows);
oldaxlims = zeros(narrows,7);
oneax = all(ax==ax(1));
if (oneax),
T = zeros(4,4);
invT = zeros(4,4);
else,
T = zeros(16,narrows);
invT = zeros(16,narrows);
end;
axnotdone = logical(ones(size(ax)));
while (any(axnotdone)),
ii = min(find(axnotdone));
curax = ax(ii);
curpage = page(ii);
% get axes limits and aspect ratio
axl = [get(curax,'XLim'); get(curax,'YLim'); get(curax,'ZLim')];
oldaxlims(min(find(oldaxlims(:,1)==0)),:) = [curax reshape(axl',1,6)];
% get axes size in pixels (points)
u = get(curax,'Units');
axposoldunits = get(curax,'Position');
really_curpage = curpage & strcmp(u,'normalized');
if (really_curpage),
curfig = get(curax,'Parent');
pu = get(curfig,'PaperUnits');
set(curfig,'PaperUnits','points');
pp = get(curfig,'PaperPosition');
set(curfig,'PaperUnits',pu);
set(curax,'Units','pixels');
curapscreen = get(curax,'Position');
set(curax,'Units','normalized');
curap = pp.*get(curax,'Position');
else,
set(curax,'Units','pixels');
curapscreen = get(curax,'Position');
curap = curapscreen;
end;
set(curax,'Units',u);
set(curax,'Position',axposoldunits);
% handle non-stretched axes position
str_stretch = { 'DataAspectRatioMode' ; ...
'PlotBoxAspectRatioMode' ; ...
'CameraViewAngleMode' };
str_camera = { 'CameraPositionMode' ; ...
'CameraTargetMode' ; ...
'CameraViewAngleMode' ; ...
'CameraUpVectorMode' };
notstretched = strcmp(get(curax,str_stretch),'manual');
manualcamera = strcmp(get(curax,str_camera),'manual');
if ~arrow_WarpToFill(notstretched,manualcamera,curax),
% give a warning that this has not been thoroughly tested
if 0 & ARROW_STRETCH_WARN,
ARROW_STRETCH_WARN = 0;
strs = {str_stretch{1:2},str_camera{:}};
strs = [char(ones(length(strs),1)*sprintf('\n ')) char(strs)]';
warning([upper(mfilename) ' may not yet work quite right ' ...
'if any of the following are ''manual'':' strs(:).']);
end;
% find the true pixel size of the actual axes
texttmp = text(axl(1,[1 2 2 1 1 2 2 1]), ...
axl(2,[1 1 2 2 1 1 2 2]), ...
axl(3,[1 1 1 1 2 2 2 2]),'');
set(texttmp,'Units','points');
textpos = get(texttmp,'Position');
delete(texttmp);
textpos = cat(1,textpos{:});
textpos = max(textpos(:,1:2)) - min(textpos(:,1:2));
% adjust the axes position
if (really_curpage),
% adjust to printed size
textpos = textpos * min(curap(3:4)./textpos);
curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos];
else,
% adjust for pixel roundoff
textpos = textpos * min(curapscreen(3:4)./textpos);
curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos];
end;
end;
if ARROW_PERSP_WARN & ~strcmp(get(curax,'Projection'),'orthographic'),
ARROW_PERSP_WARN = 0;
warning([upper(mfilename) ' does not yet work right for 3-D perspective projection.']);
end;
% adjust limits for log scale on axes
curxyzlog = [strcmp(get(curax,'XScale'),'log'); ...
strcmp(get(curax,'YScale'),'log'); ...
strcmp(get(curax,'ZScale'),'log')];
if (any(curxyzlog)),
ii = find([curxyzlog;curxyzlog]);
if (any(axl(ii)<=0)),
error([upper(mfilename) ' does not support non-positive limits on log-scaled axes.']);
else,
axl(ii) = log10(axl(ii));
end;
end;
% correct for 'reverse' direction on axes;
curreverse = [strcmp(get(curax,'XDir'),'reverse'); ...
strcmp(get(curax,'YDir'),'reverse'); ...
strcmp(get(curax,'ZDir'),'reverse')];
ii = find(curreverse);
if ~isempty(ii),
axl(ii,[1 2])=-axl(ii,[2 1]);
end;
% compute the range of 2-D values
curT = get(curax,'Xform');
lim = curT*[0 1 0 1 0 1 0 1;0 0 1 1 0 0 1 1;0 0 0 0 1 1 1 1;1 1 1 1 1 1 1 1];
lim = lim(1:2,:)./([1;1]*lim(4,:));
curlimmin = min(lim')';
curlimrange = max(lim')' - curlimmin;
curinvT = inv(curT);
if (~oneax),
curT = curT.';
curinvT = curinvT.';
curT = curT(:);
curinvT = curinvT(:);
end;
% check which arrows to which cur corresponds
ii = find((ax==curax)&(page==curpage));
oo = ones(1,length(ii));
axr(:,ii) = diff(axl')' * oo;
axm(:,ii) = axl(:,1) * oo;
axrev(:,ii) = curreverse * oo;
ap(:,ii) = curap(3:4)' * oo;
xyzlog(:,ii) = curxyzlog * oo;
limmin(:,ii) = curlimmin * oo;
limrange(:,ii) = curlimrange * oo;
if (oneax),
T = curT;
invT = curinvT;
else,
T(:,ii) = curT * oo;
invT(:,ii) = curinvT * oo;
end;
axnotdone(ii) = zeros(1,length(ii));
end;
oldaxlims(oldaxlims(:,1)==0,:)=[];
% correct for log scales
curxyzlog = xyzlog.';
ii = find(curxyzlog(:));
if ~isempty(ii),
start( ii) = real(log10(start( ii)));
stop( ii) = real(log10(stop( ii)));
if (all(imag(crossdir)==0)), % pulled (ii) subscript on crossdir, 12/5/96 eaj
crossdir(ii) = real(log10(crossdir(ii)));
end;
end;
% correct for reverse directions
ii = find(axrev.');
if ~isempty(ii),
start( ii) = -start( ii);
stop( ii) = -stop( ii);
crossdir(ii) = -crossdir(ii);
end;
% transpose start/stop values
start = start.';
stop = stop.';
% take care of defaults, page was done above
ii=find(isnan(start(:) )); if ~isempty(ii), start(ii) = axm(ii)+axr(ii)/2; end;
ii=find(isnan(stop(:) )); if ~isempty(ii), stop(ii) = axm(ii)+axr(ii)/2; end;
ii=find(isnan(crossdir(:) )); if ~isempty(ii), crossdir(ii) = zeros(length(ii),1); end;
ii=find(isnan(len )); if ~isempty(ii), len(ii) = ones(length(ii),1)*deflen; end;
ii=find(isnan(baseangle )); if ~isempty(ii), baseangle(ii) = ones(length(ii),1)*defbaseangle; end;
ii=find(isnan(tipangle )); if ~isempty(ii), tipangle(ii) = ones(length(ii),1)*deftipangle; end;
ii=find(isnan(wid )); if ~isempty(ii), wid(ii) = ones(length(ii),1)*defwid; end;
ii=find(isnan(ends )); if ~isempty(ii), ends(ii) = ones(length(ii),1)*defends; end;
% transpose rest of values
len = len.';
baseangle = baseangle.';
tipangle = tipangle.';
wid = wid.';
page = page.';
crossdir = crossdir.';
ends = ends.';
ax = ax.';
% given x, a 3xN matrix of points in 3-space;
% want to convert to X, the corresponding 4xN 2-space matrix
%
% tmp1=[(x-axm)./axr; ones(1,size(x,1))];
% if (oneax), X=T*tmp1;
% else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
% tmp2=zeros(4,4*N); tmp2(:)=tmp1(:);
% X=zeros(4,N); X(:)=sum(tmp2)'; end;
% X = X ./ (ones(4,1)*X(4,:));
% for all points with start==stop, start=stop-(verysmallvalue)*(up-direction);
ii = find(all(start==stop));
if ~isempty(ii),
% find an arrowdir vertical on screen and perpendicular to viewer
% transform to 2-D
tmp1 = [(stop(:,ii)-axm(:,ii))./axr(:,ii);ones(1,length(ii))];
if (oneax), twoD=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,ii).*tmp1;
tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:);
twoD=zeros(4,length(ii)); twoD(:)=sum(tmp2)'; end;
twoD=twoD./(ones(4,1)*twoD(4,:));
% move the start point down just slightly
tmp1 = twoD + [0;-1/1000;0;0]*(limrange(2,ii)./ap(2,ii));
% transform back to 3-D
if (oneax), threeD=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT(:,ii).*tmp1;
tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:);
threeD=zeros(4,length(ii)); threeD(:)=sum(tmp2)'; end;
start(:,ii) = (threeD(1:3,:)./(ones(3,1)*threeD(4,:))).*axr(:,ii)+axm(:,ii);
end;
% compute along-arrow points
% transform Start points
tmp1=[(start-axm)./axr;ones(1,narrows)];
if (oneax), X0=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
X0=zeros(4,narrows); X0(:)=sum(tmp2)'; end;
X0=X0./(ones(4,1)*X0(4,:));
% transform Stop points
tmp1=[(stop-axm)./axr;ones(1,narrows)];
if (oneax), Xf=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
Xf=zeros(4,narrows); Xf(:)=sum(tmp2)'; end;
Xf=Xf./(ones(4,1)*Xf(4,:));
% compute pixel distance between points
D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*(ap./limrange)).^2));
D = D + (D==0); %eaj new 2/24/98
% compute and modify along-arrow distances
len1 = len;
len2 = len - (len.*tan(tipangle/180*pi)-wid/2).*tan((90-baseangle)/180*pi);
slen0 = zeros(1,narrows);
slen1 = len1 .* ((ends==2)|(ends==3));
slen2 = len2 .* ((ends==2)|(ends==3));
len0 = zeros(1,narrows);
len1 = len1 .* ((ends==1)|(ends==3));
len2 = len2 .* ((ends==1)|(ends==3));
% for no start arrowhead
ii=find((ends==1)&(D<len2));
if ~isempty(ii),
slen0(ii) = D(ii)-len2(ii);
end;
% for no end arrowhead
ii=find((ends==2)&(D<slen2));
if ~isempty(ii),
len0(ii) = D(ii)-slen2(ii);
end;
len1 = len1 + len0;
len2 = len2 + len0;
slen1 = slen1 + slen0;
slen2 = slen2 + slen0;
% note: the division by D below will probably not be accurate if both
% of the following are true:
% 1. the ratio of the line length to the arrowhead
% length is large
% 2. the view is highly perspective.
% compute stoppoints
tmp1=X0.*(ones(4,1)*(len0./D))+Xf.*(ones(4,1)*(1-len0./D));
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
stoppoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
% compute tippoints
tmp1=X0.*(ones(4,1)*(len1./D))+Xf.*(ones(4,1)*(1-len1./D));
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
tippoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
% compute basepoints
tmp1=X0.*(ones(4,1)*(len2./D))+Xf.*(ones(4,1)*(1-len2./D));
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
basepoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
% compute startpoints
tmp1=X0.*(ones(4,1)*(1-slen0./D))+Xf.*(ones(4,1)*(slen0./D));
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
startpoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
% compute stippoints
tmp1=X0.*(ones(4,1)*(1-slen1./D))+Xf.*(ones(4,1)*(slen1./D));
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
stippoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
% compute sbasepoints
tmp1=X0.*(ones(4,1)*(1-slen2./D))+Xf.*(ones(4,1)*(slen2./D));
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
sbasepoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
% compute cross-arrow directions for arrows with NormalDir specified
if (any(imag(crossdir(:))~=0)),
ii = find(any(imag(crossdir)~=0));
crossdir(:,ii) = cross((stop(:,ii)-start(:,ii))./axr(:,ii), ...
imag(crossdir(:,ii))).*axr(:,ii);
end;
% compute cross-arrow directions
basecross = crossdir + basepoint;
tipcross = crossdir + tippoint;
sbasecross = crossdir + sbasepoint;
stipcross = crossdir + stippoint;
ii = find(all(crossdir==0)|any(isnan(crossdir)));
if ~isempty(ii),
numii = length(ii);
% transform start points
tmp1 = [basepoint(:,ii) tippoint(:,ii) sbasepoint(:,ii) stippoint(:,ii)];
tmp1 = (tmp1-axm(:,[ii ii ii ii])) ./ axr(:,[ii ii ii ii]);
tmp1 = [tmp1; ones(1,4*numii)];
if (oneax), X0=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,[ii ii ii ii]).*tmp1;
tmp2=zeros(4,16*numii); tmp2(:)=tmp1(:);
X0=zeros(4,4*numii); X0(:)=sum(tmp2)'; end;
X0=X0./(ones(4,1)*X0(4,:));
% transform stop points
tmp1 = [(2*stop(:,ii)-start(:,ii)-axm(:,ii))./axr(:,ii);ones(1,numii)];
tmp1 = [tmp1 tmp1 tmp1 tmp1];
if (oneax), Xf=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,[ii ii ii ii]).*tmp1;
tmp2=zeros(4,16*numii); tmp2(:)=tmp1(:);
Xf=zeros(4,4*numii); Xf(:)=sum(tmp2)'; end;
Xf=Xf./(ones(4,1)*Xf(4,:));
% compute perpendicular directions
pixfact = ((limrange(1,ii)./limrange(2,ii)).*(ap(2,ii)./ap(1,ii))).^2;
pixfact = [pixfact pixfact pixfact pixfact];
pixfact = [pixfact;1./pixfact];
[dummyval,jj] = max(abs(Xf(1:2,:)-X0(1:2,:)));
jj1 = ((1:4)'*ones(1,length(jj))==ones(4,1)*jj);
jj2 = ((1:4)'*ones(1,length(jj))==ones(4,1)*(3-jj));
jj3 = jj1(1:2,:);
Xf(jj1)=Xf(jj1)+(Xf(jj1)-X0(jj1)==0); %eaj new 2/24/98
Xp = X0;
Xp(jj2) = X0(jj2) + ones(sum(jj2(:)),1);
Xp(jj1) = X0(jj1) - (Xf(jj2)-X0(jj2))./(Xf(jj1)-X0(jj1)) .* pixfact(jj3);
% inverse transform the cross points
if (oneax), Xp=invT*Xp;
else, tmp1=[Xp;Xp;Xp;Xp]; tmp1=invT(:,[ii ii ii ii]).*tmp1;
tmp2=zeros(4,16*numii); tmp2(:)=tmp1(:);
Xp=zeros(4,4*numii); Xp(:)=sum(tmp2)'; end;
Xp=(Xp(1:3,:)./(ones(3,1)*Xp(4,:))).*axr(:,[ii ii ii ii])+axm(:,[ii ii ii ii]);
basecross(:,ii) = Xp(:,0*numii+(1:numii));
tipcross(:,ii) = Xp(:,1*numii+(1:numii));
sbasecross(:,ii) = Xp(:,2*numii+(1:numii));
stipcross(:,ii) = Xp(:,3*numii+(1:numii));
end;
% compute all points
% compute start points
axm11 = [axm axm axm axm axm axm axm axm axm axm axm];
axr11 = [axr axr axr axr axr axr axr axr axr axr axr];
st = [stoppoint tippoint basepoint sbasepoint stippoint startpoint stippoint sbasepoint basepoint tippoint stoppoint];
tmp1 = (st - axm11) ./ axr11;
tmp1 = [tmp1; ones(1,size(tmp1,2))];
if (oneax), X0=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=[T T T T T T T T T T T].*tmp1;
tmp2=zeros(4,44*narrows); tmp2(:)=tmp1(:);
X0=zeros(4,11*narrows); X0(:)=sum(tmp2)'; end;
X0=X0./(ones(4,1)*X0(4,:));
% compute stop points
tmp1 = ([start tipcross basecross sbasecross stipcross stop stipcross sbasecross basecross tipcross start] ...
- axm11) ./ axr11;
tmp1 = [tmp1; ones(1,size(tmp1,2))];
if (oneax), Xf=T*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=[T T T T T T T T T T T].*tmp1;
tmp2=zeros(4,44*narrows); tmp2(:)=tmp1(:);
Xf=zeros(4,11*narrows); Xf(:)=sum(tmp2)'; end;
Xf=Xf./(ones(4,1)*Xf(4,:));
% compute lengths
len0 = len.*((ends==1)|(ends==3)).*tan(tipangle/180*pi);
slen0 = len.*((ends==2)|(ends==3)).*tan(tipangle/180*pi);
le = [zeros(1,narrows) len0 wid/2 wid/2 slen0 zeros(1,narrows) -slen0 -wid/2 -wid/2 -len0 zeros(1,narrows)];
aprange = ap./limrange;
aprange = [aprange aprange aprange aprange aprange aprange aprange aprange aprange aprange aprange];
D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*aprange).^2));
Dii=find(D==0); if ~isempty(Dii), D=D+(D==0); le(Dii)=zeros(1,length(Dii)); end; %should fix DivideByZero warnings
tmp1 = X0.*(ones(4,1)*(1-le./D)) + Xf.*(ones(4,1)*(le./D));
% inverse transform
if (oneax), tmp3=invT*tmp1;
else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=[invT invT invT invT invT invT invT invT invT invT invT].*tmp1;
tmp2=zeros(4,44*narrows); tmp2(:)=tmp1(:);
tmp3=zeros(4,11*narrows); tmp3(:)=sum(tmp2)'; end;
pts = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)) .* axr11 + axm11;
% correct for ones where the crossdir was specified
ii = find(~(all(crossdir==0)|any(isnan(crossdir))));
if ~isempty(ii),
D1 = [pts(:,1*narrows+ii)-pts(:,9*narrows+ii) ...
pts(:,2*narrows+ii)-pts(:,8*narrows+ii) ...
pts(:,3*narrows+ii)-pts(:,7*narrows+ii) ...
pts(:,4*narrows+ii)-pts(:,6*narrows+ii) ...
pts(:,6*narrows+ii)-pts(:,4*narrows+ii) ...
pts(:,7*narrows+ii)-pts(:,3*narrows+ii) ...
pts(:,8*narrows+ii)-pts(:,2*narrows+ii) ...
pts(:,9*narrows+ii)-pts(:,1*narrows+ii)]/2;
ii = ii'*ones(1,8) + ones(length(ii),1)*[1:4 6:9]*narrows;
ii = ii(:)';
pts(:,ii) = st(:,ii) + D1;
end;
% readjust for reverse directions
iicols=(1:narrows)'; iicols=iicols(:,ones(1,11)); iicols=iicols(:).';
tmp1=axrev(:,iicols);
ii = find(tmp1(:)); if ~isempty(ii), pts(ii)=-pts(ii); end;
% readjust for log scale on axes
tmp1=xyzlog(:,iicols);
ii = find(tmp1(:)); if ~isempty(ii), pts(ii)=10.^pts(ii); end;
% compute the x,y,z coordinates of the patches;
ii = narrows*(0:10)'*ones(1,narrows) + ones(11,1)*(1:narrows);
ii = ii(:)';
x = zeros(11,narrows);
y = zeros(11,narrows);
z = zeros(11,narrows);
x(:) = pts(1,ii)';
y(:) = pts(2,ii)';
z(:) = pts(3,ii)';
% do the output
if (nargout<=1),
% % create or modify the patches
newpatch = trueornan(ispatch) & (isempty(oldh)|~strcmp(get(oldh,'Type'),'patch'));
newline = ~trueornan(ispatch) & (isempty(oldh)|~strcmp(get(oldh,'Type'),'line'));
if isempty(oldh), H=zeros(narrows,1); else, H=oldh; end;
% % make or modify the arrows
for k=1:narrows,
if all(isnan(ud(k,[3 6])))&arrow_is2DXY(ax(k)), zz=[]; else, zz=z(:,k); end;
xx=x(:,k); yy=y(:,k);
if (0), % this fix didn't work, so let's not use it -- 8/26/03
% try to work around a MATLAB 6.x OpenGL bug -- 7/28/02
mask=any([ones(1,2+size(zz,2));diff([xx yy zz],[],1)],2);
xx=xx(mask); yy=yy(mask); if ~isempty(zz), zz=zz(mask); end;
end;
% plot the patch or line
xyz = {'XData',xx,'YData',yy,'ZData',zz,'Tag',ArrowTag};
if newpatch(k)|newline(k),
if newpatch(k),
H(k) = patch(xyz{:});
else,
H(k) = line(xyz{:});
end;
if ~isempty(oldh), arrow_copyprops(oldh(k),H(k)); end;
else,
if ispatch(k), xyz={xyz{:},'CData',[]}; end;
set(H(k),xyz{:});
end;
end;
if ~isempty(oldh), delete(oldh(oldh~=H)); end;
% % additional properties
set(H,'Clipping','off');
set(H,{'UserData'},num2cell(ud,2));
if (length(extraprops)>0), set(H,extraprops{:}); end;
% handle choosing arrow Start and/or Stop locations if unspecified
[H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims);
if ~isempty(errstr), error([upper(mfilename) ' got ' errstr]); end;
% set the output
if (nargout>0), h=H; end;
% make sure the axis limits did not change
if isempty(oldaxlims),
ARROW_AXLIMITS = [];
else,
lims = get(oldaxlims(:,1),{'XLim','YLim','ZLim'})';
lims = reshape(cat(2,lims{:}),6,size(lims,2));
mask = arrow_is2DXY(oldaxlims(:,1));
oldaxlims(mask,6:7) = lims(5:6,mask)';
ARROW_AXLIMITS = oldaxlims(find(any(oldaxlims(:,2:7)'~=lims)),:);
if ~isempty(ARROW_AXLIMITS),
warning(arrow_warnlimits(ARROW_AXLIMITS,narrows));
end;
end;
else,
% don't create the patch, just return the data
h=x;
yy=y;
zz=z;
end;
function out = arrow_defcheck(in,def,prop)
% check if we got 'default' values
out = in;
if ~isstr(in), return; end;
if size(in,1)==1 & strncmp(lower(in),'def',3),
out = def;
elseif ~isempty(prop),
error([upper(mfilename) ' does not recognize ''' in(:)' ''' as a valid ''' prop ''' string.']);
end;
function [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims)
% handle choosing arrow Start and/or Stop locations if necessary
errstr = '';
if isempty(H)|isempty(ud)|isempty(x), return; end;
% determine which (if any) need Start and/or Stop
needStart = all(isnan(ud(:,1:3)'))';
needStop = all(isnan(ud(:,4:6)'))';
mask = any(needStart|needStop);
if ~any(mask), return; end;
ud(~mask,:)=[]; ax(:,~mask)=[];
x(:,~mask)=[]; y(:,~mask)=[]; z(:,~mask)=[];
% make them invisible for the time being
set(H,'Visible','off');
% save the current axes and limits modes; set to manual for the time being
oldAx = gca;
limModes=get(ax(:),{'XLimMode','YLimMode','ZLimMode'});
set(ax(:),{'XLimMode','YLimMode','ZLimMode'},{'manual','manual','manual'});
% loop over each arrow that requires attention
jj = find(mask);
for ii=1:length(jj),
h = H(jj(ii));
axes(ax(ii));
% figure out correct call
if needStart(ii), prop='Start'; else, prop='Stop'; end;
[wasInterrupted,errstr] = arrow_click(needStart(ii)&needStop(ii),h,prop,ax(ii));
% handle errors and control-C
if wasInterrupted,
delete(H(jj(ii:end)));
H(jj(ii:end))=[];
oldaxlims(jj(ii:end),:)=[];
break;
end;
end;
% restore the axes and limit modes
axes(oldAx);
set(ax(:),{'XLimMode','YLimMode','ZLimMode'},limModes);
function [wasInterrupted,errstr] = arrow_click(lockStart,H,prop,ax)
% handle the clicks for one arrow
fig = get(ax,'Parent');
% save some things
oldFigProps = {'Pointer','WindowButtonMotionFcn','WindowButtonUpFcn'};
oldFigValue = get(fig,oldFigProps);
oldArrowProps = {'EraseMode'};
oldArrowValue = get(H,oldArrowProps);
set(H,'EraseMode','background'); %because 'xor' makes shaft invisible unless Width>1
global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z
ARROW_CLICK_H=H; ARROW_CLICK_PROP=prop; ARROW_CLICK_AX=ax;
ARROW_CLICK_USE_Z=~arrow_is2DXY(ax)|~arrow_planarkids(ax);
set(fig,'Pointer','crosshair');
% set up the WindowButtonMotion so we can see the arrow while moving around
set(fig,'WindowButtonUpFcn','set(gcf,''WindowButtonUpFcn'','''')', ...
'WindowButtonMotionFcn','');
if ~lockStart,
set(H,'Visible','on');
set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']);
end;
% wait for the button to be pressed
[wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig);
% if we wanted to click-drag, set the Start point
if lockStart & ~wasInterrupted,
pt = arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z);
feval(mfilename,H,'Start',pt,'Stop',pt);
set(H,'Visible','on');
ARROW_CLICK_PROP='Stop';
set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']);
% wait for the mouse button to be released
try
waitfor(fig,'WindowButtonUpFcn','');
catch
errstr = lasterr;
wasInterrupted = 1;
end;
end;
if ~wasInterrupted, feval(mfilename,'callback','motion'); end;
% restore some things
set(gcf,oldFigProps,oldFigValue);
set(H,oldArrowProps,oldArrowValue);
function arrow_callback(varargin)
% handle redrawing callbacks
if nargin==0, return; end;
str = varargin{1};
if ~isstr(str), error([upper(mfilename) ' got an invalid Callback command.']); end;
s = lower(str);
if strcmp(s,'motion'),
% motion callback
global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z
feval(mfilename,ARROW_CLICK_H,ARROW_CLICK_PROP,arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z));
drawnow;
else,
error([upper(mfilename) ' does not recognize ''' str(:).' ''' as a valid Callback option.']);
end;
function out = arrow_point(ax,use_z)
% return the point on the given axes
if nargin==0, ax=gca; end;
if nargin<2, use_z=~arrow_is2DXY(ax)|~arrow_planarkids(ax); end;
out = get(ax,'CurrentPoint');
out = out(1,:);
if ~use_z, out=out(1:2); end;
function [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig)
% wait for button down ignoring object ButtonDownFcn's
if nargin==0, fig=gcf; end;
errstr = '';
% save ButtonDownFcn values
objs = findobj(fig);
buttonDownFcns = get(objs,'ButtonDownFcn');
mask=~strcmp(buttonDownFcns,''); objs=objs(mask); buttonDownFcns=buttonDownFcns(mask);
set(objs,'ButtonDownFcn','');
% save other figure values
figProps = {'KeyPressFcn','WindowButtonDownFcn'};
figValue = get(fig,figProps);
% do the real work
set(fig,'KeyPressFcn','set(gcf,''KeyPressFcn'','''',''WindowButtonDownFcn'','''');', ...
'WindowButtonDownFcn','set(gcf,''WindowButtonDownFcn'','''')');
lasterr('');
try
waitfor(fig,'WindowButtonDownFcn','');
wasInterrupted = 0;
catch
wasInterrupted = 1;
end
wasKeyPress = ~wasInterrupted & strcmp(get(fig,'KeyPressFcn'),'');
if wasInterrupted, errstr=lasterr; end;
% restore ButtonDownFcn and other figure values
set(objs,'ButtonDownFcn',buttonDownFcns);
set(fig,figProps,figValue);
function [out,is2D] = arrow_is2DXY(ax)
% check if axes are 2-D X-Y plots
% may not work for modified camera angles, etc.
out = logical(zeros(size(ax))); % 2-D X-Y plots
is2D = out; % any 2-D plots
views = get(ax(:),{'View'});
views = cat(1,views{:});
out(:) = abs(views(:,2))==90;
is2D(:) = out(:) | all(rem(views',90)==0)';
function out = arrow_planarkids(ax)
% check if axes descendents all have empty ZData (lines,patches,surfaces)
out = logical(ones(size(ax)));
allkids = get(ax(:),{'Children'});
for k=1:length(allkids),
kids = get([findobj(allkids{k},'flat','Type','line')
findobj(allkids{k},'flat','Type','patch')
findobj(allkids{k},'flat','Type','surface')],{'ZData'});
for j=1:length(kids),
if ~isempty(kids{j}), out(k)=logical(0); break; end;
end;
end;
function arrow_fixlimits(axlimits)
% reset the axis limits as necessary
if isempty(axlimits), disp([upper(mfilename) ' does not remember any axis limits to reset.']); end;
for k=1:size(axlimits,1),
if any(get(axlimits(k,1),'XLim')~=axlimits(k,2:3)), set(axlimits(k,1),'XLim',axlimits(k,2:3)); end;
if any(get(axlimits(k,1),'YLim')~=axlimits(k,4:5)), set(axlimits(k,1),'YLim',axlimits(k,4:5)); end;
if any(get(axlimits(k,1),'ZLim')~=axlimits(k,6:7)), set(axlimits(k,1),'ZLim',axlimits(k,6:7)); end;
end;
function out = arrow_WarpToFill(notstretched,manualcamera,curax)
% check if we are in "WarpToFill" mode.
out = strcmp(get(curax,'WarpToFill'),'on');
% 'WarpToFill' is undocumented, so may need to replace this by
% out = ~( any(notstretched) & any(manualcamera) );
function out = arrow_warnlimits(axlimits,narrows)
% create a warning message if we've changed the axis limits
msg = '';
switch (size(axlimits,1))
case 1, msg='';
case 2, msg='on two axes ';
otherwise, msg='on several axes ';
end;
msg = [upper(mfilename) ' changed the axis limits ' msg ...
'when adding the arrow'];
if (narrows>1), msg=[msg 's']; end;
out = [msg '.' sprintf('\n') ' Call ' upper(mfilename) ...
' FIXLIMITS to reset them now.'];
function arrow_copyprops(fm,to)
% copy line properties to patches
props = {'EraseMode','LineStyle','LineWidth','Marker','MarkerSize',...
'MarkerEdgeColor','MarkerFaceColor','ButtonDownFcn', ...
'Clipping','DeleteFcn','BusyAction','HandleVisibility', ...
'Selected','SelectionHighlight','Visible'};
lineprops = {'Color', props{:}};
patchprops = {'EdgeColor',props{:}};
patch2props = {'FaceColor',patchprops{:}};
fmpatch = strcmp(get(fm,'Type'),'patch');
topatch = strcmp(get(to,'Type'),'patch');
set(to( fmpatch& topatch),patch2props,get(fm( fmpatch& topatch),patch2props)); %p->p
set(to(~fmpatch&~topatch),lineprops, get(fm(~fmpatch&~topatch),lineprops )); %l->l
set(to( fmpatch&~topatch),lineprops, get(fm( fmpatch&~topatch),patchprops )); %p->l
set(to(~fmpatch& topatch),patchprops, get(fm(~fmpatch& topatch),lineprops) ,'FaceColor','none'); %l->p
function arrow_props
% display further help info about ARROW properties
c = sprintf('\n');
disp([c ...
'ARROW Properties: Default values are given in [square brackets], and other' c ...
' acceptable equivalent property names are in (parenthesis).' c c ...
' Start The starting points. For N arrows, B' c ...
' this should be a Nx2 or Nx3 matrix. /|\ ^' c ...
' Stop The end points. For N arrows, this /|||\ |' c ...
' should be a Nx2 or Nx3 matrix. //|||\\ L|' c ...
' Length Length of the arrowhead (in pixels on ///|||\\\ e|' c ...
' screen, points on a page). [16] (Len) ////|||\\\\ n|' c ...
' BaseAngle Angle (degrees) of the base angle /////|D|\\\\\ g|' c ...
' ADE. For a simple stick arrow, use //// ||| \\\\ t|' c ...
' BaseAngle=TipAngle. [90] (Base) /// ||| \\\ h|' c ...
' TipAngle Angle (degrees) of tip angle ABC. //<----->|| \\ |' c ...
' [16] (Tip) / base ||| \ V' c ...
' Width Width of the base in pixels. Not E angle ||<-------->C' c ...
' the ''LineWidth'' prop. [0] (Wid) |||tipangle' c ...
' Page If provided, non-empty, and not NaN, |||' c ...
' this causes ARROW to use hardcopy |||' c ...
' rather than onscreen proportions. A' c ...
' This is important if screen aspect --> <-- width' c ...
' ratio and hardcopy aspect ratio are ----CrossDir---->' c ...
' vastly different. []' c...
' CrossDir A vector giving the direction towards which the fletches' c ...
' on the arrow should go. [computed such that it is perpen-' c ...
' dicular to both the arrow direction and the view direction' c ...
' (i.e., as if it was pasted on a normal 2-D graph)] (Note' c ...
' that CrossDir is a vector. Also note that if an axis is' c ...
' plotted on a log scale, then the corresponding component' c ...
' of CrossDir must also be set appropriately, i.e., to 1 for' c ...
' no change in that direction, >1 for a positive change, >0' c ...
' and <1 for negative change.)' c ...
' NormalDir A vector normal to the fletch direction (CrossDir is then' c ...
' computed by the vector cross product [Line]x[NormalDir]). []' c ...
' (Note that NormalDir is a vector. Unlike CrossDir,' c ...
' NormalDir is used as is regardless of log-scaled axes.)' c ...
' Ends Set which end has an arrowhead. Valid values are ''none'',' c ...
' ''stop'', ''start'', and ''both''. [''stop''] (End)' c...
' ObjectHandles Vector of handles to previously-created arrows to be' c ...
' updated or line objects to be converted to arrows.' c ...
' [] (Object,Handle)' c ]);
function out = arrow_demo
% demo
% create the data
[x,y,z] = peaks;
[ddd,out.iii]=max(z(:));
out.axlim = [min(x(:)) max(x(:)) min(y(:)) max(y(:)) min(z(:)) max(z(:))];
% modify it by inserting some NaN's
[m,n] = size(z);
m = floor(m/2);
n = floor(n/2);
z(1:m,1:n) = NaN*ones(m,n);
% graph it
clf('reset');
out.hs=surf(x,y,z);
out.x=x; out.y=y; out.z=z;
xlabel('x'); ylabel('y');
function h = arrow_demo3(in)
% set the view
axlim = in.axlim;
axis(axlim);
zlabel('z');
%set(in.hs,'FaceColor','interp');
view(3); % view(viewmtx(-37.5,30,20));
title(['Demo of the capabilities of the ARROW function in 3-D']);
% Normal blue arrow
h1 = feval(mfilename,[axlim(1) axlim(4) 4],[-.8 1.2 4], ...
'EdgeColor','b','FaceColor','b');
% Normal white arrow, clipped by the surface
h2 = feval(mfilename,axlim([1 4 6]),[0 2 4]);
t=text(-2.4,2.7,7.7,'arrow clipped by surf');
% Baseangle<90
h3 = feval(mfilename,[3 .125 3.5],[1.375 0.125 3.5],30,50);
t2=text(3.1,.125,3.5,'local maximum');
% Baseangle<90, fill and edge colors different
h4 = feval(mfilename,axlim(1:2:5)*.5,[0 0 0],36,60,25, ...
'EdgeColor','b','FaceColor','c');
t3=text(axlim(1)*.5,axlim(3)*.5,axlim(5)*.5-.75,'origin');
set(t3,'HorizontalAlignment','center');
% Baseangle>90, black fill
h5 = feval(mfilename,[-2.9 2.9 3],[-1.3 .4 3.2],30,120,[],6, ...
'EdgeColor','r','FaceColor','k','LineWidth',2);
% Baseangle>90, no fill
h6 = feval(mfilename,[-2.9 2.9 1.3],[-1.3 .4 1.5],30,120,[],6, ...
'EdgeColor','r','FaceColor','none','LineWidth',2);
% Stick arrow
h7 = feval(mfilename,[-1.6 -1.65 -6.5],[0 -1.65 -6.5],[],16,16);
t4=text(-1.5,-1.65,-7.25,'global mininum');
set(t4,'HorizontalAlignment','center');
% Normal, black fill
h8 = feval(mfilename,[-1.4 0 -7.2],[-1.4 0 -3],'FaceColor','k');
t5=text(-1.5,0,-7.75,'local minimum');
set(t5,'HorizontalAlignment','center');
% Gray fill, crossdir specified, 'LineStyle' --
h9 = feval(mfilename,[-3 2.2 -6],[-3 2.2 -.05],36,[],27,6,[],[0 -1 0], ...
'EdgeColor','k','FaceColor',.75*[1 1 1],'LineStyle','--');
% a series of normal arrows, linearly spaced, crossdir specified
h10y=(0:4)'/3;
h10 = feval(mfilename,[-3*ones(size(h10y)) h10y -6.5*ones(size(h10y))], ...
[-3*ones(size(h10y)) h10y -.05*ones(size(h10y))], ...
12,[],[],[],[],[0 -1 0]);
% a series of normal arrows, linearly spaced
h11x=(1:.33:2.8)';
h11 = feval(mfilename,[h11x -3*ones(size(h11x)) 6.5*ones(size(h11x))], ...
[h11x -3*ones(size(h11x)) -.05*ones(size(h11x))]);
% series of magenta arrows, radially oriented, crossdir specified
h12x=2; h12y=-3; h12z=axlim(5)/2; h12xr=1; h12zr=h12z; ir=.15;or=.81;
h12t=(0:11)'/6*pi;
h12 = feval(mfilename, ...
[h12x+h12xr*cos(h12t)*ir h12y*ones(size(h12t)) ...
h12z+h12zr*sin(h12t)*ir],[h12x+h12xr*cos(h12t)*or ...
h12y*ones(size(h12t)) h12z+h12zr*sin(h12t)*or], ...
10,[],[],[],[], ...
[-h12xr*sin(h12t) zeros(size(h12t)) h12zr*cos(h12t)],...
'FaceColor','none','EdgeColor','m');
% series of normal arrows, tangentially oriented, crossdir specified
or13=.91; h13t=(0:.5:12)'/6*pi;
locs = [h12x+h12xr*cos(h13t)*or13 h12y*ones(size(h13t)) h12z+h12zr*sin(h13t)*or13];
h13 = feval(mfilename,locs(1:end-1,:),locs(2:end,:),6);
% arrow with no line ==> oriented downwards
h14 = feval(mfilename,[3 3 .100001],[3 3 .1],30);
t6=text(3,3,3.6,'no line'); set(t6,'HorizontalAlignment','center');
% arrow with arrowheads at both ends
h15 = feval(mfilename,[-.5 -3 -3],[1 -3 -3],'Ends','both','FaceColor','g', ...
'Length',20,'Width',3,'CrossDir',[0 0 1],'TipAngle',25);
h=[h1;h2;h3;h4;h5;h6;h7;h8;h9;h10;h11;h12;h13;h14;h15];
function h = arrow_demo2(in)
axlim = in.axlim;
dolog = 1;
if (dolog), set(in.hs,'YData',10.^get(in.hs,'YData')); end;
shading('interp');
view(2);
title(['Demo of the capabilities of the ARROW function in 2-D']);
hold on; [C,H]=contour(in.x,in.y,in.z,20,'-'); hold off;
for k=H',
set(k,'ZData',(axlim(6)+1)*ones(size(get(k,'XData'))),'Color','k');
if (dolog), set(k,'YData',10.^get(k,'YData')); end;
end;
if (dolog), axis([axlim(1:2) 10.^axlim(3:4)]); set(gca,'YScale','log');
else, axis(axlim(1:4)); end;
% Normal blue arrow
start = [axlim(1) axlim(4) axlim(6)+2];
stop = [in.x(in.iii) in.y(in.iii) axlim(6)+2];
if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end;
h1 = feval(mfilename,start,stop,'EdgeColor','b','FaceColor','b');
% three arrows with varying fill, width, and baseangle
start = [-3 -3 10; -3 -1.5 10; -1.5 -3 10];
stop = [-.03 -.03 10; -.03 -1.5 10; -1.5 -.03 10];
if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end;
h2 = feval(mfilename,start,stop,24,[90;60;120],[],[0;0;4],'Ends',str2mat('both','stop','stop'));
set(h2(2),'EdgeColor',[0 .35 0],'FaceColor',[0 .85 .85]);
set(h2(3),'EdgeColor','r','FaceColor',[1 .5 1]);
h=[h1;h2];
function out = trueornan(x)
if isempty(x),
out=x;
else,
out = isnan(x);
out(~out) = x(~out);
end;
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_ur3.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_ur3.m
| 2,856 |
utf_8
|
adf30ae6a0e9dbce9ac8cbb59ac24e31
|
%MDL_UR5 Create model of Universal Robotics UR3 manipulator
%
% MDL_UR5 is a script that creates the workspace variable ur3 which
% describes the kinematic characteristics of a Universal Robotics UR3 manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr arm along +ve x-axis configuration
%
% Reference::
% - https://www.universal-robots.com/how-tos-and-faqs/faq/ur-faq/actual-center-of-mass-for-robot-17264/
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_ur5, mdl_ur10, mdl_puma560, SerialLink.
% MODEL: Universal Robotics, UR3, 6DOF, standard_DH
% 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 r = mdl_ur3()
deg = pi/180;
% robot length values (metres)
a = [0, -0.24365, -0.21325, 0, 0, 0]';
d = [0.1519, 0, 0, 0.11235, 0.08535, 0.0819]';
alpha = [1.570796327, 0, 0, 1.570796327, -1.570796327, 0]';
theta = zeros(6,1);
DH = [theta d a alpha];
mass = [2, 3.42, 1.26, 0.8, 0.8, 0.35];
center_of_mass = [
0,-0.02, 0
0.13, 0, 0.1157
0.05, 0, 0.0238
0, 0, 0.01
0, 0, 0.01
0, 0, -0.02 ];
% and build a serial link manipulator
% offsets from the table on page 4, "Mico" angles are the passed joint
% angles. "DH Algo" are the result after adding the joint angle offset.
robot = SerialLink(DH, ...
'name', 'UR3', 'manufacturer', 'Universal Robotics');
% add the mass data, no inertia available
links = robot.links;
for i=1:6
links(i).m = mass(i);
links(i).r = center_of_mass(i,:);
end
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'ur3', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles
assignin('caller', 'qr', [180 0 0 0 90 0]*deg); % vertical pose as per Fig 2
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_hyper3d.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_hyper3d.m
| 2,453 |
utf_8
|
0b51edaf018a57987435de79571d823f
|
%MDL_HYPER3D Create model of a hyper redundant 3D manipulator
%
% MDL_HYPER3D is a script that creates the workspace variable h3d which
% describes the kinematic characteristics of a serial link manipulator with
% 10 joints which at zero angles is a straight line in the XY plane.
%
% MDL_HYPER3D(N) as above but creates a manipulator with N joints.
%
% Also define the workspace vectors:
% qz joint angle vector for zero angle configuration
%
% R = MDL_HYPER3D(N) functional form of the above, returns the SerialLink object.
%
% [R,QZ] = MDL_HYPER3D(N) as above but also returns a vector of zero joint angles.
%
% Notes::
% - In the zero configuration joint axes alternate between being parallel
% to the z- and y-axes.
% - A crude snake or elephant trunk robot.
% - The manipulator in default pose is a straight line 1m long.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_hyper2d, mdl_ball, mdl_coil, SerialLink.
% MODEL: hyper redundant, 10DOF, standard_DH
% 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 [r,qq] = mdl_hyper3d(N)
if nargin == 0
N = 10;
end
% create the links
for i=1:N
links(i) = Link([0 0 1/N, pi/2]);
q(i) = 0;
end
% and build a serial link manipulator
robot = SerialLink(links, 'name', 'hyper3d', ...
'plotopt', {'nojoints'});
% place the variables into the global workspace
if nargout == 0
assignin('caller', 'h3d', robot);
assignin('caller', 'qz', q);
elseif nargout == 1
r = robot;
elseif nargout == 2
r = robot;
qq = q;
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_panda.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_panda.m
| 4,184 |
utf_8
|
2921b74bc99d500bced903651c7d0157
|
%MDL_PANDA Create model of Franka-Emika PANDA robot
%
% MDL_PANDA is a script that creates the workspace variable panda which
% describes the kinematic characteristics of a Franka-Emika PANDA manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr arm along +ve x-axis configuration
%
% Reference::
% - http://www.diag.uniroma1.it/~deluca/rob1_en/WrittenExamsRob1/Robotics1_18.01.11.pdf
% - "Dynamic Identification of the Franka Emika Panda Robot With Retrieval of Feasible Parameters Using Penalty-Based Optimization"
% C. Gaz, M. Cognetti, A. Oliva, P. Robuffo Giordano and A. De Luca
% IEEE Robotics and Automation Letters 4(4), pp. 4147-4154, Oct. 2019, doi: 10.1109/LRA.2019.2931248
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_sawyer, SerialLink.
% MODEL: Franka-Emika, PANDA, 7DOF, standard_DH
% Copyright (C) 1993-2018, 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 r = mdl_panda()
deg = pi/180;
mm = 1e-3;
%% Define links (thanks Alex Smith for this code)
L1 = RevoluteMDH('a', 0.0, 'd', 0.333, 'alpha', 0.0, 'qlim', [-2.8973 2.8973], ...
'm', 4.970684, 'r', [3.875e-03 2.081e-03 0], 'I', [7.03370e-01 7.06610e-01 9.11700e-03 -1.39000e-04 1.91690e-02 6.77200e-03], 'G', 1);
L2 = RevoluteMDH('a', 0.0, 'd', 0.0, 'alpha', -pi/2, 'qlim', [-1.7628 1.7628], ...
'm', 0.646926, 'r', [-3.141e-03 -2.872e-02 3.495e-03], 'I', [7.96200e-03 2.81100e-02 2.59950e-02 -3.92500e-03 7.04000e-04 1.02540e-02], 'G', 1);
L3 = RevoluteMDH('a', 0.0, 'd', 0.316, 'alpha', pi/2, 'qlim', [-2.8973 2.8973], ...
'm', 3.228604, 'r', [ 2.7518e-02 3.9252e-02 -6.6502e-02], 'I', [3.72420e-02 3.61550e-02 1.08300e-02 -4.76100e-03 -1.28050e-02 -1.13960e-02], 'G', 1);
L4 = RevoluteMDH('a', 0.0825, 'd', 0.0, 'alpha', pi/2, 'qlim', [-3.0718 -0.0698], ...
'm', 3.587895, 'r', [-5.317e-02 1.04419e-01 2.7454e-02], 'I', [2.58530e-02 1.95520e-02 2.83230e-02 7.79600e-03 8.64100e-03 -1.33200e-03], 'G', 1);
L5 = RevoluteMDH('a', -0.0825, 'd', 0.384, 'alpha', -pi/2, 'qlim', [-2.8973 2.8973], ...
'm', 1.225946, 'r', [-1.1953e-02 4.1065e-02 -3.8437e-02], 'I', [3.55490e-02 2.94740e-02 8.62700e-03 -2.11700e-03 2.29000e-04 -4.03700e-03], 'G', 1);
L6 = RevoluteMDH('a', 0.0, 'd', 0.0, 'alpha', pi/2, 'qlim', [-0.0175 3.7525], ...
'm', 1.666555, 'r', [6.0149e-02 -1.4117e-02 -1.0517e-02], 'I', [1.96400e-03 4.35400e-03 5.43300e-03 1.09000e-04 3.41000e-04 -1.15800e-03], 'G', 1);
L7 = RevoluteMDH('a', 0.088, 'd', 0.107, 'alpha', pi/2, 'qlim', [-2.8973 2.8973], ...
'm', 7.35522e-01, 'r', [1.0517e-02 -4.252e-03 6.1597e-02 ], 'I', [1.25160e-02 1.00270e-02 4.81500e-03 -4.28000e-04 -7.41000e-04 -1.19600e-03], 'G', 1);
%% Create SerialLink object
robot = SerialLink([L1 L2 L3 L4 L5 L6 L7], 'name', 'PANDA', 'manufacturer', 'Franka-Emika', 'tool', transl([0 0 110*mm]));
qv = [0 0 0 -4 0 0 0]*deg;
qr = [0 -90 -90 90 0 -90 90]*deg;
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'panda', robot);
assignin('caller', 'qv', qv); % zero angles
assignin('caller', 'qr', qr);
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_offset6.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_offset6.m
| 2,194 |
utf_8
|
313a23c9bd82f70359a9cc6af980e14c
|
%MDL_OFFSET6 A minimalistic 6DOF robot arm with shoulder offset
%
% MDL_OFFSET6 is a script that creates the workspace variable off6 which
% describes the kinematic characteristics of a simple arm manipulator with
% a spherical wrist and a shoulder offset, using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
%
% Notes::
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_simple6, mdl_puma560, mdl_twolink, SerialLink.
% MODEL: generic, 6DOF, standard_DH
% 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 r = mdl_offset6()
% robot length values (metres)
L1 = 1;
L2 = 1;
O1 = 0;
O2 = 0.2;
O3 = 0;
% and build a serial link manipulator
robot = SerialLink([
Revolute('alpha', -pi/2, 'a', O1, 'd', 0)
Revolute('alpha', 0, 'a', L1, 'd', O2)
Revolute('alpha', pi/2, 'a', L2, 'd', O3)
Revolute('alpha', pi/2, 'a', 0, 'd', 0)
Revolute('alpha', -pi/2, 'a', 0, 'd', 0)
Revolute('alpha', 0, 'a', 0, 'd', 0)
], ...
'name', 'Offset6');
% place the variables into the global workspace
if nargout == 1
r = robot;
elseif nargout == 0
assignin('caller', 'off6', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles, arm up
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_M16.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_M16.m
| 2,668 |
utf_8
|
73dc87ecd65dc4a301c45bd0abe8762c
|
%MDL_M16 Create model of Fanuc M16 manipulator
%
% MDL_M16 is a script that creates the workspace variable m16 which
% describes the kinematic characteristics of a Fanuc M16 manipulator using
% standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr vertical 'READY' configuration
% qd lower arm horizontal as per data sheet
%
% References::
% - "Fanuc M-16iB data sheet", http://www.robots.com/fanuc/m-16ib.
% - "Utilizing the Functional Work Space Evaluation Tool for Assessing a
% System Design and Reconfiguration Alternatives",
% A. Djuric and R. J. Urbanic
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_irb140, mdl_fanuc10l, mdl_motomanHP6, mdl_S4ABB2p8, mdl_puma560, SerialLink.
% MODEL: Fanuc, M16, 6DOF, standard_DH
% 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 r = mdl_m16()
deg = pi/180;
% robot length values (metres)
d1 = 0.524;
a1 = 0.150;
a2 = 0.770;
a3 = -0.100;
d4 = 0.740;
d6 = 0.100;
% DH parameter table
% theta d a alpha
dh = [0 d1 a1 -pi/2
0 0 a2 pi
0 0 a3 pi/2
0 d4 0 -pi/2
0 0 0 pi/2
0 d6 0 pi];
% and build a serial link manipulator
robot = SerialLink(dh, 'name', 'M16', ...
'manufacturer', 'Fanuc');
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'm16', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles
assignin('caller', 'qd', [0 -90 0 0 -180 180]*deg); % data sheet pose, horizontal
assignin('caller', 'qr', [0 -90 90 0 -180 180]*deg); % ready pose, arm up
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_simple6.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_simple6.m
| 2,112 |
utf_8
|
9a12a84c51a8b43ed67a2abcce02a22b
|
%MDL_SIMPLE6 A minimalistic 6DOF robot arm
%
% MDL_SIMPLE6 is a script creates the workspace variable s6 which describes
% the kinematic characteristics of a simple arm manipulator with a
% spherical wrist and no shoulder offset, using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
%
% Notes::
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_offset6, mdl_puma560, SerialLink.
% MODEL: generic, 6DOF, standard_DH
% 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 r = mdl_simple6()
% robot length values (metres)
L1 = 1;
L2 = 1;
% and build a serial link manipulator
robot = SerialLink([
Revolute('alpha', pi/2, 'a', 0, 'd', 0)
Revolute('alpha', 0, 'a', L1, 'd', 0)
Revolute('alpha', -pi/2, 'a', L2, 'd', 0)
Revolute('alpha', -pi/2, 'a', 0, 'd', 0)
Revolute('alpha', pi/2, 'a', 0, 'd', 0)
Revolute('alpha', 0, 'a', 0, 'd', 0)
], ...
'name', 'Simple6');
% place the variables into the global workspace
if nargout == 1
r = robot;
elseif nargout == 0
assignin('caller', 's6', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles, arm up
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_irb140.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_irb140.m
| 2,661 |
utf_8
|
745d238d39c628d1e889e77fe9bdb79a
|
%MDL_IRB140 Create model of ABB IRB 140 manipulator
%
% MDL_IRB140 is a script that creates the workspace variable irb140 which
% describes the kinematic characteristics of an ABB IRB 140 manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr vertical 'READY' configuration
% qd lower arm horizontal as per data sheet
%
% Reference::
% - "IRB 140 data sheet", ABB Robotics.
% - "Utilizing the Functional Work Space Evaluation Tool for Assessing a
% System Design and Reconfiguration Alternatives"
% A. Djuric and R. J. Urbanic
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_fanuc10l, mdl_m16, mdl_motormanHP6, mdl_S4ABB2p8, mdl_puma560, SerialLink.
% MODEL: ABB, IRB140, 6DOF, standard_DH
% 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 r = mdl_irb140()
deg = pi/180;
% robot length values (metres)
d1 = 0.352;
a1 = 0.070;
a2 = 0.360;
d4 = 0.380;
d6 = 0.065;
% DH parameter table
% theta d a alpha
dh = [0 d1 a1 -pi/2
0 0 a2 0
0 0 0 pi/2
0 d4 0 -pi/2
0 0 0 pi/2
0 d6 0 pi/2];
% and build a serial link manipulator
robot = SerialLink(dh, 'name', 'IRB 140', ...
'manufacturer', 'ABB', 'ikine', 'nooffset');
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'irb140', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles
assignin('caller', 'qd', [0 -90 180 0 0 -90]*deg); % data sheet pose, horizontal
assignin('caller', 'qr', [0 -90 90 0 90 -90]*deg); % ready pose, arm up
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_jaco.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_jaco.m
| 2,912 |
utf_8
|
bf104e27b26a59eeb11cbed46a7ee03d
|
%MDL_JACO Create model of Kinova Jaco manipulator
%
% MDL_JACO is a script that creates the workspace variable jaco which
% describes the kinematic characteristics of a Kinova Jaco manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr vertical 'READY' configuration
%
% Reference::
% - "DH Parameters of Jaco" Version 1.0.8, July 25, 2013.
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_mico, mdl_puma560, SerialLink.
% MODEL: Kinova, Jaco, 6DOF, standard_DH
% 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 r = mdl_jaco()
deg = pi/180;
% robot length values (metres)
D1 = 0.2755;
D2 = 0.4100;
D3 = 0.2073;
D4 = 0.0743;
D5 = 0.0743;
D6 = 0.1687;
e2 = 0.0098;
% alternate parameters
aa = 30*deg;
ca = cos(aa);
sa = sin(aa);
c2a = cos(2*aa);
s2a = sin(2*aa);
d4b = D3 + sa/s2a*D4;
d5b = sa/s2a*D4 + sa/s2a*D5;
d6b = sa/s2a*D5 + D6;
% and build a serial link manipulator
% offsets from the table on page 4, "Mico" angles are the passed joint
% angles. "DH Algo" are the result after adding the joint angle offset.
robot = SerialLink([
Revolute('alpha', pi/2, 'a', 0, 'd', D1, 'flip')
Revolute('alpha', pi, 'a', D2, 'd', 0, 'offset', -pi/2)
Revolute('alpha', pi/2, 'a', 0, 'd', -e2, 'offset', pi/2)
Revolute('alpha', 2*aa, 'a', 0, 'd', -d4b)
Revolute('alpha', 2*aa, 'a', 0, 'd', -d5b, 'offset', -pi)
Revolute('alpha', pi, 'a', 0, 'd', -d6b, 'offset', 100*deg)
], ...
'name', 'Jaco', 'manufacturer', 'Kinova');
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'jaco', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles
assignin('caller', 'qr', [270 180 180 0 0 0]*deg); % vertical pose as per Fig 2
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_coil.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_coil.m
| 2,093 |
utf_8
|
e950b9ee64dab23230e15783425d5406
|
%MDL_COIL Create model of a coil manipulator
%
% MDL_COIL creates the workspace variable coil which describes the
% kinematic characteristics of a serial link manipulator with 50 joints
% that folds into a helix shape.
%
% MDL_BALL(N) as above but creates a manipulator with N joints.
%
% Also defines the workspace vectors:
% q joint angle vector for default helical configuration
%
% Reference::
% - "A divide and conquer articulated-body algorithm for parallel O(log(n))
% calculation of rigid body dynamics, Part 2",
% Int. J. Robotics Research, 18(9), pp 876-892.
%
% Notes::
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_ball, SerialLink.
% MODEL: generic, coil, hyper redundant, 50DOF, standard_DH
% 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 r = mdl_coil(N)
if nargin == 0
N = 50;
end
% create the links
for i=1:N
links(i) = Link('d', 0, 'a', 1/N, 'alpha', 5*pi/N);
end
% and build a serial link manipulator
robot = SerialLink(links, 'name', 'coil');
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'coil', robot);
assignin('caller', 'q', 10*pi/N*ones(1,N));
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_ur5.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_ur5.m
| 2,911 |
utf_8
|
b86d09aa65b4a2a4c7071a210c1661cd
|
%MDL_UR5 Create model of Universal Robotics UR5 manipulator
%
% MDL_UR5 is a script that creates the workspace variable ur5 which
% describes the kinematic characteristics of a Universal Robotics UR5 manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr arm along +ve x-axis configuration
%
% Reference::
% - https://www.universal-robots.com/how-tos-and-faqs/faq/ur-faq/actual-center-of-mass-for-robot-17264/
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_ur3, mdl_ur10, mdl_puma560, SerialLink.
% MODEL: Universal Robotics, UR5, 6DOF, standard_DH
% 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 r = mdl_ur5()
deg = pi/180;
% robot length values (metres)
a = [0, -0.42500, -0.39225, 0, 0, 0]';
d = [0.089459, 0, 0, 0.10915, 0.09465, 0.0823]';
alpha = [1.570796327, 0, 0, 1.570796327, -1.570796327, 0]';
theta = zeros(6,1);
DH = [theta d a alpha];
mass = [3.7000, 8.3930, 2.33, 1.2190, 1.2190, 0.1897];
center_of_mass = [
0,-0.02561, 0.00193
0.2125, 0, 0.11336
0.15, 0, 0.0265
0, -0.0018, 0.01634
0, -0.0018, 0.01634
0, 0, -0.001159];
% and build a serial link manipulator
% offsets from the table on page 4, "Mico" angles are the passed joint
% angles. "DH Algo" are the result after adding the joint angle offset.
robot = SerialLink(DH, ...
'name', 'UR5', 'manufacturer', 'Universal Robotics');
% add the mass data, no inertia available
links = robot.links;
for i=1:6
links(i).m = mass(i);
links(i).r = center_of_mass(i,:);
end
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'ur5', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles
assignin('caller', 'qr', [180 0 0 0 90 0]*deg); % vertical pose as per Fig 2
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_mico.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_mico.m
| 3,573 |
utf_8
|
563156da7fc9b980f7ea7f2eefe0d57d
|
%MDL_MICO Create model of Kinova Mico manipulator
%
% MDL_MICO is a script that creates the workspace variable mico which
% describes the kinematic characteristics of a Kinova Mico manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr vertical 'READY' configuration
%
% Reference::
% - "DH Parameters of Mico" Version 1.0.1, August 05, 2013.
% Kinova
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also Revolute, mdl_jaco, mdl_puma560, mdl_twolink, SerialLink.
% MODEL: Kinova, Mico, 6DOF, standard_DH
% 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 r = mdl_mico()
deg = pi/180;
% robot length values (metres) page 4
D1 = 0.2755;
D2 = 0.2900;
D3 = 0.1233;
D4 = 0.0741;
D5 = 0.0741;
D6 = 0.1600;
e2 = 0.0070;
% alternate parameters
aa = 30*deg;
ca = cos(aa);
sa = sin(aa);
c2a = cos(2*aa);
s2a = sin(2*aa);
d4b = D3 + sa/s2a*D4;
d5b = sa/s2a*D4 + sa/s2a*D5;
d6b = sa/s2a*D5 + D6;
% and build a serial link manipulator
% offsets from the table on page 4, "Mico" angles are the passed joint
% angles. "DH Algo" are the result after adding the joint angle offset.
robot = SerialLink([
Revolute('alpha', pi/2, 'a', 0, 'd', D1, 'flip')
Revolute('alpha', pi, 'a', D2, 'd', 0, 'offset', -pi/2)
Revolute('alpha', pi/2, 'a', 0, 'd', -e2, 'offset', pi/2)
Revolute('alpha', 2*aa, 'a', 0, 'd', -d4b)
Revolute('alpha', 2*aa, 'a', 0, 'd', -d5b, 'offset', -pi)
Revolute('alpha', pi, 'a', 0, 'd', -d6b, 'offset', pi/2)
], ...
'name', 'Mico', 'manufacturer', 'Kinova');
%{
% MDH version, no test yet
robot = SerialLink([
Revolute('alpha', 0, 'a', 0, 'd', D1, 'modified', 'flip')
Revolute('alpha', -pi/2, 'a', 0, 'd', 0, 'modified', 'offset', -pi/2)
Revolute('alpha', 0, 'a', D2, 'd', e2, 'modified', 'offset', pi/2)
Revolute('alpha', -pi/2, 'a', 0, 'd', d4b, 'modified')
Revolute('alpha', 2*aa, 'a', 0, 'd', d5b, 'modified', 'offset', -pi)
Revolute('alpha', 2*aa, 'a', 0, 'd', d6b, 'modified', 'offset', pi/2)
], ...
'name', 'Mico', 'manufacturer', 'Kinova');
%}
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'mico', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles, arm up
assignin('caller', 'qr', [270 180 180 0 0 180]*deg); % vertical pose as per Fig 2
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_ur10.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_ur10.m
| 2,890 |
utf_8
|
11ff9e3db6c3032bb4470970e053ab65
|
%MDL_UR10 Create model of Universal Robotics UR10 manipulator
%
% MDL_UR5 is a script that creates the workspace variable ur10 which
% describes the kinematic characteristics of a Universal Robotics UR10 manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr arm along +ve x-axis configuration
%
% Reference::
% - https://www.universal-robots.com/how-tos-and-faqs/faq/ur-faq/actual-center-of-mass-for-robot-17264/
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_ur3, mdl_ur5, mdl_puma560, SerialLink.
% MODEL: Universal Robotics, UR10, 6DOF, standard_DH
% 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 r = mdl_ur10()
deg = pi/180;
% robot length values (metres)
a = [0, -0.612, -0.5723, 0, 0, 0]';
d = [0.1273, 0, 0, 0.163941, 0.1157, 0.0922]';
alpha = [1.570796327, 0, 0, 1.570796327, -1.570796327, 0]';
theta = zeros(6,1);
DH = [theta d a alpha];
mass = [7.1, 12.7, 4.27, 2.000, 2.000, 0.365];
center_of_mass = [
0.021, 0, 0.027
0.38, 0, 0.158
0.24, 0, 0.068
0.0, 0.007, 0.018
0.0, 0.007, 0.018
0, 0, -0.026 ];
% and build a serial link manipulator
% offsets from the table on page 4, "Mico" angles are the passed joint
% angles. "DH Algo" are the result after adding the joint angle offset.
robot = SerialLink(DH, ...
'name', 'UR10', 'manufacturer', 'Universal Robotics');
% add the mass data, no inertia available
links = robot.links;
for i=1:6
links(i).m = mass(i);
links(i).r = center_of_mass(i,:);
end
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'ur10', robot);
assignin('caller', 'qz', [0 0 0 0 0 0]); % zero angles
assignin('caller', 'qr', [180 0 0 0 90 0]*deg); % vertical pose as per Fig 2
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_sawyer.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_sawyer.m
| 2,512 |
utf_8
|
3505a00351cb03e2c2c617d54aa358e9
|
%MDL_SAWYER Create model of Rethink Robotics Sawyer robot
%
% MDL_SAYWER is a script that creates the workspace variable sawyer which
% describes the kinematic characteristics of a Rethink Robotics Sawyer manipulator
% using standard DH conventions.
%
% Also define the workspace vectors:
% qz zero joint angle configuration
% qr arm along +ve x-axis configuration
%
% Reference::
% - https://sites.google.com/site/daniellayeghi/daily-work-and-writing/major-project-2
%
% Notes::
% - SI units of metres are used.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_baxter, SerialLink.
% MODEL: Rethink Robotics, Sawyer, 7DOF, standard_DH
% Copyright (C) 1993-2018, 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 r = mdl_sawyer()
deg = pi/180;
mm = 1e-3;
% robot length values (metres)
d = [81 0 0 0 0 0 0]'*mm;
a = [317 192.5 400 168.5 400 136.3 133.75]'*mm;
alpha = [-pi/2 -pi/2 -pi/2 -pi/2 -pi/2 -pi/2 0]';
theta = zeros(7,1);
DH = [theta d a alpha];
% and build a serial link manipulator
% offsets from the table on page 4, "Mico" angles are the passed joint
% angles. "DH Algo" are the result after adding the joint angle offset.
qz = [0 0 0 0 0 0 0];
qr = [0 270 0 180 0 180 270]*deg;
robot = SerialLink(DH, ...
'configs', {'qz', qz, 'qr', qr}, ...
'name', 'Sawyer', 'manufacturer', 'Rethink Robotics');
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'sawyer', robot);
assignin('caller', 'qz', qz); % zero angles
assignin('caller', 'qr', qr);
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_hyper2d.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_hyper2d.m
| 2,321 |
utf_8
|
4e99a45a15c4a444ea67a5279b6d9513
|
%MDL_HYPER2D Create model of a hyper redundant planar manipulator
%
% MDL_HYPER2D creates the workspace variable h2d which describes the
% kinematic characteristics of a serial link manipulator with 10 joints
% which at zero angles is a straight line in the XY plane.
%
% MDL_HYPER2D(N) as above but creates a manipulator with N joints.
%
% Also define the workspace vectors:
% qz joint angle vector for zero angle configuration
%
% R = MDL_HYPER2D(N) functional form of the above, returns the SerialLink object.
%
% [R,QZ] = MDL_HYPER2D(N) as above but also returns a vector of zero joint angles.
%
% Notes::
% - All joint axes are parallel to z-axis.
% - The manipulator in default pose is a straight line 1m long.
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_hyper3d, mdl_coil, mdl_ball, mdl_twolink, SerialLink.
% MODEL: planar, hyper redundant, 10DOF, standard_DH
% 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 [r,qq] = mdl_hyper2d(N)
if nargin == 0
N = 10;
end
% create the links
for i=1:N
links(i) = Link([0 0 1/N, 0]);
q(i) = 0;
end
% and build a serial link manipulator
robot = SerialLink(links, 'name', 'hyper2d');
% place the variables into the global workspace
if nargout == 0
assignin('caller', 'h2d', robot);
assignin('caller', 'qz', q);
elseif nargout == 1
r = robot;
elseif nargout == 2
r = robot;
qq = q;
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mdl_ball.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/models/mdl_ball.m
| 2,377 |
utf_8
|
24984b99a4eeb299735e225c67a81ed2
|
%MDL_BALL Create model of a ball manipulator
%
% MDL_BALL creates the workspace variable ball which describes the
% kinematic characteristics of a serial link manipulator with 50 joints
% that folds into a ball shape.
%
% MDL_BALL(N) as above but creates a manipulator with N joints.
%
% Also define the workspace vectors:
% q joint angle vector for default ball configuration
%
% Reference::
% - "A divide and conquer articulated-body algorithm for parallel O(log(n))
% calculation of rigid body dynamics, Part 2",
% Int. J. Robotics Research, 18(9), pp 876-892.
%
% Notes::
% - Unlike most other mdl_xxx scripts this one is actually a function that
% behaves like a script and writes to the global workspace.
%
% See also mdl_coil, SerialLink.
% MODEL: generic, ball shape, hyper redundant, 50DOF, standard_DH
% 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 r = mdl_ball(N)
if nargin == 0
N = 50;
end
% create the links
for i=1:N
links(i) = Link([0 0 0.1, pi/2]);
q(i) = fract(i);
end
% and build a serial link manipulator
robot = SerialLink(links, 'name', 'ball');
% place the variables into the global workspace
if nargin == 1
r = robot;
elseif nargin == 0
assignin('caller', 'ball', robot);
assignin('caller', 'q', q);
end
end
function f = fract(i)
theta1 = 1;
theta2 = -2/3;
switch mod(i,3)
case 1
f = theta1;
case 2
f = theta2;
case 0
f = fract(i/3);
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
tripleangle.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Apps/tripleangle.m
| 16,728 |
utf_8
|
fe2b05e9e2f40ca331623cf7307f61ec
|
% TRIPLEANGLE Visualize triple angle rotations
%
% TRIPLEANGLE, by itself, displays a simple GUI with three angle sliders
% and a set of axes showing three coordinate frames. The frames correspond
% to rotation after the first angle (red), the first and second angles (green)
% and all three angles (blue).
%
% TRIPLEANGLE(OPTIONS) as above but with options to select the rotation axes.
%
% Options::
% 'rpy' Rotation about axes x, y, z (default)
% 'euler' Rotation about axes z, y, z
% 'ABC' Rotation about axes A, B, C where A,B,C are each one of x,y or z.
%
% Other options relevant to TRPLOT can be appended.
%
% Notes::
% - All angles are displayed in units of degrees.
% - Requires a number of .stl files in the examples folder.
% - Buttons select particular view points.
% - Checkbutton enables display of the gimbals (on by default)
% - This file originally generated by GUIDE.
%
% See also RPY2R, EUL2R, TRPLOT.
% 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 varargout = tripleangle(varargin)
% Last Modified by GUIDE v2.5 19-Aug-2015 15:19:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tripleangle_OpeningFcn, ...
'gui_OutputFcn', @tripleangle_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before tripleang is made visible.
function tripleangle_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to tripleang (see VARARGIN)
% Choose default command line output for tripleang
handles.output = hObject;
figure(handles.figure1);
% process options
opt.wait = false;
opt.which = {'rpy', 'euler'};
[opt,args] = tb_optparse(opt, varargin);
if length(args) > 0 && ischar(args{1})
s = args{1};
try
set(handles.popupmenu1, 'Value', strfind('xyz', s(1)));
set(handles.popupmenu2, 'Value', strfind('xyz', s(2)));
set(handles.popupmenu3, 'Value', strfind('xyz', s(3)));
if length(args) > 1
args = args{2:end};
else
args = {};
end
opt.which = 'none';
catch me
% doesnt match a rotation string, go with 'rpy'
opt.which = 'rpy';
end
end
% set initial slider to axis mapping
switch opt.which
case 'rpy'
set(handles.popupmenu1, 'Value', 3);
set(handles.popupmenu2, 'Value', 2);
set(handles.popupmenu3, 'Value', 1);
case 'euler'
set(handles.popupmenu1, 'Value', 3);
set(handles.popupmenu2, 'Value', 2);
set(handles.popupmenu3, 'Value', 3);
end
% draw the axes at null rotation
%handles.h1 = trplot(eye(3,3), 'color', 'r', args{:});
% set the initial value of text fields
set(handles.text1, 'String', sprintf('%.1f', get(handles.slider1, 'Value')));
set(handles.text2, 'String', sprintf('%.1f', get(handles.slider2, 'Value')));
set(handles.text3, 'String', sprintf('%.1f', get(handles.slider3, 'Value')));
% configure the graphics
axis(1.5*[-1 1 -1 1 -1 1]);
daspect([1 1 1]);
light('Position', [0 0 5]);
light('Position', [2 2 1]);
grid on
xlabel('X')
ylabel('Y');
zlabel('Z');
% establish transforms
handles.plane = hgtransform('Tag', 'plane');
handles.ring1 = hgtransform('Tag', 'ring1');
handles.ring2 = hgtransform('Tag', 'ring2');
handles.ring3 = hgtransform('Tag', 'ring3');
%% load the models
% read the plane model
fprintf('reading STL models...');
[V,F] = stlRead( 'spitfire_assy-gear_up.stl' );
% shift origin to wing centre line
V = bsxfun(@plus, V, [0 0 75]);
patch('Faces', F, 'Vertices', V/180, ...
'FaceColor', 0.8*[1.0000 0.7812 0.4975], 'EdgeAlpha', 0, ...
'Parent', handles.plane);
%% read the gimbal rings
% inner
fprintf('.');
[V,F] = stlRead( 'gimbal-ring1.stl' );
patch('Faces', F, 'Vertices', V*1, ...
'FaceColor', 'b', 'EdgeAlpha', 0, ...
'Parent', handles.ring1);
% middle
fprintf('.');
[V,F] = stlRead( 'gimbal-ring2.stl' );
patch('Faces', F, 'Vertices', V*1.1, ...
'FaceColor', 'g', 'EdgeAlpha', 0, ...
'Parent', handles.ring2);
% outer
fprintf('.');
[V,F] = stlRead( 'gimbal-ring3.stl' );
patch('Faces', F, 'Vertices', V*1.1^2, ...
'FaceColor', 'r', 'EdgeAlpha', 0, ...
'Parent', handles.ring3);
fprintf('\rSupermarine Spitfire Mk VIII by Ed Morley @GRABCAD\n');
fprintf('Gimbal models by Peter Corke using OpenSCAD\n');
% enable mouse-based 3D rotation
rotate3d on
view(50, 22);
% Update handles structure
guidata(hObject, handles);
% ask for continuous callbacks
addlistener(handles.slider1, 'ContinuousValueChange', ...
@(obj,event) slider1_Callback(obj, event, handles) );
addlistener(handles.slider2, 'ContinuousValueChange', ...
@(obj,event) slider2_Callback(obj, event, handles) );
addlistener(handles.slider3, 'ContinuousValueChange', ...
@(obj,event) slider3_Callback(obj, event, handles) );
update(handles)
% UIWAIT makes tripleang wait for user response (see UIRESUME)
if opt.wait
uiwait(handles.figure1);
end
% --- Outputs from this function are returned to the command line.
function varargout = tripleangle_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text1, 'String', sprintf('%.1f', get(hObject, 'Value')));
update(handles);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text2, 'String', sprintf('%.1f', get(hObject, 'Value')));
update(handles);
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider3_Callback(hObject, eventdata, handles)
% hObject handle to slider3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text3, 'String', sprintf('%.1f', get(hObject, 'Value')));
update(handles);
% --- Executes during object creation, after setting all properties.
function slider3_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function update(handles)
% compute the three rotation matrices
R1 = Rx( get(handles.slider1, 'Value'), get(handles.popupmenu1, 'Value'));
R2 = Rx( get(handles.slider2, 'Value'), get(handles.popupmenu2, 'Value'));
R3 = Rx( get(handles.slider3, 'Value'), get(handles.popupmenu3, 'Value'));
% display the three frames
%trplot(R1*R2*R3, 'handle', handles.h1);
set(handles.ring3, 'Matrix', r2t( R1 * roty(pi/2) ));
% Ry
set(handles.ring2, 'Matrix', r2t( R1*R2 * rotz(pi/2) ));
% Rx
set(handles.ring1, 'Matrix', r2t( R1*R2*R3 * rotx(pi/2) ));
set(handles.plane, 'Matrix', r2t( R1*R2*R3 * roty(pi/2)*rotz(pi/2) ))
function R = Rx(theta, which)
theta = theta * pi/180;
switch which
case 1
R = rotx(theta);
case 2
R = roty(theta);
case 3
R = rotz(theta);
end
% --- Executes on button press in pb_RPY.
function pb_RPY_Callback(hObject, eventdata, handles)
% hObject handle to pb_RPY (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.popupmenu1, 'Value', 3);
set(handles.popupmenu2, 'Value', 2);
set(handles.popupmenu3, 'Value', 1);
% --- Executes on button press in pb_euler.
function pb_euler_Callback(hObject, eventdata, handles)
% hObject handle to pb_euler (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.popupmenu1, 'Value', 2);
set(handles.popupmenu2, 'Value', 3);
set(handles.popupmenu3, 'Value', 2);
% --- Executes on button press in pb_top.
function pb_top_Callback(hObject, eventdata, handles)
% hObject handle to pb_top (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
view(90, 90)
% --- Executes on button press in pb_side.
function pb_side_Callback(hObject, eventdata, handles)
% hObject handle to pb_side (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
view(0, 0);
% --- Executes on button press in pb_front.
function pb_front_Callback(hObject, eventdata, handles)
% hObject handle to pb_front (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
view(90, 0);
% --- Executes on button press in pb_reset.
function pb_reset_Callback(hObject, eventdata, handles)
% hObject handle to pb_reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.slider1, 'Value', 0);
set(handles.text1, 'String', sprintf('%.1f', 0));
set(handles.slider2, 'Value', 0);
set(handles.text2, 'String', sprintf('%.1f', 0));
set(handles.slider3, 'Value', 0);
set(handles.text3, 'String', sprintf('%.1f', 0));
update(handles)
view(50, 22);
% --- Executes on button press in gimbals.
function gimbals_Callback(hObject, eventdata, handles)
% hObject handle to gimbals (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of gimbals
if get(hObject,'Value')
set(handles.ring1, 'Visible', 'on');
set(handles.ring2, 'Visible', 'on');
set(handles.ring3, 'Visible', 'on');
else
set(handles.ring1, 'Visible', 'off');
set(handles.ring2, 'Visible', 'off');
set(handles.ring3, 'Visible', 'off');
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
polar_sfunc.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/simulink/polar_sfunc.m
| 4,897 |
utf_8
|
e94a62691fcfd183c87cde7beb3d91ee
|
function movepoint_sfunc(block)
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).Dimensions = 3;
block.InputPort(1).DirectFeedthrough = true;
% Override output port properties
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.OutputPort(1).Dimensions = 4;
block.NumDialogPrms = 0;
% Specify if Accelerator should use TLC or call back into
% M-file
block.SetAccelRunOnTLC(false);
block.SimStateCompliance = 'DefaultSimState';
%block.RegBlockMethod('CheckParameters', @CheckPrms);
%block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
%block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
%block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
%block.RegBlockMethod('SetInputPortDataType', @SetInpPortDataType);
%block.RegBlockMethod('SetOutputPortDataType', @SetOutPortDataType);
%block.RegBlockMethod('SetInputPortComplexSignal', @SetInpPortComplexSig);
%block.RegBlockMethod('SetOutputPortComplexSignal', @SetOutPortComplexSig);
%% PostPropagationSetup:
%% Functionality : Setup work areas and state variables. Can
%% also register run-time methods here
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
%% Register methods called at run-time
%% -----------------------------------------------------------------
%%
%% ProcessParameters:
%% Functionality : Called in order to allow update of run-time
%% parameters
%block.RegBlockMethod('ProcessParameters', @ProcessPrms);
%%
%% InitializeConditions:
%% Functionality : Called in order to initialize state and work
%% area values
%block.RegBlockMethod('InitializeConditions', @InitializeConditions);
%%
%% Start:
%% Functionality : Called in order to initialize state and work
%% area values
block.RegBlockMethod('Start', @Start);
%%
%% Outputs:
%% Functionality : Called to generate block outputs in
%% simulation step
block.RegBlockMethod('Outputs', @Outputs);
%%
%% Update:
%% Functionality : Called to update discrete states
%% during simulation step
%% C-Mex counterpart: mdlUpdate
%%
%block.RegBlockMethod('Update', @Update);
%%
%% Derivatives:
%% Functionality : Called to update derivatives of
%% continuous states during simulation step
%% C-Mex counterpart: mdlDerivatives
%%
%block.RegBlockMethod('Derivatives', @Derivatives);
%%
%% Projection:
%% Functionality : Called to update projections during
%% simulation step
%% C-Mex counterpart: mdlProjections
%%
%block.RegBlockMethod('Projection', @Projection);
%%
%% SimStatusChange:
%% Functionality : Called when simulation goes to pause mode
%% or continnues from pause mode
%% C-Mex counterpart: mdlSimStatusChange
%%
%block.RegBlockMethod('SimStatusChange', @SimStatusChange);
%%
%% Terminate:
%% Functionality : Called at the end of simulation for cleanup
%% C-Mex counterpart: mdlTerminate
%%
%block.RegBlockMethod('Terminate', @Terminate);
%block.RegBlockMethod('WriteRTW', @WriteRTW);
end
function DoPostPropSetup(block)
block.NumDworks = 1;
block.Dwork(1).Name = 'direction';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0;
block.Dwork(1).Complexity = 'Real';
block.Dwork(1).UsedAsDiscState = false;
end
function Start(block)
block.Dwork(1).Data = 0;
end
function Outputs(block)
X = block.InputPort(1).Data;
x = X(1); y = X(2); theta = X(3);
d = sqrt(x^2 + y^2);
if block.Dwork(1).Data == 0
beta = -atan2(-y, -x);
alpha = -theta - beta;
fprintf('alpha %f, beta %f\n', alpha, beta);
% first time in simulation, choose the direction of travel
if (alpha > pi/2) || (alpha < -pi/2)
fprintf('going backwards\n');
block.Dwork(1).Data = -1;
else
fprintf('going forwards\n');
block.Dwork(1).Data = 1;
end
elseif block.Dwork(1).Data == -1
beta = -atan2(y, x);
alpha = -theta - beta;
else
beta = -atan2(-y, -x);
alpha = -theta - beta;
end
if alpha > pi/2
alpha = pi/2;
end
if alpha < -pi/2
alpha = -pi/2;
end
block.OutputPort(1).Data = [d alpha beta block.Dwork(1).Data];
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
slplotbot.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/simulink/slplotbot.m
| 1,828 |
utf_8
|
ba0ac29e746c49ecc04195482e486441
|
%SLPLOTBOT S-function for robot animation
%
% This is the S-function for animating the robot. It assumes input
% data u to be the joint angles q.
%
% Implemented as an S-function so as to update display at the end of
% each Simulink major integration step.
function [sys,x0,str,ts] = splotbot(t,x,u,flag, robot, fps, holdplot)
switch flag
case 0
% initialize the robot graphics
[sys,x0,str,ts] = mdlInitializeSizes(fps); % Init
if ~isempty(robot)
clf
robot.plot(zeros(1, robot.n), 'delay', 0, 'noraise')
end
if holdplot
hold on
end
case 3
% come here on update
if ~isempty(u)
%fprintf('--slplotbot: t=%f\n', t);
robot.animate(u');
drawnow
end
ret = [];
case {1, 2, 4, 9}
ret = [];
end
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(fps)
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 0;
sizes.NumInputs = -1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [-1 0]; %[1.0/fps];
% end mdlInitializeSizes
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
quadrotor_dynamics.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/simulink/quadrotor_dynamics.m
| 9,935 |
utf_8
|
93681b1e292cd9a30d3887f7d7603cc9
|
function [sys,x0,str,ts] = quadrotor_dynamics(t,x,u,flag, quad, x0, groundflag)
% Flyer2dynamics lovingly coded by Paul Pounds, first coded 12/4/04
% A simulation of idealised X-4 Flyer II flight dynamics.
% version 2.0 2005 modified to be compatible with latest version of Matlab
% version 3.0 2006 fixed rotation matrix problem
% version 4.0 4/2/10, fixed rotor flapping rotation matrix bug, mirroring
% version 5.0 8/8/11, simplified and restructured
% version 6.0 25/10/13, fixed rotation matrix/inverse wronskian definitions, flapping cross-product bug
warning off MATLAB:divideByZero
global groundFlag;
% New in version 2:
% - Generalised rotor thrust model
% - Rotor flapping model
% - Frame aerodynamic drag model
% - Frame aerodynamic surfaces model
% - Internal motor model
% - Much coolage
% Version 1.3
% - Rigid body dynamic model
% - Rotor gyroscopic model
% - External motor model
%ARGUMENTS
% u Reference inputs 1x4
% tele Enable telemetry (1 or 0) 1x1
% crash Enable crash detection (1 or 0) 1x1
% init Initial conditions 1x12
%INPUTS
% u = [N S E W]
% NSEW motor commands 1x4
%CONTINUOUS STATES
% z Position 3x1 (x,y,z)
% v Velocity 3x1 (xd,yd,zd)
% n Attitude 3x1 (Y,P,R)
% o Angular velocity 3x1 (wx,wy,wz)
% w Rotor angular velocity 4x1
%
% Notes: z-axis downward so altitude is -z(3)
%CONTINUOUS STATE MATRIX MAPPING
% x = [z1 z2 z3 n1 n2 n3 z1 z2 z3 o1 o2 o3 w1 w2 w3 w4]
%INITIAL CONDITIONS
n0 = [0 0 0]; % n0 Ang. position initial conditions 1x3
v0 = [0 0 0]; % v0 Velocity Initial conditions 1x3
o0 = [0 0 0]; % o0 Ang. velocity initial conditions 1x3
init = [x0 n0 v0 o0]; % x0 is the passed initial position 1x3
groundFlag = groundflag;
%CONTINUOUS STATE EQUATIONS
% z` = v
% v` = g*e3 - (1/m)*T*R*e3
% I*o` = -o X I*o + G + torq
% R = f(n)
% n` = inv(W)*o
% Dispatch the flag.
%
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes(init, quad); % Initialization
case 1
sys = mdlDerivatives(t,x,u, quad); % Calculate derivatives
case 3
sys = mdlOutputs(t,x, quad); % Calculate outputs
case { 2, 4, 9 } % Unused flags
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end
end % End of flyer2dynamics
%==============================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the
% S-function.
%==============================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes(init, quad)
%
% Call simsizes for a sizes structure, fill it in and convert it
% to a sizes array.
%
sizes = simsizes;
sizes.NumContStates = 12;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 12;
sizes.NumInputs = 4;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
%
% Initialize the initial conditions.
x0 = init;
%
% str is an empty matrix.
str = [];
%
% Generic timesample
ts = [0 0];
if quad.verbose
disp(sprintf('t\t\tz1\t\tz2\t\tz3\t\tn1\t\tn2\t\tn3\t\tv1\t\tv2\t\tv3\t\to1\t\to2\t\to3\t\tw1\t\tw2\t\tw3\t\tw4\t\tu1\t\tu2\t\tu3\t\tu4'))
end
end % End of mdlInitializeSizes.
%==============================================================
% mdlDerivatives
% Calculate the state derivatives for the next timestep
%==============================================================
%
function sys = mdlDerivatives(t,x,u, quad)
global a1s b1s groundFlag
%CONSTANTS
%Cardinal Direction Indicies
N = 1; % N 'North' 1x1
E = 2; % S 'South' 1x1
S = 3; % E 'East' 1x1
W = 4; % W 'West' 1x1
D(:,1) = [quad.d;0;quad.h]; % Di Rotor hub displacements 1x3
D(:,2) = [0;quad.d;quad.h];
D(:,3) = [-quad.d;0;quad.h];
D(:,4) = [0;-quad.d;quad.h];
%Body-fixed frame references
e1 = [1;0;0]; % ei Body fixed frame references 3x1
e2 = [0;1;0];
e3 = [0;0;1];
%EXTRACT ROTOR SPEEDS FROM U
w = u(1:4);
%EXTRACT STATES FROM X
z = x(1:3); % position in {W}
n = x(4:6); % RPY angles {W}
v = x(7:9); % velocity in {W}
o = x(10:12); % angular velocity in {W}
%PREPROCESS ROTATION AND WRONSKIAN MATRICIES
phi = n(1); % yaw
the = n(2); % pitch
psi = n(3); % roll
% rotz(phi)*roty(the)*rotx(psi)
R = [cos(the)*cos(phi) sin(psi)*sin(the)*cos(phi)-cos(psi)*sin(phi) cos(psi)*sin(the)*cos(phi)+sin(psi)*sin(phi); %BBF > Inertial rotation matrix
cos(the)*sin(phi) sin(psi)*sin(the)*sin(phi)+cos(psi)*cos(phi) cos(psi)*sin(the)*sin(phi)-sin(psi)*cos(phi);
-sin(the) sin(psi)*cos(the) cos(psi)*cos(the)];
%Manual Construction
% Q3 = [cos(phi) -sin(phi) 0;sin(phi) cos(phi) 0;0 0 1]; % RZ %Rotation mappings
% Q2 = [cos(the) 0 sin(the);0 1 0;-sin(the) 0 cos(the)]; % RY
% Q1 = [1 0 0;0 cos(psi) -sin(psi);0 sin(psi) cos(psi)]; % RX
% R = Q3*Q2*Q1 %Rotation matrix
%
% RZ * RY * RX
iW = [0 sin(psi) cos(psi); %inverted Wronskian
0 cos(psi)*cos(the) -sin(psi)*cos(the);
cos(the) sin(psi)*sin(the) cos(psi)*sin(the)] / cos(the);
if any(w == 0)
% might need to fix this, preculudes aerobatics :(
% mu becomes NaN due to 0/0
error('quadrotor_dynamics: not defined for zero rotor speed');
end
%ROTOR MODEL
for i=[N E S W] %for each rotor
%Relative motion
Vr = cross(o,D(:,i)) + v;
mu = sqrt(sum(Vr(1:2).^2)) / (abs(w(i))*quad.r); %Magnitude of mu, planar components
lc = Vr(3) / (abs(w(i))*quad.r); %Non-dimensionalised normal inflow
li = mu; %Non-dimensionalised induced velocity approximation
alphas = atan2(lc,mu);
j = atan2(Vr(2),Vr(1)); %Sideslip azimuth relative to e1 (zero over nose)
J = [cos(j) -sin(j);
sin(j) cos(j)]; %BBF > mu sideslip rotation matrix
%Flapping
beta = [((8/3*quad.theta0 + 2*quad.theta1)*mu - 2*(lc)*mu)/(1-mu^2/2); %Longitudinal flapping
0;];%sign(w) * (4/3)*((Ct/sigma)*(2*mu*gamma/3/a)/(1+3*e/2/r) + li)/(1+mu^2/2)]; %Lattitudinal flapping (note sign)
beta = J'*beta; %Rotate the beta flapping angles to longitudinal and lateral coordinates.
a1s(i) = beta(1) - 16/quad.gamma/abs(w(i)) * o(2);
b1s(i) = beta(2) - 16/quad.gamma/abs(w(i)) * o(1);
%Forces and torques
T(:,i) = quad.Ct*quad.rho*quad.A*quad.r^2*w(i)^2 * [-cos(b1s(i))*sin(a1s(i)); sin(b1s(i));-cos(a1s(i))*cos(b1s(i))]; %Rotor thrust, linearised angle approximations
Q(:,i) = -quad.Cq*quad.rho*quad.A*quad.r^3*w(i)*abs(w(i)) * e3; %Rotor drag torque - note that this preserves w(i) direction sign
tau(:,i) = cross(T(:,i),D(:,i)); %Torque due to rotor thrust
end
%RIGID BODY DYNAMIC MODEL
dz = v;
dn = iW*o;
dv = quad.g*e3 + R*(1/quad.M)*sum(T,2);
% vehicle can't fall below ground
if groundFlag && (z(3) > 0)
z(3) = 0;
dz(3) = 0;
end
do = inv(quad.J)*(cross(-o,quad.J*o) + sum(tau,2) + sum(Q,2)); %row sum of torques
sys = [dz;dn;dv;do]; %This is the state derivative vector
end % End of mdlDerivatives.
%==============================================================
% mdlOutputs
% Calculate the output vector for this timestep
%==============================================================
%
function sys = mdlOutputs(t,x, quad)
%TELEMETRY
if quad.verbose
disp(sprintf('%0.3f\t',t,x))
end
% compute output vector as a function of state vector
% z Position 3x1 (x,y,z)
% v Velocity 3x1 (xd,yd,zd)
% n Attitude 3x1 (Y,P,R)
% o Angular velocity 3x1 (Yd,Pd,Rd)
n = x(4:6); % RPY angles
phi = n(1); % yaw
the = n(2); % pitch
psi = n(3); % roll
% rotz(phi)*roty(the)*rotx(psi)
R = [cos(the)*cos(phi) sin(psi)*sin(the)*cos(phi)-cos(psi)*sin(phi) cos(psi)*sin(the)*cos(phi)+sin(psi)*sin(phi); %BBF > Inertial rotation matrix
cos(the)*sin(phi) sin(psi)*sin(the)*sin(phi)+cos(psi)*cos(phi) cos(psi)*sin(the)*sin(phi)-sin(psi)*cos(phi);
-sin(the) sin(psi)*cos(the) cos(psi)*cos(the)];
iW = [0 sin(psi) cos(psi); %inverted Wronskian
0 cos(psi)*cos(the) -sin(psi)*cos(the);
cos(the) sin(psi)*sin(the) cos(psi)*sin(the)] / cos(the);
% return velocity in the body frame
sys = [ x(1:6);
inv(R)*x(7:9); % translational velocity mapped to body frame
iW*x(10:12)]; % RPY rates mapped to body frame
%sys = [x(1:6); iW*x(7:9); iW*x(10:12)];
%sys = x;
end
% End of mdlOutputs.
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
quadrotor_plot.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/simulink/quadrotor_plot.m
| 6,817 |
utf_8
|
d45a42badcf21b410b948d7700545049
|
% Copyright (C) 1993-2014, 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/>.
function [sys,x0,str,ts] = quadrotor_plot(t,x,u,flag,s,plot,enable,vehicle)
% Flyer plot, lovingly coded by Paul Pounds, first coded 17/4/02
% version 2 2004 added scaling and ground display
% version 3 2010 improved rotor rendering and fixed mirroring bug
%
% Displays X-4 flyer position and attitude in a 3D plot.
% GREEN ROTOR POINTS NORTH
% BLUE ROTOR POINTS EAST
% PARAMETERS
% s defines the plot size in meters
% swi controls flyer attitude plot; 1 = on, otherwise off.
% INPUTS
% 1 Center X position
% 2 Center Y position
% 3 Center Z position
% 4 Yaw angle in rad
% 5 Pitch angle in rad
% 6 Roll angle in rad
% OUTPUTS
% None
ts = [-1 0];
if ~isfield(vehicle, 'nrotors')
vehicle.nrotors = 4; % sensible default for quadrotor function
end
switch flag
case 0
[sys,x0,str,ts] = mdlInitializeSizes(ts,plot,enable); % Initialization
case 3
sys = mdlOutputs(t,u,s,plot,enable, vehicle); % Calculate outputs
case {1,2, 4, 9} % Unused flags
sys = [];
otherwise
error(['unhandled flag = ',num2str(flag)]); % Error handling
end
% Initialize
function [sys,x0,str,ts] = mdlInitializeSizes(ts,plot,enable)
% Call simsizes for a sizes structure, fill it in, and convert it
% to a sizes array.
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 0;
sizes.NumInputs = 6;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = []; % Set str to an empty matrix.
ts = [0.05 0];
if enable == 1
figure(plot);
clf;
%colordef(1,'none');
%global anim
%anim = Animate('quad-movie');
%TODO enable animation saving from the block
end
% End of mdlInitializeSizes.
function sys = mdlOutputs(t,u,s, plot, enable, quad)
global a1s b1s
% not quite sure what this is about -- PIC
if numel(a1s) == [0];
a1s = zeros(1, quad.nrotors);
b1s = zeros(1, quad.nrotors);
end
% vehicle dimensons
d = quad.d; %Hub displacement from COG
r = quad.r; %Rotor radius
for i = 1:quad.nrotors
theta = (i-1)/quad.nrotors*2*pi;
% Di Rotor hub displacements (1x3)
% first rotor is on the x-axis, clockwise order looking down from above
D(:,i) = [ d*cos(theta); d*sin(theta); 0];
scal = s(1)/4;
%Attitude center displacements
C(:,i) = [ scal*cos(theta); scal*sin(theta); 0];
end
if enable == 1
%draw ground
figure(plot);
clf;
if length(s) == 1
axis([-s s -s s 0 s]);
else
axis([-s(1) s(1) -s(1) s(1) 0 s(2)])
s = s(1);
end
hold on;
% plot the ground boundaries and the big cross
plot3([-s -s],[s -s],[0 0],'-b')
plot3([-s s],[s s],[0 0],'-b')
plot3([s -s],[-s -s],[0 0],'-b')
plot3([s s],[s -s],[0 0],'-b')
plot3([s -s],[-s s],[0 0],'-b')
plot3([-s s],[-s s],[0 0],'-b')
grid on
%READ STATE
z = [u(1);u(2);u(3)];
n = [u(4);u(5);u(6)];
%PREPROCESS ROTATION MATRIX
phi = n(1); %Euler angles
the = n(2);
psi = n(3);
R = [cos(the)*cos(phi) sin(psi)*sin(the)*cos(phi)-cos(psi)*sin(phi) cos(psi)*sin(the)*cos(phi)+sin(psi)*sin(phi); %BBF > Inertial rotation matrix
cos(the)*sin(phi) sin(psi)*sin(the)*sin(phi)+cos(psi)*cos(phi) cos(psi)*sin(the)*sin(phi)-sin(psi)*cos(phi);
-sin(the) sin(psi)*cos(the) cos(psi)*cos(the)];
%Manual Construction
%Q3 = [cos(psi) -sin(psi) 0;sin(psi) cos(psi) 0;0 0 1]; %Rotation mappings
%Q2 = [cos(the) 0 sin(the);0 1 0;-sin(the) 0 cos(the)];
%Q1 = [1 0 0;0 cos(phi) -sin(phi);0 sin(phi) cos(phi)];
%R = Q3*Q2*Q1; %Rotation matrix
%CALCULATE FLYER TIP POSITONS USING COORDINATE FRAME ROTATION
F = [1 0 0;0 -1 0;0 0 -1];
%Draw flyer rotors
t = [0:pi/8:2*pi];
for j = 1:length(t)
circle(:,j) = [r*sin(t(j));r*cos(t(j));0];
end
for i = 1:quad.nrotors
hub(:,i) = F*(z + R*D(:,i)); %points in the inertial frame
q = 1; %Flapping angle scaling for output display - makes it easier to see what flapping is occurring
Rr = [cos(q*a1s(i)) sin(q*b1s(i))*sin(q*a1s(i)) cos(q*b1s(i))*sin(q*a1s(i)); %Rotor > Plot frame
0 cos(q*b1s(i)) -sin(q*b1s(i));
-sin(q*a1s(i)) sin(q*b1s(i))*cos(q*a1s(i)) cos(q*b1s(i))*cos(q*a1s(i))];
tippath(:,:,i) = F*R*Rr*circle;
plot3([hub(1,i)+tippath(1,:,i)],[hub(2,i)+tippath(2,:,i)],[hub(3,i)+tippath(3,:,i)],'b-')
end
%Draw flyer
hub0 = F*z; % centre of vehicle
for i = 1:quad.nrotors
% line from hub to centre plot3([hub(1,N) hub(1,S)],[hub(2,N) hub(2,S)],[hub(3,N) hub(3,S)],'-b')
plot3([hub(1,i) hub0(1)],[hub(2,i) hub0(2)],[hub(3,i) hub0(3)],'-b')
% plot a circle at the hub itself
plot3([hub(1,i)],[hub(2,i)],[hub(3,i)],'o')
end
% plot the vehicle's centroid on the ground plane
plot3([z(1) 0],[-z(2) 0],[0 0],'--k')
plot3([z(1)],[-z(2)],[0],'xk')
% label the axes
xlabel('x');
ylabel('y');
zlabel('z (height above ground)');
view(3)
end
sys = [];
% End of mdlOutputs.
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
nrotor_dynamics.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/simulink/nrotor_dynamics.m
| 10,074 |
utf_8
|
2bf71a487d17cb2635f1e387cbcd02c1
|
function [sys,x0,str,ts] = nrotor_dynamics(t,x,u,flag, vehicle, x0, groundflag)
% Flyer2dynamics lovingly coded by Paul Pounds, first coded 12/4/04
% A simulation of idealised X-4 Flyer II flight dynamics.
% version 2.0 2005 modified to be compatible with latest version of Matlab
% version 3.0 2006 fixed rotation matrix problem
% version 4.0 4/2/10, fixed rotor flapping rotation matrix bug, mirroring
% version 5.0 8/8/11, simplified and restructured
% version 6.0 25/10/13, fixed rotation matrix/inverse wronskian definitions, flapping cross-product bug
% modified by PIC for N rotors
global groundFlag
warning off MATLAB:divideByZero
% New in version 2:
% - Generalised rotor thrust model
% - Rotor flapping model
% - Frame aerodynamic drag model
% - Frame aerodynamic surfaces model
% - Internal motor model
% - Much coolage
% Version 1.3
% - Rigid body dynamic model
% - Rotor gyroscopic model
% - External motor model
%ARGUMENTS
% u Reference inputs 1x4
% tele Enable telemetry (1 or 0) 1x1
% crash Enable crash detection (1 or 0) 1x1
% init Initial conditions 1x12
%INPUTS
% u rotor speed 1xN
%CONTINUOUS STATES
% z Position 3x1 (x,y,z)
% v Velocity 3x1 (xd,yd,zd)
% n Attitude 3x1 (Y,P,R)
% o Angular velocity 3x1 (wx,wy,wz)
% w Rotor angular velocity 4x1
%CONTINUOUS STATE MATRIX MAPPING
% x = [z1 z2 z3 n1 n2 n3 z1 z2 z3 o1 o2 o3 w1 w2 w3 w4]
%INITIAL CONDITIONS
n0 = [0 0 0]; % n0 Ang. position initial conditions 1x3
v0 = [0 0 0]; % v0 Velocity Initial conditions 1x3
o0 = [0 0 0]; % o0 Ang. velocity initial conditions 1x3
init = [x0 n0 v0 o0]; % x0 is the passed initial position 1x3
groundFlag = groundflag;;
%CONTINUOUS STATE EQUATIONS
% z' = v
% v' = g*e3 - (1/m)*T*R*e3
% I*o' = -o X I*o + G + torq
% R = f(n)
% n' = inv(W)*o
% basic sanity checks on number of rotors
if ~isfield(vehicle, 'nrotors')
error('RTB:nrotor_dynamics:bardarg', 'Number of rotors not specified in model structure')
end
if mod(vehicle.nrotors,2) == 1
error('RTB:nrotor_dynamics:bardarg', 'Number of rotors must be even')
end
if vehicle.nrotors < 4
error('RTB:nrotor_dynamics:bardarg', 'Number of rotors must be at least 4')
end
groundFlag = groundflag;
% Dispatch the flag.
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes(init, vehicle); % Initialization
case 1
sys = mdlDerivatives(t,x,u, vehicle); % Calculate derivatives
case 3
sys = mdlOutputs(t,x, vehicle); % Calculate outputs
case { 2, 4, 9 } % Unused flags
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end
end % End of flyer2dynamics
%==============================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the
% S-function.
%==============================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes(init, vehicle)
%
% Call simsizes for a sizes structure, fill it in and convert it
% to a sizes array.
%
sizes = simsizes;
sizes.NumContStates = 12;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 12;
sizes.NumInputs = vehicle.nrotors;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
%
% Initialize the initial conditions.
x0 = init;
%
% str is an empty matrix.
str = [];
%
% Generic timesample
ts = [0 0];
if vehicle.verbose
disp(sprintf('t\t\tz1\t\tz2\t\tz3\t\tn1\t\tn2\t\tn3\t\tv1\t\tv2\t\tv3\t\to1\t\to2\t\to3\t\tw1\t\tw2\t\tw3\t\tw4\t\tu1\t\tu2\t\tu3\t\tu4'))
end
end % End of mdlInitializeSizes.
%==============================================================
% mdlDerivatives
% Calculate the state derivatives for the next timestep
%==============================================================
%
function sys = mdlDerivatives(t,x,u, quad)
global a1s b1s
for i = 1:quad.nrotors
theta = (i-1)/quad.nrotors*2*pi;
% Di Rotor hub displacements (1x3)
% first rotor is on the x-axis, clockwise order looking down from above
D(:,i) = [ quad.d*cos(theta); quad.d*sin(theta); quad.h];
end
%Body-fixed frame references
e1 = [1;0;0]; % ei Body fixed frame references 3x1
e2 = [0;1;0];
e3 = [0;0;1];
%EXTRACT ROTOR SPEED DEMANDS FROM U
w = u(1:quad.nrotors);
%EXTRACT STATES FROM X
z = x(1:3); % position in {W}
n = x(4:6); % RPY angles {W}
v = x(7:9); % velocity in {W}
o = x(10:12); % angular velocity in {W}
%PREPROCESS ROTATION AND WRONSKIAN MATRICIES
phi = n(1); % yaw
the = n(2); % pitch
psi = n(3); % roll
% rotz(phi)*roty(the)*rotx(psi)
R = [cos(the)*cos(phi) sin(psi)*sin(the)*cos(phi)-cos(psi)*sin(phi) cos(psi)*sin(the)*cos(phi)+sin(psi)*sin(phi); %BBF > Inertial rotation matrix
cos(the)*sin(phi) sin(psi)*sin(the)*sin(phi)+cos(psi)*cos(phi) cos(psi)*sin(the)*sin(phi)-sin(psi)*cos(phi);
-sin(the) sin(psi)*cos(the) cos(psi)*cos(the)];
%Manual Construction
% Q3 = [cos(phi) -sin(phi) 0;sin(phi) cos(phi) 0;0 0 1]; % RZ %Rotation mappings
% Q2 = [cos(the) 0 sin(the);0 1 0;-sin(the) 0 cos(the)]; % RY
% Q1 = [1 0 0;0 cos(psi) -sin(psi);0 sin(psi) cos(psi)]; % RX
% R = Q3*Q2*Q1 %Rotation matrix
%
% RZ * RY * RX
iW = [0 sin(psi) cos(psi); %inverted Wronskian
0 cos(psi)*cos(the) -sin(psi)*cos(the);
cos(the) sin(psi)*sin(the) cos(psi)*sin(the)] / cos(the);
%ROTOR MODEL
for i=1:quad.nrotors %for each rotor
%Relative motion
Vr = cross(o,D(:,i)) + v;
mu = sqrt(sum(Vr(1:2).^2)) / (abs(w(i))*quad.r); %Magnitude of mu, planar components
lc = Vr(3) / (abs(w(i))*quad.r); %Non-dimensionalised normal inflow
li = mu; %Non-dimensionalised induced velocity approximation
alphas = atan2(lc,mu);
j = atan2(Vr(2),Vr(1)); %Sideslip azimuth relative to e1 (zero over nose)
J = [cos(j) -sin(j);
sin(j) cos(j)]; %BBF > mu sideslip rotation matrix
%Flapping
beta = [((8/3*quad.theta0 + 2*quad.theta1)*mu - 2*(lc)*mu)/(1-mu^2/2); %Longitudinal flapping
0;];%sign(w) * (4/3)*((Ct/sigma)*(2*mu*gamma/3/a)/(1+3*e/2/r) + li)/(1+mu^2/2)]; %Lattitudinal flapping (note sign)
beta = J'*beta; %Rotate the beta flapping angles to longitudinal and lateral coordinates.
a1s(i) = beta(1) - 16/quad.gamma/abs(w(i)) * o(2);
b1s(i) = beta(2) - 16/quad.gamma/abs(w(i)) * o(1);
%Forces and torques
T(:,i) = quad.Ct*quad.rho*quad.A*quad.r^2*w(i)^2 * [-cos(b1s(i))*sin(a1s(i)); sin(b1s(i));-cos(a1s(i))*cos(b1s(i))]; %Rotor thrust, linearised angle approximations
Q(:,i) = -quad.Cq*quad.rho*quad.A*quad.r^3*w(i)*abs(w(i)) * e3; %Rotor drag torque - note that this preserves w(i) direction sign
tau(:,i) = cross(T(:,i),D(:,i)); %Torque due to rotor thrust
end
%RIGID BODY DYNAMIC MODEL
dz = v;
% vehicle can't fall below ground
if groundFlag && (z(3) > 0)
z(3) = 0;
dz(3) = 0;
end
dn = iW*o;
dv = quad.g*e3 + R*(1/quad.M)*sum(T,2);
do = inv(quad.J)*(cross(-o,quad.J*o) + sum(tau,2) + sum(Q,2)); %row sum of torques
sys = [dz;dn;dv;do]; %This is the state derivative vector
end % End of mdlDerivatives.
%==============================================================
% mdlOutputs
% Calculate the output vector for this timestep
%==============================================================
%
function sys = mdlOutputs(t,x, quad)
%CRASH DETECTION
if x(3)>0
x(3) = 0;
if x(6) > 0
x(6) = 0;
end
end
%if (x(3)>0)&(crash)
% error('CRASH!')
%end
%TELEMETRY
if quad.verbose
disp(sprintf('%0.3f\t',t,x))
end
% compute output vector as a function of state vector
% z Position 3x1 (x,y,z)
% v Velocity 3x1 (xd,yd,zd)
% n Attitude 3x1 (Y,P,R)
% o Angular velocity 3x1 (Yd,Pd,Rd)
n = x(4:6); % RPY angles
phi = n(1); % yaw
the = n(2); % pitch
psi = n(3); % roll
% rotz(phi)*roty(the)*rotx(psi)
R = [cos(the)*cos(phi) sin(psi)*sin(the)*cos(phi)-cos(psi)*sin(phi) cos(psi)*sin(the)*cos(phi)+sin(psi)*sin(phi); %BBF > Inertial rotation matrix
cos(the)*sin(phi) sin(psi)*sin(the)*sin(phi)+cos(psi)*cos(phi) cos(psi)*sin(the)*sin(phi)-sin(psi)*cos(phi);
-sin(the) sin(psi)*cos(the) cos(psi)*cos(the)];
iW = [0 sin(psi) cos(psi); %inverted Wronskian
0 cos(psi)*cos(the) -sin(psi)*cos(the);
cos(the) sin(psi)*sin(the) cos(psi)*sin(the)] / cos(the);
% return velocity in the body frame
sys = [ x(1:6);
inv(R)*x(7:9); % translational velocity mapped to body frame
iW*x(10:12)]; % RPY rates mapped to body frame
%sys = [x(1:6); iW*x(7:9); iW*x(10:12)];
%sys = x;
end
% End of mdlOutputs.
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
slaccel.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/simulink/slaccel.m
| 1,863 |
utf_8
|
b40a5c69f4b536d307e49d1c9a3e0261
|
%SLACCEL S-function for robot acceleration
%
% This is the S-function for computing robot acceleration. It assumes input
% data u to be the vector [q qd tau].
%
% Implemented as an S-function to get around vector sizing problem with
% Simulink 4.
function [sys, x0, str, ts] = slaccel(t, x, u, flag, robot)
switch flag
case 0
% initialize the robot graphics
[sys,x0,str,ts] = mdlInitializeSizes(robot); % Init
case {3}
% come here to calculate derivitives
% first check that the torque vector is sensible
assert(numel(u) == (3*robot.n), 'RTB:slaccel:badarg', 'Input vector is length %d, should be %d', numel(u), 3*robot.n);
assert(isreal(u), 'RTB:slaccel:badarg', 'Input vector is complex, should be real');
sys = robot.accel(u(:)');
case {1, 2, 4, 9}
sys = [];
end
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(robot)
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = robot.n;
sizes.NumInputs = 3*robot.n;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0 0];
% end mdlInitializeSizes
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
SerialLink.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/SerialLink.m
| 3,422 |
utf_8
|
6b79f782cc7245759b17bccc567eadfb
|
%ROBOT robot object constructor
%
% ROBOT
% ROBOT(robot) create a copy of an existing ROBOT object
% ROBOT(LINK, ...) create from a cell array of LINK objects
% ROBOT(DH, ...) create from legacy DYN matrix
% ROBOT(DYN, ...) create from legacy DYN matrix
%
% optional trailing arguments are:
% Name robot type or name
% Manufacturer who built it
% Comment general comment
%
% If the legacy matrix forms are used the default name is the workspace
% variable that held the data.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 r = SerialLink(L, varargin)
r.name = 'noname';
r.manufacturer = '';
r.comment = '';
r.links = [];
r.n = 0;
r.mdh = 0;
r.gravity = [0; 0; 9.81];
r.base = eye(4,4);
r.tool = eye(4,4);
r.handle = []; % graphics handles
r.q = []; % current joint angles
r.lineopt = {'Color', 'black', 'Linewidth', 4};
r.shadowopt = {'Color', 0.7*[1 1 1], 'Linewidth', 3};
r.plotopt = {};
r = class(r, 'SerialLink');
if nargin == 0
%zero argument constructor
return;
else
if isa(L, 'SerialLink')
if length(L) == 1
% clone the passed robot
for j=1:L.n
newlinks(j) = L.links(j);
end
r.links = newlinks;
else
% compound the robots in the vector
r = L(1);
for k=2:length(L)
r = r * L(k);
end
end
elseif isa(L,'Link')
r.links = L; %attach the links
elseif isa(L, 'double')
% legacy matrix
dh_dyn = L;
clear L
for j=1:numrows(dh_dyn)
L(j) = Link();
L(j).theta = dh_dyn(j,1);
L(j).d = dh_dyn(j,2);
L(j).a = dh_dyn(j,3);
L(j).alpha = dh_dyn(j,4);
if numcols(dh_dyn) > 4
L(j).sigma = dh_dyn(j,5);
end
end
r.links = L;
else
error('unknown type passed to SerialLink');
end
r.n = length(r.links);
end
%process the rest of the arguments in key, value pairs
opt.name = 'robot';
opt.comment = [];
opt.manufacturer = [];
opt.base = [];
opt.tool = [];
opt.offset = [];
opt.qlim = [];
opt.plotopt = [];
[opt,out] = tb_optparse(opt, varargin);
if ~isempty(out)
error( sprintf('unknown option <%s>', out{1}));
end
% copy the properties to robot object
p = fieldnames(r);
for i=1:length(p)
if isfield(opt, p{i}) && ~isempty(getfield(opt, p{i}))
r = setfield(r, p{i}, getfield(opt, p{i}));
end
end
% set the robot object mdh status flag
mdh = [r.links.mdh];
if all(mdh == 0)
r.mdh = mdh(1);
elseif all (mdh == 1)
r.mdh = mdh(1);
else
error('SerialLink has mixed D&H links conventions');
end
r = class(r, 'SerialLink');
endfunction
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
showlink.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/showlink.m
| 1,144 |
utf_8
|
c7461e742177bef949f7c9c1f29746a4
|
%SerialLink.showlink Show parameters of all links
%
% R.showlink() shows details of all link parameters for the robot object,
% including inertial parameters.
%
% See also Link.showlink, Link.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 showlink(r)
for i=1:r.n,
fprintf('Link %d------------------------\n', i);
r.links(i).dyn();
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
plot.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/plot.m
| 12,227 |
utf_8
|
a5e1b4b6574996e90a18af55228dd05d
|
%PLOT Graphical robot animation
%
% PLOT(ROBOT, Q)
% PLOT(ROBOT, Q, options)
%
% Displays a graphical animation of a robot based on the
% kinematic model. A stick figure polyline joins the origins of
% the link coordinate frames.
% The robot is displayed at the joint angle Q, or if a matrix it is
% animated as the robot moves along the trajectory.
%
% The graphical robot object holds a copy of the robot object and
% the graphical element is tagged with the robot's name (.name method).
% This state also holds the last joint configuration
% drawn (.q method).
%
% If no robot of this name is currently displayed then a robot will
% be drawn in the current figure. If the robot already exists then
% that graphical model will be found and moved.
%
% MULTIPLE VIEWS OF THE SAME ROBOT
% If one or more plots of this robot already exist then these will all
% be moved according to the argument Q.
%
% MULTIPLE ROBOTS
% Multiple robots can be displayed in the same plot, by using "hold on"
% before calls to plot(robot).
%
% options is a list of any of the following:
% 'workspace' [xmin, xmax ymin ymax zmin zmax]
% 'perspective' 'ortho' controls camera view mode
% 'erase' 'noerase' controls erasure of arm during animation
% 'base' 'nobase' controls display of base 'pedestal'
% 'loop' 'noloop' controls display of base 'pedestal'
% 'wrist' 'nowrist' controls display of wrist
% 'name', 'noname' display the robot's name near the first joint
% 'shadow' 'noshadow' controls display of shadow
% 'xyz' 'noa' wrist axis label
% 'joints' 'nojoints' controls display of joints
% 'mag' scale annotation scale factor
%
% The options come from 3 sources and are processed in the order:
% 1. Cell array of options returned by the function PLOTBOTOPT
% 2. Cell array of options returned by the .plotopt method of the
% robot object. These are set by the .plotopt method.
% 3. List of arguments in the command line.
%
% GRAPHICAL ANNOTATIONS:
%
% The basic stick figure robot can be annotated with
% shadow on the floor
% XYZ wrist axes and labels
% joint cylinders and axes
%
% All of these require some kind of dimension and this is determined
% using a simple heuristic from the workspace dimensions. This dimension
% can be changed by setting the multiplicative scale factor using the
% 'mag' option above.
%
% GETTING GRAPHICAL ROBOT STATE:
% q = PLOT(ROBOT)
% Returns the joint configuration from the state of an existing
% graphical representation of the specified robot. If multiple
% instances exist, that of the first one returned by findobj() is
% given.
%
% See also PLOTBOTOPT, DRIVEBOT, FKINE, ROBOT.
% Copright (C) Peter Corke 1993
% HANDLES:
%
% A robot comprises a bunch of individual graphical elements and these are
% kept in a structure which can be stored within the .handle element of a
% robot object.
% h.robot the robot stick figure
% h.shadow the robot's shadow
% h.x wrist vectors
% h.y
% h.z
% h.xt wrist vector labels
% h.yt
% h.zt
%
% The plot function returns a new robot object with the handle element set.
%
% For the h.robot object we additionally:
% save this new robot object as its UserData
% tag it with the name field from the robot object
%
% This enables us to find all robots with a given name, in all figures,
% and update them.
% MOD.HISTORY
% 12/94 make axis scaling adjust to robot kinematic params
% 4/99 use objects
% 2/01 major rewrite, axis names, drivebot, state etc.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 rnew = plot(robot, tg, varargin)
%
% q = PLOT(robot)
% return joint coordinates from a graphical robot of given name
%
if nargin == 1,
rh = findobj('Tag', robot.name);
if ~isempty(rh),
r = get(rh(1), 'UserData');
rnew = r.q;
end
return
end
np = numrows(tg);
n = robot.n;
if numcols(tg) ~= n,
error('Insufficient columns in q')
end
if ~isfield(robot, 'handles'),
%
% if there are no handles in this object we assume it has
% been invoked from the command line not drivebot() so we
% process the options
%
%%%%%%%%%%%%%% process options
erasemode = 'xor';
joints = 1;
wrist = 1;
repeat = 1;
shadow = 1;
wrist = 1;
dims = [];
base = 0;
wristlabel = 'xyz';
projection = 'orthographic';
magscale = 1;
name = 1;
% read options string in the order
% 1. robot.plotopt
% 2. the M-file plotbotopt if it exists
% 3. command line arguments
if exist('plotbotopt', 'file') == 2,
options = plotbotopt;
options = [options robot.plotopt varargin];
else
options = [robot.plotopt varargin];
end
i = 1;
while i <= length(options),
switch lower(options{i}),
case 'workspace'
dims = options{i+1};
i = i+1;
case 'mag'
magscale = options{i+1};
i = i+1;
case 'perspective'
projection = 'perspective';
case 'ortho'
projection = 'orthographic';
case 'erase'
erasemode = 'xor';
case 'noerase'
erasemode = 'none';
case 'base'
base = 1;
case 'nobase'
base = 0;
case 'loop'
repeat = Inf;
case 'noloop'
repeat = 1;
case 'name',
name = 1;
case 'noname',
name = 0;
case 'wrist'
wrist = 1;
case 'nowrist'
wrist = 0;
case 'shadow'
shadow = 1;
case 'noshadow'
shadow = 0;
case 'xyz'
wristlabel = 'XYZ';
case 'noa'
wristlabel = 'NOA';
case 'joints'
joints = 1;
case 'nojoints'
joints = 0;
otherwise
error(['unknown option: ' options{i}]);
end
i = i+1;
end
if isempty(dims),
%
% simple heuristic to figure the maximum reach of the robot
%
L = robot.links;
reach = 0;
for i=1:n,
reach = reach + abs(L(i).a) + abs(L(i).d);
end
dims = [-reach reach -reach reach -reach reach];
mag = reach/10;
else
reach = min(abs(dims));
end
mag = magscale * reach/10;
end
%
% setup an axis in which to animate the robot
%
if isempty(robot.handle) & isempty(findobj(gcf, 'Tag', robot.name)),
if ~ishold,
clf
axis(dims);
end
figure(gcf); % bring to the top
xlabel('X')
ylabel('Y')
zlabel('Z')
set(gca, 'drawmode', 'fast');
grid on
zlim = get(gca, 'ZLim');
h.zmin = zlim(1);
if base,
b = transl(robot.base);
line('xdata', [b(1);b(1)], ...
'ydata', [b(2);b(2)], ...
'zdata', [h.zmin;b(3)], ...
'LineWidth', 4, ...
'color', 'red');
end
if name,
b = transl(robot.base);
text(b(1), b(2)-mag, [' ' robot.name])
end
% create a line which we will
% subsequently modify. Set erase mode to xor for fast
% update
%
h.robot = line(robot.lineopt{:}, ...
'Erasemode', erasemode);
if shadow == 1,
h.shadow = line(robot.shadowopt{:}, ...
'Erasemode', erasemode);
end
if wrist == 1,
h.x = line('xdata', [0;0], ...
'ydata', [0;0], ...
'zdata', [0;0], ...
'color', 'red', ...
'erasemode', 'xor');
h.y = line('xdata', [0;0], ...
'ydata', [0;0], ...
'zdata', [0;0], ...
'color', 'green', ...
'erasemode', 'xor');
h.z = line('xdata', [0;0], ...
'ydata', [0;0], ...
'zdata', [0;0], ...
'color', 'blue', ...
'erasemode', 'xor');
h.xt = text(0, 0, wristlabel(1), 'FontWeight', 'bold', 'HorizontalAlignment', 'Center');
h.yt = text(0, 0, wristlabel(2), 'FontWeight', 'bold', 'HorizontalAlignment', 'Center');
h.zt = text(0, 0, wristlabel(3), 'FontWeight', 'bold', 'HorizontalAlignment', 'Center');
end
%
% display cylinders (revolute) or boxes (pristmatic) at
% each joint, as well as axis centerline.
%
if joints == 1,
L = robot.links;
for i=1:robot.n,
% cylinder or box to represent the joint
if L(i).sigma == 0,
N = 8;
else
N = 4;
end
[xc,yc,zc] = cylinder([mag/4, mag/4], N);
zc(zc==0) = -mag/2;
zc(zc==1) = mag/2;
% add the surface object and color it
h.joint(i) = surface(xc,yc,zc);
%set(h.joint(i), 'erasemode', 'xor');
set(h.joint(i), 'FaceColor', 'blue');
% build a matrix of coordinates so we
% can transform the cylinder in animate()
% and hang it off the cylinder
xyz = [xc(:)'; yc(:)'; zc(:)'; ones(1,2*N+2)];
set(h.joint(i), 'UserData', xyz);
% add a dashed line along the axis
h.jointaxis(i) = line('xdata', [0;0], ...
'ydata', [0;0], ...
'zdata', [0;0], ...
'color', 'blue', ...
'linestyle', '--', ...
'erasemode', 'xor');
end
end
h.mag = mag;
robot.handle = h;
set(h.robot, 'Tag', robot.name);
set(h.robot, 'UserData', robot);
end
% save the handles in the passed robot object
rh = findobj('Tag', robot.name);
for r=1:repeat,
for p=1:np,
for r=rh',
animate( get(r, 'UserData'), tg(p,:));
end
end
end
% save the last joint angles away in the graphical robot
for r=rh',
rr = get(r, 'UserData');
rr.q = tg(end,:);
set(r, 'UserData', rr);
end
if nargout > 0,
rnew = robot;
end
function animate(robot, q)
n = robot.n;
h = robot.handle;
L = robot.links;
mag = h.mag;
b = transl(robot.base);
x = b(1);
y = b(2);
z = b(3);
xs = b(1);
ys = b(2);
zs = h.zmin;
% compute the link transforms, and record the origin of each frame
% for the animation.
t = robot.base;
Tn = t;
for j=1:n,
Tn(:,:,j) = t;
t = t * L(j).A(q(j));
x = [x; t(1,4)];
y = [y; t(2,4)];
z = [z; t(3,4)];
xs = [xs; t(1,4)];
ys = [ys; t(2,4)];
zs = [zs; h.zmin];
end
t = t *robot.tool;
%
% draw the robot stick figure and the shadow
%
set(h.robot,'xdata', x, 'ydata', y, 'zdata', z);
if isfield(h, 'shadow'),
set(h.shadow,'xdata', xs, 'ydata', ys, 'zdata', zs);
end
%
% display the joints as cylinders with rotation axes
%
if isfield(h, 'joint'),
xyz_line = [0 0; 0 0; -2*mag 2*mag; 1 1];
for j=1:n,
% get coordinate data from the cylinder
xyz = get(h.joint(j), 'UserData');
xyz = Tn(:,:,j) * xyz;
ncols = numcols(xyz)/2;
xc = reshape(xyz(1,:), 2, ncols);
yc = reshape(xyz(2,:), 2, ncols);
zc = reshape(xyz(3,:), 2, ncols);
set(h.joint(j), 'Xdata', xc, 'Ydata', yc, ...
'Zdata', zc);
xyzl = Tn(:,:,j) * xyz_line;
set(h.jointaxis(j), 'Xdata', xyzl(1,:), 'Ydata', xyzl(2,:), 'Zdata', xyzl(3,:));
xyzl = Tn(:,:,j) * xyz_line;
h.jointlabel(j) = text(xyzl(1,1), xyzl(2,1) , xyzl(3,1), num2str(j), 'HorizontalAlignment', 'Center');
end
end
%
% display the wrist axes and labels
%
if isfield(h, 'x'),
%
% compute the wrist axes, based on final link transformation
% plus the tool transformation.
%
xv = t*[mag;0;0;1];
yv = t*[0;mag;0;1];
zv = t*[0;0;mag;1];
%
% update the line segments, wrist axis and links
%
set(h.x,'xdata',[t(1,4) xv(1)], 'ydata', [t(2,4) xv(2)], ...
'zdata', [t(3,4) xv(3)]);
set(h.y,'xdata',[t(1,4) yv(1)], 'ydata', [t(2,4) yv(2)], ...
'zdata', [t(3,4) yv(3)]);
set(h.z,'xdata',[t(1,4) zv(1)], 'ydata', [t(2,4) zv(2)], ...
'zdata', [t(3,4) zv(3)]);
wristlabel = "XYZ";
% text(xv(1),xv(2),xv(3), ['X'])
% text(yv(1),yv(2),yv(3), ['Y'])
% text(zv(1),zv(2),zv(3), ['Z'])
h.xt = text(xv(1),xv(2),xv(3), wristlabel(1), 'FontWeight', 'bold', 'HorizontalAlignment', 'Center');
h.yt = text(yv(1),yv(2),yv(3), wristlabel(2), 'FontWeight', 'bold', 'HorizontalAlignment', 'Center');
h.zt = text(zv(1),zv(2),zv(3), wristlabel(3), 'FontWeight', 'bold', 'HorizontalAlignment', 'Center');
% set(h.zt, 'rotation', zv(1:3));
% set(h.xt, 'Position', xv(1:3));
% set(h.yt, 'Position', yv(1:3));
end
drawnow
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
dyn.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/dyn.m
| 1,207 |
utf_8
|
3c68eba44763c252b2636604f6cd8e84
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 dyn(r)
%SerialLink.dyn Display inertial properties
%
% R.dyn() displays the inertial properties of the SerialLink object in a multi-line
% format. The properties shown are mass, centre of mass, inertia, gear ratio,
% motor inertia and motor friction.
%
% See also Link.dyn.
for j=1:r.n
fprintf('----- link %d\n', j);
l = r.links(j);
l.dyn()
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
rne_dh.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/rne_dh.m
| 4,885 |
utf_8
|
1e44d3260a31a7c4fce5eb34a71c71fc
|
%SERIALLINK.RNE_DH Compute inverse dynamics via recursive Newton-Euler formulation
%
% Recursive Newton-Euler for standard Denavit-Hartenberg notation. Is invoked by
% R.RNE().
%
% See also SERIALLINK.RNE.
%
% verified against MAPLE code, which is verified by examples
%
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 [tau,wbase] = rne_dh(robot, a1, a2, a3, a4, a5)
z0 = [0;0;1];
grav = robot.gravity; % default gravity from the object
fext = zeros(6, 1);
n = robot.n;
% check that robot object has dynamic parameters for each link
for j=1:n,
link = robot.links(j);
if isempty(link.r) || isempty(link.I) || isempty(link.m)
error('dynamic parameters (m, r, I) not set in link %d', j);
end
end
% Set debug to:
% 0 no messages
% 1 display results of forward and backward recursions
% 2 display print R and p*
debug = 0;
if numcols(a1) == 3*n,
Q = a1(:,1:n);
Qd = a1(:,n+1:2*n);
Qdd = a1(:,2*n+1:3*n);
np = numrows(Q);
if nargin >= 3,
grav = a2(:);
end
if nargin == 4,
fext = a3;
end
else
np = numrows(a1);
Q = a1;
Qd = a2;
Qdd = a3;
if numcols(a1) ~= n | numcols(Qd) ~= n | numcols(Qdd) ~= n | ...
numrows(Qd) ~= np | numrows(Qdd) ~= np,
error('bad data');
end
if nargin >= 5,
grav = a4(:);
end
if nargin == 6,
fext = a5;
end
end
tau = zeros(np,n);
for p=1:np,
q = Q(p,:)';
qd = Qd(p,:)';
qdd = Qdd(p,:)';
Fm = [];
Nm = [];
pstarm = [];
Rm = [];
w = zeros(3,1);
wd = zeros(3,1);
v = zeros(3,1);
vd = grav(:);
%
% init some variables, compute the link rotation matrices
%
for j=1:n,
link = robot.links(j);
Tj = link.A(q(j));
if link.RP == 'R',
d = link.d;
else
d = q(j);
end
alpha = link.alpha;
pstar = [link.a; d*sin(alpha); d*cos(alpha)];
if j == 1,
pstar = t2r(robot.base) * pstar;
Tj = robot.base * Tj;
end
pstarm(:,j) = pstar;
Rm{j} = t2r(Tj);
if debug>1,
Rm{j}
Pstarm(:,j)'
end
end
%
% the forward recursion
%
for j=1:n,
link = robot.links(j);
Rt = Rm{j}'; % transpose!!
pstar = pstarm(:,j);
r = link.r;
%
% statement order is important here
%
if link.RP == 'R',
% revolute axis
wd = Rt*(wd + z0*qdd(j) + ...
cross(w,z0*qd(j)));
w = Rt*(w + z0*qd(j));
%v = cross(w,pstar) + Rt*v;
vd = cross(wd,pstar) + ...
cross(w, cross(w,pstar)) +Rt*vd;
else
% prismatic axis
w = Rt*w;
wd = Rt*wd;
vd = Rt*(z0*qdd(j)+vd) + ...
cross(wd,pstar) + ...
2*cross(w,Rt*z0*qd(j)) +...
cross(w, cross(w,pstar));
end
%whos
vhat = cross(wd,r') + ...
cross(w,cross(w,r')) + vd;
F = link.m*vhat;
N = link.I*wd + cross(w,link.I*w);
Fm = [Fm F];
Nm = [Nm N];
if debug,
fprintf('w: '); fprintf('%.3f ', w)
fprintf('\nwd: '); fprintf('%.3f ', wd)
fprintf('\nvd: '); fprintf('%.3f ', vd)
fprintf('\nvdbar: '); fprintf('%.3f ', vhat)
fprintf('\n');
end
end
%
% the backward recursion
%
fext = fext(:);
f = fext(1:3); % force/moments on end of arm
nn = fext(4:6);
for j=n:-1:1,
link = robot.links(j);
pstar = pstarm(:,j);
%
% order of these statements is important, since both
% nn and f are functions of previous f.
%
if j == n,
R = eye(3,3);
else
R = Rm{j+1};
end
r = link.r;
nn = R*(nn + cross(R'*pstar,f)) + ...
cross(pstar+r',Fm(:,j)) + ...
Nm(:,j);
f = R*f + Fm(:,j);
if debug,
fprintf('f: '); fprintf('%.3f ', f)
fprintf('\nn: '); fprintf('%.3f ', nn)
fprintf('\n');
end
R = Rm{j};
if link.RP == 'R',
% revolute
tau(p,j) = nn'*(R'*z0) + ...
link.G^2 * link.Jm*qdd(j) + ...
abs(link.G) * friction(link, qd(j));
else
% prismatic
tau(p,j) = f'*(R'*z0) + ...
link.G^2 * link.Jm*qdd(j) + ...
abs(link.G) * friction(link, qd(j));
end
end
% this last bit needs work/testing
R = Rm{1};
nn = R*(nn);
f = R*f;
wbase = [f; nn];
end
endfunction
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
ikine6s.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/ikine6s.m
| 6,065 |
utf_8
|
4f342a905d0c1a34d604e6fa1ed16df5
|
%SerialLink.ikine6s Inverse kinematics for 6-axis robot with spherical wrist
%
% Q = R.ikine6s(T) is the joint coordinates corresponding to the robot
% end-effector pose T represented by the homogenenous transform. This
% is a analytic solution for a 6-axis robot with a spherical wrist (such as
% the Puma 560).
%
% Q = R.IKINE6S(T, CONFIG) as above but specifies the configuration of the arm in
% the form of a string containing one or more of the configuration codes:
%
% 'l' arm to the left (default)
% 'r' arm to the right
% 'u' elbow up (default)
% 'd' elbow down
% 'n' wrist not flipped (default)
% 'f' wrist flipped (rotated by 180 deg)
%
% Notes::
% - The inverse kinematic solution is generally not unique, and
% depends on the configuration string.
%
% Reference::
%
% Inverse kinematics for a PUMA 560 based on the equations by Paul and Zhang
% From The International Journal of Robotics Research
% Vol. 5, No. 2, Summer 1986, p. 32-44
%
%
% Author::
% Robert Biro with Gary Von McMurray,
% GTRI/ATRP/IIMB,
% Georgia Institute of Technology
% 2/13/95
%
% See also SerialLink.FKINE, SerialLink.IKINE.
function theta = ikine6s(robot, T, varargin)
if robot.n ~= 6,
error('Solution only applicable for 6DOF manipulator');
end
if robot.mdh ~= 0,
error('Solution only applicable for standard DH conventions');
end
if ndims(T) == 3,
theta = [];
for k=1:size(T,3),
th = ikine6s(robot, T(:,:,k), varargin{:});
theta = [theta; th];
end
return;
end
L = robot.links;
a1 = L(1).a;
a2 = L(2).a;
a3 = L(3).a;
if ~isspherical(robot)
error('wrist is not spherical')
end
d1 = L(1).d;
d2 = L(2).d;
d3 = L(3).d;
d4 = L(4).d;
if ~ishomog(T),
error('T is not a homog xform');
end
% undo base transformation
T = inv(robot.base) * T;
% The following parameters are extracted from the Homogeneous
% Transformation as defined in equation 1, p. 34
Ox = T(1,2);
Oy = T(2,2);
Oz = T(3,2);
Ax = T(1,3);
Ay = T(2,3);
Az = T(3,3);
Px = T(1,4);
Py = T(2,4);
Pz = T(3,4);
% The configuration parameter determines what n1,n2,n4 values are used
% and how many solutions are determined which have values of -1 or +1.
if nargin < 3,
configuration = '';
else
configuration = lower(varargin{1});
end
% default configuration
n1 = -1; % L
n2 = -1; % U
n4 = -1; % N
if ~isempty(findstr(configuration, 'l')),
n1 = -1;
end
if ~isempty(findstr(configuration, 'r')),
n1 = 1;
end
if ~isempty(findstr(configuration, 'u')),
if n1 == 1,
n2 = 1;
else
n2 = -1;
end
end
if ~isempty(findstr(configuration, 'd')),
if n1 == 1,
n2 = -1;
else
n2 = 1;
end
end
if ~isempty(findstr(configuration, 'n')),
n4 = 1;
end
if ~isempty(findstr(configuration, 'f')),
n4 = -1;
end
%
% Solve for theta(1)
%
% r is defined in equation 38, p. 39.
% theta(1) uses equations 40 and 41, p.39,
% based on the configuration parameter n1
%
r=sqrt(Px^2 + Py^2);
if (n1 == 1),
theta(1)= atan2(Py,Px) + asin(d3/r);
else
theta(1)= atan2(Py,Px) + pi - asin(d3/r);
end
%
% Solve for theta(2)
%
% V114 is defined in equation 43, p.39.
% r is defined in equation 47, p.39.
% Psi is defined in equation 49, p.40.
% theta(2) uses equations 50 and 51, p.40, based on the configuration
% parameter n2
%
V114= Px*cos(theta(1)) + Py*sin(theta(1));
r=sqrt(V114^2 + Pz^2);
Psi = acos((a2^2-d4^2-a3^2+V114^2+Pz^2)/(2.0*a2*r));
if ~isreal(Psi),
warning('point not reachable');
theta = [NaN NaN NaN NaN NaN NaN];
return
end
theta(2) = atan2(Pz,V114) + n2*Psi;
%
% Solve for theta(3)
%
% theta(3) uses equation 57, p. 40.
%
num = cos(theta(2))*V114+sin(theta(2))*Pz-a2;
den = cos(theta(2))*Pz - sin(theta(2))*V114;
theta(3) = atan2(a3,d4) - atan2(num, den);
%
% Solve for theta(4)
%
% V113 is defined in equation 62, p. 41.
% V323 is defined in equation 62, p. 41.
% V313 is defined in equation 62, p. 41.
% theta(4) uses equation 61, p.40, based on the configuration
% parameter n4
%
V113 = cos(theta(1))*Ax + sin(theta(1))*Ay;
V323 = cos(theta(1))*Ay - sin(theta(1))*Ax;
V313 = cos(theta(2)+theta(3))*V113 + sin(theta(2)+theta(3))*Az;
theta(4) = atan2((n4*V323),(n4*V313));
%[(n4*V323),(n4*V313)]
%
% Solve for theta(5)
%
% num is defined in equation 65, p. 41.
% den is defined in equation 65, p. 41.
% theta(5) uses equation 66, p. 41.
%
num = -cos(theta(4))*V313 - V323*sin(theta(4));
den = -V113*sin(theta(2)+theta(3)) + Az*cos(theta(2)+theta(3));
theta(5) = atan2(num,den);
%[num den]
%
% Solve for theta(6)
%
% V112 is defined in equation 69, p. 41.
% V122 is defined in equation 69, p. 41.
% V312 is defined in equation 69, p. 41.
% V332 is defined in equation 69, p. 41.
% V412 is defined in equation 69, p. 41.
% V432 is defined in equation 69, p. 41.
% num is defined in equation 68, p. 41.
% den is defined in equation 68, p. 41.
% theta(6) uses equation 70, p. 41.
%
V112 = cos(theta(1))*Ox + sin(theta(1))*Oy;
V132 = sin(theta(1))*Ox - cos(theta(1))*Oy;
V312 = V112*cos(theta(2)+theta(3)) + Oz*sin(theta(2)+theta(3));
V332 = -V112*sin(theta(2)+theta(3)) + Oz*cos(theta(2)+theta(3));
V412 = V312*cos(theta(4)) - V132*sin(theta(4));
V432 = V312*sin(theta(4)) + V132*cos(theta(4));
num = -V412*cos(theta(5)) - V332*sin(theta(5));
den = - V432;
theta(6) = atan2(num,den);
% remove the link offset angles
for i=1:6
theta(i) = theta(i) - L(i).offset;
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
jacob0.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/jacob0.m
| 2,687 |
utf_8
|
d4357319844fce3feaea8b842aa504d1
|
%SerialLink.JACOB0 Jacobian in world coordinates
%
% J0 = R.jacob0(Q, OPTIONS) is a 6xN Jacobian matrix for the robot in pose Q.
% The manipulator Jacobian matrix maps joint velocity to end-effector spatial
% velocity V = J0*QD expressed in the world-coordinate frame.
%
% Options::
% 'rpy' Compute analytical Jacobian with rotation rate in terms of
% roll-pitch-yaw angles
% 'eul' Compute analytical Jacobian with rotation rates in terms of
% Euler angles
% 'trans' Return translational submatrix of Jacobian
% 'rot' Return rotational submatrix of Jacobian
%
% Note::
% - the Jacobian is computed in the world frame and transformed to the
% end-effector frame.
% - the default Jacobian returned is often referred to as the geometric
% Jacobian, as opposed to the analytical Jacobian.
%
% See also SerialLink.jacobn, deltatr, tr2delta.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 J0 = jacob0(robot, q, varargin)
opt.rpy = false;
opt.eul = false;
opt.trans = false;
opt.rot = false;
opt = tb_optparse(opt, varargin);
%
% dX_tn = Jn dq
%
Jn = jacobn(robot, q); % Jacobian from joint to wrist space
%
% convert to Jacobian in base coordinates
%
Tn = fkine(robot, q); % end-effector transformation
R = t2r(Tn);
J0 = [R zeros(3,3); zeros(3,3) R] * Jn;
if opt.rpy
rpy = tr2rpy( fkine(robot, q) );
B = rpy2jac(rpy);
if rcond(B) < eps,
error('Representational singularity');
end
J0 = blkdiag( eye(3,3), inv(B) ) * J0;
elseif opt.eul
eul = tr2eul( fkine(robot, q) );
B = eul2jac(eul);
if rcond(B) < eps,
error('Representational singularity');
end
J0 = blkdiag( eye(3,3), inv(B) ) * J0;
end
if opt.trans
J0 = J0(1:3,:);
elseif opt.rot
J0 = J0(4:6,:);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
jacobn.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/jacobn.m
| 2,285 |
utf_8
|
d0a28ea847a72cd2f6438b539ca8bedc
|
%SerialLink.JACOBN Jacobian in end-effector frame
%
% JN = R.jacobn(Q, options) is a 6xN Jacobian matrix for the robot in
% pose Q. The manipulator Jacobian matrix maps joint velocity to
% end-effector spatial velocity V = J0*QD in the end-effector frame.
%
% Options::
% 'trans' Return translational submatrix of Jacobian
% 'rot' Return rotational submatrix of Jacobian
%
% Notes::
% - this Jacobian is often referred to as the geometric Jacobian
%
% Reference::
% Paul, Shimano, Mayer,
% Differential Kinematic Control Equations for Simple Manipulators,
% IEEE SMC 11(6) 1981,
% pp. 456-460
%
% See also SerialLink.jacob0, delta2tr, tr2delta.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 J = jacobn(robot, q, varargin)
opt.trans = false;
opt.rot = false;
opt = tb_optparse(opt, varargin);
n = robot.n;
L = robot.links; % get the links
J = [];
U = robot.tool;
for j=n:-1:1,
if robot.mdh == 0,
% standard DH convention
U = L(j).A(q(j)) * U;
end
if L(j).RP == 'R',
% revolute axis
d = [ -U(1,1)*U(2,4)+U(2,1)*U(1,4)
-U(1,2)*U(2,4)+U(2,2)*U(1,4)
-U(1,3)*U(2,4)+U(2,3)*U(1,4)];
delta = U(3,1:3)'; % nz oz az
else
% prismatic axis
d = U(3,1:3)'; % nz oz az
delta = zeros(3,1); % 0 0 0
end
J = [[d; delta] J];
if robot.mdh ~= 0,
% modified DH convention
U = L(j).A(q(j)) * U;
end
end
if opt.trans
J0 = J0(1:3,:);
elseif opt.rot
J0 = J0(4:6,:);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
subsasgn.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/subsasgn.m
| 1,764 |
utf_8
|
12b197110489a5436b0f9c7d8346641f
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 r = subsasgn(r, s, v)
if s(1).type ~= '.'
error('only .field supported')
end
switch s(1).subs,
case 'links'
r.links = v;
case 'lineopt',
r.lineopt = v;
case 'shadowopt',
r.shadowopt = v;
case 'offset',
L = r.links;
for i=1:r.n,
L(i).offset = v(i);
end
case 'qlim',
if numrows(v) ~= r.n,
error('insufficient rows in joint limit matrix');
end
L = r.links;
for i=1:r.n,
L(i).qlim = v(i,:);
end
case 'q',
r.q = v;
case 'handle',
r.handle = v;
case 'plotopt',
r.plotopt = v;
case 'gravity',
r.gravity = v;
case 'tool',
if ~ishomog(v)
error('base must be a homogeneous transform');
end
r.tool = v;
case 'base',
if ~ishomog(v)
error('base must be a homogeneous transform');
end
r.base = v;
case 'name',
r.name = v;
case 'manufacturer',
r.manufacturer = v;
case 'comment',
r.comment = v;
otherwise, error('Unknown method in subsasgn')
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
isspherical.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/isspherical.m
| 1,289 |
utf_8
|
a8a3dab75cbabe5ce56b5d99f9cbed37
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 v = isspherical(r)
%SerialLink.isspherical Test for spherical wrist
%
% R.isspherical() is true if the robot has a spherical wrist, that is, the
% last 3 axes intersect at a point.
%
% See also SerialLink.ikine6s.
L = r.links(end-2:end);
v = false;
if ~isempty( find( [L(1).a L(2).a L(3).a L(2).d L(3).d] ~= 0 ))
return
end
if (abs(L(1).alpha) == pi/2) & (abs(L(1).alpha + L(2).alpha) < eps)
v = true;
return;
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
islimit.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/islimit.m
| 1,196 |
utf_8
|
10b2f47bd6a9fdbf33da48c014e3bb33
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 v = islimit(r,q)
%SerialLink.islimit Joint limit test
%
% V = R.ISLIMIT(Q) is a vector of boolean values, one per joint,
% false (0) if Q(i) is within the joint limits, else true (1).
L = r.links;
if length(q) ~= r.n
error('argument for islimit method is wrong length');
end
v = [];
for i=1:r.n
v = [v; r.links(i).islimit(q(i))];
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
jacob_dot.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/jacob_dot.m
| 2,601 |
utf_8
|
9f2000212bd6bcf04fa5999185dd9fd6
|
%SerialLink.jacob_dot Hessian in end-effector frame
%
% JDQ = R.jacob_dot(Q, QD) is the product of the Hessian, derivative of the
% Jacobian, and the joint rates.
%
% Notes::
% - useful for operational space control
% - not yet tested/debugged.
%
% See also: SerialLink.jacob0, diff2tr, tr2diff.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 Jdot = jacob_dot(robot, q, qd)
n = robot.n;
L = robot.links; % get the links
Tj = robot.base; % this is cumulative transform from base
w = [0;0;0];
v = [0;0;0];
for j=1:n,
link = robot.links(j);
Aj = link.A(q(j));
Tj = Tj * Aj;
R{j} = t2r(Aj);
T{j} = t2r(Tj);
p(:,j) = transl(Tj); % origin of link j
if j>1,
z(:,j) = T{j-1} * [0 0 1]'; % in world frame
w = R{j}*( w + z(:,j) * qd(j));
v = v + cross(R{j}*w, R{j-1}*p(:,j));
%v = R{j-1}'*v + cross(w, p(:,j));
%w = R{j-1}'* w + z(:,j) * qd(j);
else
z(:,j) = [0 0 1]';
v = [0 0 0]';
w = z(:,j) * qd(j);
end
vel(:,j) = v; % velocity of origin of link j
omega(:,j) = w; % omega of link j in link j frame
end
omega
z
J = [];
Jdot = [];
for j=1:n,
if j>1,
t = p(:,n) - p(:,j-1);
td = vel(:,n) - vel(:,j-1);
else
t = p(:,n);
td = vel(:,n);
end
if L(j).RP == 'R',
J_col = [cross(z(:,j), t); z(:,j)];
Jdot_col = [cross(cross(omega(:,j), z(:,j)), t) + cross(z(:,j), td) ; cross(omega(:,j), z(:,j))];
else
J_col = [z(:,j); 0;0;0];
Jdot_col = zeros(6,1);
end
J = [J J_col];
Jdot = [Jdot Jdot_col];
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
jtraj.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/jtraj.m
| 1,770 |
utf_8
|
ea27c1029941256bff4d31f4be8b7f73
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 jt = jtraj(r, T1, T2, t, varargin)
%SerialLink.jtraj Create joint space trajectory
%
% Q = R.jtraj(T0, TF, M) is a joint space trajectory where the joint
% coordinates reflect motion from end-effector pose T0 to TF in M steps with
% default zero boundary conditions for velocity and acceleration.
% The trajectory Q is an MxN matrix, with one row per time step, and
% one column per joint, where N is the number of robot joints.
%
% Note::
% - requires solution of inverse kinematics. R.ikine6s() is used if
% appropriate, else R.ikine(). Additional trailing arguments to R.jtraj()
% are passed as trailing arugments to the these functions.
%
% See also jtraj, SerialLink.ikine, SerialLink.ikine6s.
if isspherical(r) && (r.n == 6)
q1 = ikine6s(r, T1, varargin{:});
q2 = ikine6s(r, T2, varargin{:});
else
q1 = ikine(r, T1, varargin{:});
q2 = ikine(r, T2, varargin{:});
end
jt = jtraj(q1, q2, t);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
gravload.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/gravload.m
| 1,717 |
utf_8
|
03a9c9463c5e3f40ba8d40fe8907fffc
|
%SerialLink.gravload Gravity loading
%
% TAUG = R.gravload(Q) is the joint gravity loading for the robot in the
% joint configuration Q. Gravitational acceleration is a property of the
% robot object.
%
% If Q is a row vector, the result is a row vector of joint torques. If
% Q is a matrix, each row is interpreted as a joint configuration vector,
% and the result is a matrix each row being the corresponding joint torques.
%
% TAUG = R.gravload(Q, GRAV) is as above but the gravitational
% acceleration vector GRAV is given explicitly.
%
% See also SerialLink.rne, SerialLink.itorque, SerialLink.coriolis.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 tg = gravload(robot, q, grav)
if numcols(q) ~= robot.n
error('Insufficient columns in q')
end
if nargin == 2
tg = rne(robot, q, zeros(size(q)), zeros(size(q)));
elseif nargin == 3
tg = rne(robot, q, zeros(size(q)), zeros(size(q)), grav);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
char.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/char.m
| 2,312 |
utf_8
|
1d0928dd606e427c1cf624e12f7cd15e
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 = char(robot)
%
% S = R.char() is a string representation of the robot parameters.
s = '';
for j=1:length(robot)
r = robot(j);
% informational line
if r.mdh
convention = 'modDH';
else
convention = 'stdDH';
end
s = sprintf('%s (%d axis, %s, %s)', r.name, r.n, config(r), convention);
% comment and other info
line = '';
if ~isempty(r.manufacturer)
line = strcat(line, sprintf(' %s;', r.manufacturer));
end
if ~isempty(r.comment)
line = strcat(line, sprintf(' %s;', r.comment));
end
s = strvcat(s, line);
% link parameters
s = strvcat(s, '+---+-----------+-----------+-----------+-----------+');
s = strvcat(s, '| j | theta | d | a | alpha |');
s = strvcat(s, '+---+-----------+-----------+-----------+-----------+');
s = strvcat(s, char(r.links, true));
s = strvcat(s, '+---+-----------+-----------+-----------+-----------+');
% gravity, base, tool
s_grav = horzcat(strvcat('grav = ', ' ', ' '), num2str(r.gravity));
s_grav = strvcat(s_grav, " ");
s_base = horzcat(strvcat(" base = ",' ',' ', ' '),num2str(r.base));
s_tool = horzcat(strvcat(' tool = ',' ',' ', ' '), num2str(r.tool));
line = horzcat(s_grav, s_base, s_tool);
s = strvcat(s, ' ', line);
if j ~= length(robot)
s = strvcat(s, ' ');
end
end
endfunction
function v = config(r)
v = '';
for i=1:r.n
v(i) = r.links(i).RP;
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
friction.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/friction.m
| 1,264 |
utf_8
|
324caf1538af019255ff9332591ec174
|
%SerialLink.friction Friction force
%
% TAU = R.friction(QD) is the vector of joint friction forces/torques for the
% robot moving with joint velocities QD.
%
% The friction model includes viscous friction (linear with velocity)
% and Coulomb friction (proportional to sign(QD)).
%
% See also Link.friction.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 tau = friction(robot, qd)
L = robot.links;
for i=1:robot.n,
tau(i) = friction(L(i), qd(i));
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
ikine.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/ikine.m
| 4,504 |
utf_8
|
391a739d99e22dd779dd9fb68317af08
|
%SerialLink.IKINE Inverse manipulator kinematics
%
% Q = R.ikine(T) is the joint coordinates corresponding to the robot
% end-effector pose T which is a homogenenous transform.
%
% Q = R.ikine(T, Q0, OPTIONS) specifies the initial estimate of the joint
% coordinates.
%
% Q = R.ikine(T, Q0, M, OPTIONS) specifies the initial estimate of the joint
% coordinates and a mask matrix. For the case where the manipulator
% has fewer than 6 DOF the solution space has more dimensions than can
% be spanned by the manipulator joint coordinates. In this case
% the mask matrix M specifies the Cartesian DOF (in the wrist coordinate
% frame) that will be ignored in reaching a solution. The mask matrix
% has six elements that correspond to translation in X, Y and Z, and rotation
% about X, Y and Z respectively. The value should be 0 (for ignore) or 1.
% The number of non-zero elements should equal the number of manipulator DOF.
%
% For example when using a 5 DOF manipulator rotation about the wrist z-axis
% might be unimportant in which case M = [1 1 1 1 1 0].
%
% In all cases if T is 4x4xM it is taken as a homogeneous transform sequence
% and R.ikine() returns the joint coordinates corresponding to each of the
% transforms in the sequence. Q is MxN where N is the number of robot joints.
% The initial estimate of Q for each time step is taken as the solution
% from the previous time step.
%
% Options::
%
% Notes::
% - Solution is computed iteratively using the pseudo-inverse of the
% manipulator Jacobian.
% - The inverse kinematic solution is generally not unique, and
% depends on the initial guess Q0 (defaults to 0).
% - Such a solution is completely general, though much less efficient
% than specific inverse kinematic solutions derived symbolically.
% - This approach allows a solution to obtained at a singularity, but
% the joint angles within the null space are arbitrarily assigned.
%
% See also SerialLink.fkine, tr2delta, SerialLink.jacob0, SerialLink.ikine6s.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 qt = ikine(robot, tr, varargin)
% set default parameters for solution
opt.ilimit = 100;
opt.tol = 1e-6;
opt.alpha = 1;
opt.plot = false;
opt.pinv = false;
[opt,args] = tb_optparse(opt, varargin);
n = robot.n;
% robot.ikine(tr, q)
if length(args) > 0
q = args{1};
if isempty(q)
q = zeros(1, n);
else
q = q(:)';
end
else
q = zeros(1, n);
end
% robot.ikine(tr, q, m)
if length(args) > 1
m = args{2};
m = m(:);
if numel(m) ~= 6
error('Mask matrix should have 6 elements');
end
if numel(find(m)) ~= robot.n
error('Mask matrix must have same number of 1s as robot DOF')
end
else
if n < 6
error('For a manipulator with fewer than 6DOF a mask matrix argument must be specified');
end
m = ones(6, 1);
end
% make this a logical array so we can index with it
m = logical(m);
npoints = size(tr,3); % number of points
qt = zeros(npoints, n); % preallocate space for results
tcount = 0; % total iteration count
eprev = Inf;
save.e = Inf;
save.q = [];
history = [];
for i=1:npoints
T = tr(:,:,i);
nm = Inf;
count = 0;
optim = optimset('Display', 'iter', 'TolX', 0, 'TolFun', opt.tol, 'MaxIter', opt.ilimit);
optim
q = fminsearch(@(x) ikinefunc(x, T, robot, m), q, optim);
end
qt = q;
end
function E = ikinefunc(q, T, robot, m)
e = tr2delta(fkine(robot, q'), T);
E = norm(e(m));
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
nofriction.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/nofriction.m
| 1,537 |
utf_8
|
703f45d87978f4e206b0b491525168f5
|
%SerialLink.nofriction Remove friction
%
% RNF = R.nofriction() is a robot object with the same parameters as R but
% with non-linear (Couolmb) friction coefficients set to zero.
%
% RNF = R.nofriction('all') as above but all friction coefficients set to zero.
%
% Notes:
% - Non-linear (Coulomb) friction can cause numerical problems when integrating
% the equations of motion (R.fdyn).
% - The resulting robot object has its name string modified by prepending 'NF/'.
%
% See also SerialLink.fdyn, Link.nofriction.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 r2 = nofriction(r, varargin)
r2 = SerialLink(r); % make a copy
for j=1:r2.n,
r2.links(j) = r.links(j).nofriction(varargin{:});
end
r2.name = ['NF/' r.name];
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
subsref.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/subsref.m
| 3,987 |
utf_8
|
278306b42a8ab93fa47e1b7062d8fa9f
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 [v, a, b] = subsref(r, s)
if s(1).type ~= '.'
%error('only .field supported')
end
% NOTE WELL: the following code can't use getfield() since
% getfield() uses this, and Matlab will crash!!
el = char(s(1).subs);
switch el,
%-------------------------------------------------------------------------------------
% External Functions
case 'fkine',
q = s(2).subs;
v = fkine(r,q{:});
case 'ikine6s',
q = s(2).subs;
v = ikine6s(r,q{:});
case 'ikine',
q = s(2).subs;
v = ikine(r,q{:});
case 'maniplty',
q = s(2).subs;
[v, a] = maniplty(r,q{:});
case 'rne'
q = s(2).subs;
[v, a] = rne(r,q{:});
case 'isspherical',
v = isspherical(r);
case 'gravload'
q = s(2).subs;
v = gravload(r,q{:});
case 'inertia'
q = s(2).subs;
v = inertia(r,q{:});
case 'cinertia',
q = s(2).subs;
v = cinertia(r,q{:});
case 'coriolis'
q = s(2).subs;
v = coriolis(r,q{:});
case 'friction'
q = s(2).subs;
v = friction(r,q{:});
case 'nofriction'
if numel(s(2).subs) < 1
v = nofriction(r);
else
q = s(2).subs;
v = nofriction(r,q{:});
end
case 'islimit',
q = s(2).subs;
v = islimit(r,q{:});
case 'payload',
q = s(2).subs;
l = r.links;
l(r.n).m = q{1};
l(r.n).r = q{2};
r.links = l;
v = SerialLink(r);
case 'jacob0',
q = s(2).subs;
v = jacob0(r,q{:});
case 'accel',
q = s(2).subs;
v = accel(r,q{:});
case 'plot',
q = s(2).subs;
plot(r,q{:})
case 'fdyn',
q = s(2).subs;
[v, a, b] = fdyn(r,q{:});
case 'jacobn',
q = s(2).subs;
v = jacobn(r,q{:});
case 'jtraj',
q = s(2).subs;
v = jtraj(r,q{:});
case 'perturb',
q = s(2).subs;
v = perturb(r,q{:});
case 'itorque',
q = s(2).subs;
v = itorque(r,q{:});
case 'jacob_dot',
q = s(2).subs;
v = jacob_dot(r,q{:});
case 'dyn',
q = s(2).subs;
v = dyn(r,q{:});
case 'showlink',
q = s(2).subs;
v = showlink(r,q{:});
%-------------------------------------------------------------------------------------
case 'links',
if length(s) == 1,
v = r.links;
elseif length(s) == 2,
if s(2).type == '()'
j = s(2).subs;
j = j{:};
if (j < 1) | (j > r.n)
error('link index out of bounds')
end
end
v = r.links(j);
elseif length(s) >= 3,
if s(2).type == '()'
j = s(2).subs;
j = j{:};
if (j < 1) | (j > r.n)
error('link index out of bounds')
end
end
if s(3).subs = 'dyn',
link = r.links(j);
v = link.dyn();
end
end
case 'offset',
L = r.links;
v = [];
for i=1:r.n,
v = [v; L(i).offset];
end
case 'qlim',
L = r.links;
v = [];
for i=1:r.n,
v = [v; L(i).qlim];
end
case 'n',
v = r.n;
case 'name',
v = r.name;
case 'dh',
v = rdh(r);
case 'dyn'
v = rdyn(r);
case 'gravity'
v = r.gravity;
case 'tool'
v = r.tool;
case 'base'
v = r.base;
case 'mdh',
v = r.mdh;
case 'q',
v = r.q;
case 'plotopt',
v = r.plotopt;
case 'lineopt'
v = r.lineopt;
case 'shadowopt'
v = r.shadowopt;
case {'show', 'handle'}
v = r.handle';
otherwise, error('Unknown method in subsref')
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
coriolis.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/coriolis.m
| 3,406 |
utf_8
|
752fc02f5d2bb2dafac400185d4ff702
|
%SerialLink.coriolis Coriolis matrix
%
% C = R.CORIOLIS(Q, QD) is the NxN Coriolis/centripetal matrix for
% the robot in configuration Q and velocity QD, where N is the number of
% joints. The product C*QD is the vector of joint force/torque due to velocity
% coupling. The diagonal elements are due to centripetal effects and the
% off-diagonal elements are due to Coriolis effects. This matrix is also
% known as the velocity coupling matrix, since gives the disturbance forces
% on all joints due to velocity of any joint.
%
% If Q and QD are matrices (DxN), each row is interpretted as a joint state
% vector, and the result (NxNxD) is a 3d-matrix where each plane corresponds
% to a row of Q and QD.
%
% Notes::
% - joint friction is also a joint force proportional to velocity but it is
% eliminated in the computation of this value.
% - computationally slow, involves N^2/2 invocations of RNE.
%
% See also SerialLink.rne.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 C = coriolis(robot, q, qd)
if numcols(q) ~= robot.n
error('q must have %d columns', robot.n);
end
if numcols(qd) ~= robot.n
error('qd must have %d columns', robot.n);
end
% we need to create a clone robot with no friciton, since friction
% is also proportional to joint velocity
robot2 = nofriction(robot,'all');
if numrows(q) > 1
if numrows(q) ~= numrows(qd)
error('for trajectory q and qd must have same number of rows');
end
C = [];
for i=1:numrows(q)
C = cat(3, C, robot2.coriolis(q(i,:), qd(i,:)));
end
return
end
N = robot2.n;
C = zeros(N,N);
Csq = zeros(N,N);
% find the torques that depend on a single finite joint speed,
% these are due to the squared (centripetal) terms
%
% set QD = [1 0 0 ...] then resulting torque is due to qd_1^2
for j=1:N
QD = zeros(1,N);
QD(j) = 1;
tau = rne(robot2,q, QD, zeros(size(q)), [0 0 0]');
Csq(:,j) = Csq(:,j) + tau';
end
% find the torques that depend on a pair of finite joint speeds,
% these are due to the product (Coridolis) terms
% set QD = [1 1 0 ...] then resulting torque is due to
% qd_1 qd_2 + qd_1^2 + qd_2^2
for j=1:N
for k=j+1:N
% find a product term qd_j * qd_k
QD = zeros(1,N);
QD(j) = 1;
QD(k) = 1;
tau = rne(robot2,q, QD, zeros(size(q)), [0 0 0]');
C(:,k) = C(:,k) + (tau' - Csq(:,k) - Csq(:,j)) * qd(j);
end
end
C = C + Csq * diag(qd);
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
accel.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/accel.m
| 2,889 |
utf_8
|
4cab37c2a136ea9cb47620898bafff08
|
%SerialLink.accel Manipulator forward dynamics
%
% QDD = R.accel(Q, QD, TORQUE) is a vector (Nx1) of joint accelerations that result
% from applying the actuator force/torque to the manipulator robot in state Q and QD.
% If Q, QD, TORQUE are matrices with M rows, then QDD is a matrix with M rows
% of acceleration corresponding to the equivalent rows of Q, QD, TORQUE.
%
% QDD = R.ACCEL(X) as above but X=[Q,QD,TORQUE].
%
% Note::
% - Uses the method 1 of Walker and Orin to compute the forward dynamics.
% - This form is useful for simulation of manipulator dynamics, in
% conjunction with a numerical integration function.
%
% See also SerialLink.rne, SerialLink, ode45.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 qdd = accel(robot, Q, qd, torque)
if numcols(Q) ~= robot.n
error('q must have %d columns', robot.n);
end
if numcols(qd) ~= robot.n
error('qd must have %d columns', robot.n);
end
if numcols(torque) ~= robot.n
error('torque must have %d columns', robot.n);
end
if numrows(Q) > 1
if numrows(Q) ~= numrows(qd)
error('for trajectory q and qd must have same number of rows');
end
if numrows(Q) ~= numrows(torque)
error('for trajectory q and torque must have same number of rows');
end
qdd = [];
for i=1:numrows(Q)
qdd = cat(1, qdd, robot.accel(Q(i,:), qd(i,:), torque(i,:))');
end
return
end
n = robot.n;
if nargin == 2
% accel(X)
q = Q(1:n);
qd = Q(n+1:2*n);
torque = Q(2*n+1:3*n);
else
% accel(Q, qd, torque)
q = Q;
if length(q) == robot.n,
q = q(:);
qd = qd(:);
end
end
% compute current manipulator inertia
% torques resulting from unit acceleration of each joint with
% no gravity.
M = rne(robot, ones(n,1)*q', zeros(n,n), eye(n), [0;0;0]);
% compute gravity and coriolis torque
% torques resulting from zero acceleration at given velocity &
% with gravity acting.
tau = rne(robot, q', qd', zeros(1,n));
qdd = inv(M) * (torque(:) - tau');
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
itorque.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/itorque.m
| 1,522 |
utf_8
|
cc3d52dd02430ec8e7e51b019dd6000a
|
%SerialLink.itorque Inertia torque
%
% TAUI = R.itorque(Q, QDD) is the inertia force/torque N-vector at the specified
% joint configuration Q and acceleration QDD, that is, TAUI = INERTIA(Q)*QDD.
%
% If Q and QDD are row vectors, the result is a row vector of joint torques.
% If Q and QDD are matrices, each row is interpretted as a joint state
% vector, and the result is a matrix each row being the corresponding joint
% torques.
%
% Note::
% - If the robot model contains non-zero motor inertia then this will
% included in the result.
%
% See also SerialLink.rne, SerialLink.inertia.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 it = itorque(robot, q, qdd)
it = rne(robot, q, zeros(size(q)), qdd, [0;0;0]);
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
rne_mdh.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/rne_mdh.m
| 4,445 |
utf_8
|
336e755459929378f84bea818a23b08b
|
%SERIALLINK.RNE_MDH Compute inverse dynamics via recursive Newton-Euler formulation
%
% Recursive Newton-Euler for modified Denavit-Hartenberg notation. Is invoked by
% R.RNE().
%
% See also SERIALLINK.RNE.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 tau = rne_mdh(robot, a1, a2, a3, a4, a5)
z0 = [0;0;1];
grav = robot.gravity; % default gravity from the object
fext = zeros(6, 1);
% Set debug to:
% 0 no messages
% 1 display results of forward and backward recursions
% 2 display print R and p*
debug = 0;
n = robot.n;
if numcols(a1) == 3*n,
Q = a1(:,1:n);
Qd = a1(:,n+1:2*n);
Qdd = a1(:,2*n+1:3*n);
np = numrows(Q);
if nargin >= 3,
grav = a2(:);
end
if nargin == 4,
fext = a3;
end
else
np = numrows(a1);
Q = a1;
Qd = a2;
Qdd = a3;
if numcols(a1) ~= n | numcols(Qd) ~= n | numcols(Qdd) ~= n | ...
numrows(Qd) ~= np | numrows(Qdd) ~= np,
error('bad data');
end
if nargin >= 5,
grav = a4(:);
end
if nargin == 6,
fext = a5;
end
end
tau = zeros(np,n);
for p=1:np,
q = Q(p,:)';
qd = Qd(p,:)';
qdd = Qdd(p,:)';
Fm = [];
Nm = [];
pstarm = [];
Rm = [];
w = zeros(3,1);
wd = zeros(3,1);
v = zeros(3,1);
vd = grav(:);
%
% init some variables, compute the link rotation matrices
%
for j=1:n,
link = robot.link{j};
Tj = link(q(j));
if link.RP == 'R',
D = link.D;
else
D = q(j);
end
alpha = link.alpha;
pm = [link.A; -D*sin(alpha); D*cos(alpha)]; % (i-1) P i
if j == 1,
pm = t2r(robot.base) * pm;
Tj = robot.base * Tj;
end
Pm(:,j) = pm;
Rm{j} = t2r(Tj);
if debug>1,
Rm{j}
Pm(:,j)'
end
end
%
% the forward recursion
%
for j=1:n,
link = robot.link{j};
R = Rm{j}'; % transpose!!
P = Pm(:,j);
Pc = link.r;
%
% trailing underscore means new value
%
if link.RP == 'R',
% revolute axis
w_ = R*w + z0*qd(j);
wd_ = R*wd + cross(R*w,z0*qd(j)) + z0*qdd(j);
%v = cross(w,P) + R*v;
vd_ = R * (cross(wd,P) + ...
cross(w, cross(w,P)) + vd);
else
% prismatic axis
w_ = R*w;
wd_ = R*wd;
%v = R*(z0*qd(j) + v) + cross(w,P);
vd_ = R*(cross(wd,P) + ...
cross(w, cross(w,P)) + vd ...
) + 2*cross(R*w,z0*qd(j)) + z0*qdd(j);
end
% update variables
w = w_;
wd = wd_;
vd = vd_;
vdC = cross(wd,Pc) + ...
cross(w,cross(w,Pc)) + vd;
F = link.m*vdC;
N = link.I*wd + cross(w,link.I*w);
Fm = [Fm F];
Nm = [Nm N];
if debug,
fprintf('w: '); fprintf('%.3f ', w)
fprintf('\nwd: '); fprintf('%.3f ', wd)
fprintf('\nvd: '); fprintf('%.3f ', vd)
fprintf('\nvdbar: '); fprintf('%.3f ', vdC)
fprintf('\n');
end
end
%
% the backward recursion
%
fext = fext(:);
f = fext(1:3); % force/moments on end of arm
nn = fext(4:6);
for j=n:-1:1,
%
% order of these statements is important, since both
% nn and f are functions of previous f.
%
link = robot.link{j};
if j == n,
R = eye(3,3);
P = [0;0;0];
else
R = Rm{j+1};
P = Pm(:,j+1); % i/P/(i+1)
end
Pc = link.r;
f_ = R*f + Fm(:,j);
nn_ = Nm(:,j) + R*nn + cross(Pc,Fm(:,j)) + ...
cross(P,R*f);
f = f_;
nn = nn_;
if debug,
fprintf('f: '); fprintf('%.3f ', f)
fprintf('\nn: '); fprintf('%.3f ', nn)
fprintf('\n');
end
if link.RP == 'R',
% revolute
tau(p,j) = nn'*z0 + ...
link.G^2 * link.Jm*qdd(j) + ...
abs(link.G) * friction(link, qd(j));
else
% prismatic
tau(p,j) = f'*z0 + ...
link.G^2 * link.Jm*qdd(j) + ...
abs(link.G) * friction(link, qd(j));
end
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
mtimes.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/mtimes.m
| 1,843 |
utf_8
|
6c52eb4cccc6f967d5e7786b9ed721e1
|
% robot objects can be multiplied r1*r2 which is mechanically equivalent
% to mounting robot r2 on the end of robot r1.
%
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 r2 = mtimes(r, l)
%SerialLink.mtimes Join robots
%
% R = R1 * R2 is a robot object that is equivalent to mounting robot R2
% on the end of robot R1.
if isa(l, 'SerialLink')
r2 = SerialLink(r);
x = r2.links;
for i = 1:length(x)
new_links(i) = Link(x(i));
end
y = l.links;
for i = 1:length(y)
new_links(i + length(x)) = Link(y(i));
end
r2.links = new_links;
r2.base = r.base;
r2.n = length(r2.links);
elseif isa(l, 'Link')
r2 = SerialLink(r);
x = r2.links;
for i = 1:length(x)
new_links(i) = Link(x(i));
end
for i = 1:length(l)
new_links(i + length(x)) = Link(l(i));
end
r2.links = new_links;
r2.n = length(r2.links);
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
perturb.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/perturb.m
| 1,687 |
utf_8
|
021a5522f737b29a05c4b03005bcd14c
|
%SerialLink.perturb Perturb robot parameters
%
% RP = R.perturb(P) is a new robot object in which the dynamic parameters (link
% mass and inertia) have been perturbed. The perturbation is multiplicative so
% that values are multiplied by random numbers in the interval (1-P) to (1+P).
% The name string of the perturbed robot is prefixed by 'P/'.
%
% Useful for investigating the robustness of various model-based control
% schemes. For example to vary parameters in the range +/- 10 percent is:
% r2 = p560.perturb(0.1);
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 r2 = perturb(r, p)
if nargin == 1,
p = 0.1; % 10 percent disturb by default
end
for i=1:r.n,
l2(i) = r.links(i);
s = (2*rand-1)*p + 1;
l2(i).m = l2(i).m * s;
s = (2*rand-1)*p + 1;
l2(i).I = l2(i).I * s;
end
% clone the robot
r2 = SerialLink(r);
r2.links = l2;
r2.name = ['P/' r.name];
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
cinertia.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/cinertia.m
| 1,262 |
utf_8
|
4b7612402dafd0f93bce5f1d520ee65f
|
%SerialLink.cinertia Cartesian inertia matrix
%
% M = R.cinertia(Q) is the NxN Cartesian (operational space) inertia matrix which relates
% Cartesian force/torque to Cartesian acceleration at the joint configuration Q, and N
% is the number of robot joints.
%
% See also SerialLink.inertia, SerialLink.rne.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 Mx = cinertia(robot, q)
J = jacob0(robot, q);
Ji = inv(J);
M = inertia(robot, q);
Mx = Ji' * M * Ji;
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
fkine.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/fkine.m
| 2,043 |
utf_8
|
8ed8bfe464ffe53e36fe550ac805285e
|
%SerialLink.fkine Forward kinematics
%
% T = R.fkine(Q) is the pose of the robot end-effector as a homogeneous
% transformation for the joint configuration Q. For an N-axis manipulator
% Q is an N-vector.
%
% If Q is a matrix, the M rows are interpretted as the generalized
% joint coordinates for a sequence of points along a trajectory. Q(i,j) is
% the j'th joint parameter for the i'th trajectory point. In this case
% it returns a 4x4xM matrix where the last subscript is the index
% along the path.
%
% Note::
% - The robot's base or tool transform, if present, are incorporated into the
% result.
%
% See also SerialLink.ikine, SerialLink.ikine6s.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 t = fkine(robot, q)
%
% evaluate fkine for each point on a trajectory of
% theta_i or q_i data
%
n = robot.n;
L = robot.links;
if numel(q) == n
t = robot.base;
for i=1:n
t = t * L(i).A(q(i));
end
t = t * robot.tool;
else
if numcols(q) ~= n
error('q must have %d columns', n)
end
t = zeros(4,4,0);
for qv=q', % for each trajectory point
tt = robot.base;
for i=1:n
tt = tt * L(i).A(qv(i));
end
t = cat(3, t, tt * robot.tool);
end
end
%robot.T = t;
%robot.notify('Moved');
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
rne.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/rne.m
| 2,475 |
utf_8
|
02a4a285327714868d309bb0a561c56a
|
%SerialLink.rne Inverse dynamics
%
% TAU = R.rne(Q, QD, QDD) is the joint torque required for the robot R
% to achieve the specified joint position Q, velocity QD and acceleration QDD.
%
% TAU = R.rne(Q, QD, QDD, GRAV) as above but overriding the gravitational
% acceleration vector in the robot object R.
%
% TAU = R.rne(Q, QD, QDD, GRAV, FEXT) as above but specifying a wrench
% acting on the end of the manipulator which is a 6-vector [Fx Fy Fz Mx My Mz].
%
% TAU = R.rne(X) as above where X=[Q,QD,QDD].
%
% TAU = R.rne(X, GRAV) as above but overriding the gravitational
% acceleration vector in the robot object R.
%
% TAU = R.rne(X, GRAV, FEXT) as above but specifying a wrench
% acting on the end of the manipulator which is a 6-vector [Fx Fy Fz Mx My Mz].
%
% If Q,QD and QDD, or X are matrices with M rows representing a trajectory then
% TAU is an MxN matrix with rows corresponding to each trajectory state.
%
% Notes:
% - The robot base transform is ignored
% - The torque computed also contains a contribution due to armature
% inertia.
% - RNE can be either an M-file or a MEX-file. See the manual for details on
% how to configure the MEX-file. The M-file is a wrapper which calls either
% RNE_DH or RNE_MDH depending on the kinematic conventions used by the robot
% object.
%
% See also SerialLink.accel, SerialLink.gravload, SerialLink.inertia.
% TODO:
% should use tb_optparse
%
% verified against MAPLE code, which is verified by examples
%
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 [tau,f] = rne(robot, varargin)
if robot.mdh == 0,
[tau,f] = rne_dh(robot, varargin{:});
else
tau = rne_mdh(robot, varargin{:});
end
endfunction
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
teach.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/teach.m
| 10,728 |
utf_8
|
47647b268a77098aa9ff5d1fa3f5dda0
|
%SerialLink.teach Graphical teach pendant
%
% R.teach() drive a graphical robot by means of a graphical slider panel.
% If no graphical robot exists one is created in a new window. Otherwise
% all current instanes of the graphical robots are driven.
%
% R.teach(Q) specifies the initial joint angle, otherwise it is taken from
% one of the existing graphical robots.
%
% See also SerialLink.plot.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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
%% TODO:
%% make the sliders change the animation while moving
%% http://www.mathworks.com/matlabcentral/newsreader/view_thread/159374
%% 1. download FINDJOBJ from the file exchange: http://www.mathworks.com/matlabcentral/fileexchange/14317
%% 2. hSlider = uicontrol('style','slider', ...); %create the slider, get its Matlab handle
%% 3. jSlider = findjobj(hSlider,'nomenu'); %get handle of the underlying java object
%% 4. jSlider.AdjustmentValueChangedCallback = @myMatlabFunction; %set callback
%%
%% Note: you can also use the familiar format:
%% set(jSlider,'AdjustmentValueChangedCallback',@myMatlabFunction)
%%
%% Feel free to explore many other properties (and ~30 callbacks)
%% available in jSlider but not in its Matlab front-end interface hSlider.
%%
%% Warning: FINDJOBJ relies on undocumented and unsupported Matlab/Java
%% functionality.
function teach(r, varargin)
bgcol = [135 206 250]/255;
opt.degrees = false;
opt.q0 = [];
% TODO: options for rpy, or eul angle display
opt = tb_optparse(opt, varargin);
% drivebot(r, q)
% drivebot(r, 'deg')
scale = ones(r.n,1);
n = r.n;
width = 300;
height = 40;
minVal = -pi;
maxVal = pi;
qlim = r.qlim;
if isempty(qlim)
qlim = [minVal*ones(r.n,1) maxVal*ones(r.n,1)];
end
if isempty(opt.q0)
q = zeros(1,n);
else
q = opt.q0;
end
% set up scale factor
scale = [];
for L=r.links
if opt.degrees && L.revolute
scale = [scale 180/pi];
else
scale = [scale 1];
end
end
T6 = r.fkine(q);
fig = figure('Units', 'pixels', ...
'Position', [0 -height width height*(n+2)+20], ...
'Color', bgcol);
set(fig,'MenuBar','none')
delete( get(fig, 'Children') )
% first we check to see if there are any graphical robots of
% this name, if so we use them, otherwise create a robot plot.
rh = findobj('Tag', r.name);
% attempt to get current joint config of graphical robot
if ~isempty(rh)
rr = get(rh(1), 'UserData');
if ~isempty(rr.q)
q = rr.q;
end
end
% now make the sliders
for i=1:n
% slider label
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0 height*(n-i)+20 width*0.1 height*0.4], ...
'String', sprintf('q%d', i));
% slider itself
q(i) = max( qlim(i,1), min( qlim(i,2), q(i) ) ); % clip to range
h(i) = uicontrol(fig, 'Style', 'slider', ...
'Units', 'pixels', ...
'Position', [width*0.1 height*(n-i)+20 width*0.7 height*0.4], ...
'Min', scale(i)*qlim(i,1), ...
'Max', scale(i)*qlim(i,2), ...
'Value', scale(i)*q(i), ...
'Tag', sprintf('Slider%d', i), ...
'Callback', @(src,event)teach_callback(r.name, i));
% if findjobj exists use it, since it lets us get continous callbacks while
% a slider moves
if exist('findjobj') && ~ispc
drawnow
jh = findjobj(h(i),'nomenu');
jh.AdjustmentValueChangedCallback = {@sliderCallbackFunc, r.name, i};
end
% text box showing slider value, also editable
h2(i) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [width*0.8 height*(n-i-0.1)+20 width*0.2 height*0.7], ...
'String', num2str(scale(i)*q(i)), ...
'Tag', sprintf('Edit%d', i), ...
'Callback', @(src,event)teach_callback(r.name, i));
% hang handles off the slider and edit objects
handles = {h(i) h2(i) scale};
set(h(i), 'Userdata', handles);
set(h2(i), 'Userdata', handles);
end
% robot name text box
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'FontSize', 20, ...
'HorizontalAlignment', 'left', ...
'Position', [0 height*(n+1.2)+20 0.8*width 0.8*height], ...
'BackgroundColor', 'white', ...
'String', r.name);
% X
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0 height*(n+0.5)+20 0.06*width height/2], ...
'BackgroundColor', 'yellow', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'String', 'x:');
h3(1,1) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [0.06*width height*(n+0.5)+20 width*0.2 height*0.6], ...
'String', sprintf('%.3f', T6(1,4)), ...
'Tag', 'T6');
% Y
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0.26*width height*(n+0.5)+20 0.06*width height/2], ...
'BackgroundColor', 'yellow', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'String', 'y:');
h3(2,1) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [0.32*width height*(n+0.5)+20 width*0.2 height*0.6], ...
'String', sprintf('%.3f', T6(2,4)));
% Z
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0.52*width height*(n+0.5)+20 0.06*width height/2], ...
'BackgroundColor', 'yellow', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'String', 'z:');
h3(3,1) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [0.58*width height*(n+0.5)+20 width*0.2 height*0.6], ...
'String', sprintf('%.3f', T6(3,4)));
% AX
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0 height*(n)+20 0.06*width height/2], ...
'BackgroundColor', 'yellow', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'String', 'ax:');
h3(1,2) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [0.06*width height*(n)+20 width*0.2 height*0.6], ...
'String', sprintf('%.3f', T6(1,3)));
% AY
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0.26*width height*(n)+20 0.06*width height/2], ...
'BackgroundColor', 'yellow', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'String', 'ay:');
h3(2,2) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [0.32*width height*(n)+20 width*0.2 height*0.6], ...
'String', sprintf('%.3f', T6(2,3)));
% AZ
uicontrol(fig, 'Style', 'text', ...
'Units', 'pixels', ...
'BackgroundColor', bgcol, ...
'Position', [0.52*width height*(n)+20 0.06*width height/2], ...
'BackgroundColor', 'yellow', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'String', 'az:');
h3(3,2) = uicontrol(fig, 'Style', 'edit', ...
'Units', 'pixels', ...
'Position', [0.58*width height*(n)+20 width*0.2 height*0.6], ...
'String', sprintf('%.3f', T6(3,3)));
set(h3(1,1), 'Userdata', h3);
uicontrol(fig, 'Style', 'pushbutton', ...
'Units', 'pixels', ...
'FontSize', 16, ...
'Position', [0.8*width height*n+20 0.2*width 2*height], ...
'CallBack', 'delete(gcf)', ...
'BackgroundColor', 'red', ...
'String', 'Quit');
if isempty(rh)
figure
r.plot(q);
end
end
function teach_callback(a, b)
% called on changes to a slider or to the edit box showing joint coordinate
% teach_callback(robot name, joint index)
name = a; % name of the robot
j = b; % joint index
% find all graphical objects tagged with the robot name, this is the
% instancs of that robot across all figures
rh = findobj('Tag', name);
% get the handles {slider, textbox, scale factor}
handles = get(gcbo, 'Userdata');
scale = handles{3};
for r=rh' % for every graphical robot instance
robot = get(r, 'UserData'); % get the robot object
q = robot.q; % get its current joint angles
if isempty(q)
q = zeros(1,robot.n);
end
if gcbo == handles{1}
% get value from slider
q(j) = get(gcbo, 'Value') / scale(j);
set(handles{2}, 'String', num2str(scale(j)*q(j)));
elseif gcbo == handles{2}
% get value from text box
q(j) = str2num(get(gcbo, 'String')) / scale(j);
set(handles{1}, 'Value', q(j));
else
warning('shouldnt happen');
end
robot.q = q;
set(r, 'UserData', robot);
robot.plot(q)
end
% compute and display the T6 pose
T6 = robot.fkine(q);
h3 = get(findobj('Tag', 'T6'), 'UserData');
for i=1:3
set(h3(i,1), 'String', sprintf('%.3f', T6(i,4)));
set(h3(i,2), 'String', sprintf('%.3f', T6(i,3)));
end
robot.T = T6;
robot.notify('Moved');
drawnow
end
function sliderCallbackFunc(src, ev, name, joint)
if get(src,'ValueIsAdjusting') == 1
try
teach_callback(name, joint);
drawnow
catch
return
end
end
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
maniplty.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/maniplty.m
| 3,592 |
utf_8
|
db86403e6ccb78655d8feed3f696f702
|
%SerialLink.MANIPLTY Manipulability measure
%
% M = R.maniplty(Q, OPTIONS) is the manipulability index measure for the robot
% at the joint configuration Q. It indicates dexterity, how isotropic the
% robot's motion is with respect to the 6 degrees of Cartesian motion.
% The measure is low when the manipulator is close to a singularity.
% If Q is a matrix M is a column vector of manipulability
% indices for each pose specified by a row of Q.
%
% Two measures can be selected:
% - Yoshikawa's manipulability measure is based on the shape of the velocity
% ellipsoid and depends only on kinematic parameters.
% - Asada's manipulability measure is based on the shape of the acceleration
% ellipsoid which in turn is a function of the Cartesian inertia matrix and
% the dynamic parameters. The scalar measure computed here is the ratio of
% the smallest/largest ellipsoid axis. Ideally the ellipsoid would be
% spherical, giving a ratio of 1, but in practice will be less than 1.
%
% Options::
% 'T' compute manipulability for just transational motion
% 'R' compute manipulability for just rotational motion
% 'yoshikawa' use Asada algorithm (default)
% 'asada' use Asada algorithm
%
% Notes::
% - by default the measure includes rotational and translational dexterity, but
% this involves adding different units. It can be more useful to look at the
% translational and rotational manipulability separately.
%
% See also SerialLink.inertia, SerialLink.jacob0.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 [w,mx] = maniplty(robot, q, varargin)
n = robot.n;
opt.yoshikawa = true;
opt.asada = false;
opt.axes = {'all', 'T', 'R'};
opt = tb_optparse(opt, varargin);
if length(q) == robot.n,
q = q(:)';
end
w = [];
MX = [];
if opt.yoshikawa
for Q = q',
w = [w; yoshi(robot, Q, opt)];
end
elseif opt.asada
for Q = q',
if nargout > 1
[ww,mm] = asada(robot, Q);
w = [w; ww];
MX = cat(3, MX, mm);
else
w = [w; asada(robot, Q, opt)];
end
end
end
if nargout > 1
mx = MX;
end
function m = yoshi(robot, q, opt)
J = jacob0(robot, q);
switch opt.axes
case 'T'
J = J(1:3,:);
case 'R'
J = J(4:6,:);
end
m = sqrt(det(J * J'));
function [m, mx] = asada(robot, q, opt)
J = jacob0(robot, q);
if rank(J) < 6,
warning('robot is in degenerate configuration')
m = 0;
return;
end
switch opt.axes
case 'T'
J = J(1:3,:)
case 'R'
J = J(4:6,:);
end
Ji = inv(J);
M = inertia(robot, q);
Mx = Ji' * M * Ji;
e = eig(Mx(1:3,1:3));
m = min(e) / max(e);
if nargout > 1
mx = Mx;
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
inertia.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/inertia.m
| 1,944 |
utf_8
|
4bda3471b7775960cef1f31a8b0b2dcb
|
%SerialLink.INERTIA Manipulator inertia matrix
%
% I = R.inertia(Q) is the NxN symmetric joint inertia matrix which relates
% joint torque to joint acceleration for the robot at joint configuration Q.
% The diagonal elements I(j,j) are the inertia seen by joint actuator j.
% The off-diagonal elements are coupling inertias that relate acceleration
% on joint i to force/torque on joint j.
%
% If Q is a matrix (DxN), each row is interpretted as a joint state
% vector, and the result (NxNxD) is a 3d-matrix where each plane corresponds
% to the inertia for the corresponding row of Q.
%
% See also SerialLink.RNE, SerialLink.CINERTIA, SerialLink.ITORQUE.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 M = inertia(robot, q)
if numcols(q) ~= robot.n
error('q must have %d columns', robot.n);
end
if numrows(q) > 1
M = [];
for i=1:numrows(q)
M = cat(3, M, robot.inertia(q(i,:)));
end
return
end
n = robot.n;
if numel(q) == robot.n,
q = q(:)';
end
M = zeros(n,n,0);
for Q = q',
m = rne(robot, ones(n,1)*Q', zeros(n,n), eye(n), [0;0;0]);
M = cat(3, M, m);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
fdyn.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@SerialLink/fdyn.m
| 3,481 |
utf_8
|
2cf029c0bca1d90d2a4cb9ea9ed78ddb
|
%SerialLink.fdyn Integrate forward dynamics
%
% [T,Q,QD] = R.fdyn(T1, TORQFUN) integrates the dynamics of the robot over
% the time interval 0 to T and returns vectors of time TI, joint position Q
% and joint velocity QD. The initial joint position and velocity are zero.
% The torque applied to the joints is computed by the user function TORQFUN:
%
% [TI,Q,QD] = R.fdyn(T, TORQFUN, Q0, QD0) as above but allows the initial
% joint position and velocity to be specified.
%
% The control torque is computed by a user defined function
%
% TAU = TORQFUN(T, Q, QD, ARG1, ARG2, ...)
%
% where Q and QD are the manipulator joint coordinate and velocity state
% respectively], and T is the current time.
%
% [T,Q,QD] = R.fdyn(T1, TORQFUN, Q0, QD0, ARG1, ARG2, ...) allows optional
% arguments to be passed through to the user function.
%
% Note::
% - This function performs poorly with non-linear joint friction, such as
% Coulomb friction. The R.nofriction() method can be used to set this
% friction to zero.
% - If TORQFUN is not specified, or is given as 0 or [], then zero torque
% is applied to the manipulator joints.
% - The builtin integration function ode45() is used.
%
% See also SerialLink.accel, SerialLink.nofriction, SerialLink.RNE, ode45.
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 [t, q, qd] = fdyn(robot, t1, torqfun, q0, qd0, varargin)
global __fdyn_robot;
global __fdyn_torqfun;
n = robot.n;
if nargin == 2
torqfun = 0;
q0 = zeros(1,n);
qd0 = zeros(1,n);
elseif nargin == 3
q0 = zeros(1,n);
qd0 = zeros(1,n);
elseif nargin == 4
qd0 = zeros(1,n);
end
% concatenate q and qd into the initial state vector
x0= [q0(:); qd0(:)];
__fdyn_robot = robot;
__fdyn_torqfun = torqfun;
dt = t1/100;
t = 0:dt:t1;
y = lsode(@fdyn2, x0, t);
t = t'
q = y(:,1:n);
qd = y(:,n+1:2*n);
%FDYN2 private function called by FDYN
%
% XDD = FDYN2(T, X, FLAG, ROBOT, TORQUEFUN)
%
% Called by FDYN to evaluate the robot velocity and acceleration for
% forward dynamics. T is the current time, X = [Q QD] is the state vector,
% ROBOT is the object being integrated, and TORQUEFUN is the string name of
% the function to compute joint torques and called as
%
% TAU = TORQUEFUN(T, X)
%
% if not given zero joint torques are assumed.
%
% The result is XDD = [QD QDD].
function xd = fdyn2(x, t)
global __fdyn_robot;
global __fdyn_torqfun;
robot = __fdyn_robot;
torqfun = __fdyn_torqfun;
n = robot.n;
q = x(1:n);
qd = x(n+1:2*n);
if isstr(torqfun)
tau = feval(torqfun, t, q, qd);
else
tau = zeros(n,1)';
end
qdd = accel(robot, x(1:n,1)', x(n+1:2*n,1)', tau);
xd = [x(n+1:2*n,1); qdd];
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
dot.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@Quaternion/dot.m
| 979 |
utf_8
|
20a6e25089ef3d09abe3812e3c78ad39
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 qd = dot(q, omega)
E = q.s*eye(3,3) - skew(q.v);
omega = omega(:);
qd = Quaternion(-0.5*q.v*omega, 0.5*E*omega);
end
|
github
|
RobinAmsters/GT_mobile_robotics-master
|
norm.m
|
.m
|
GT_mobile_robotics-master/common/rvctools/robot/Octave/@Quaternion/norm.m
| 1,016 |
utf_8
|
03b88aa052109c5e5daca5fae9986aee
|
% Ryan Steindl based on Robotics Toolbox for MATLAB (v6 and v9)
%
% Copyright (C) 1993-2011, 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 n = norm(q)
%Quaternion.norm Compute the norm of a quaternion
%
% QN = Q.norm(Q) is the scalar norm or magnitude of the quaternion Q.
n = norm(double(q));
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.