New function argument validation method
This commit is contained in:
		@@ -1,32 +1,28 @@
 | 
			
		||||
function [stewart] = generateCubicConfiguration(stewart, opts_param)
 | 
			
		||||
% generateCubicConfiguration -
 | 
			
		||||
function [stewart] = generateCubicConfiguration(stewart, args)
 | 
			
		||||
% generateCubicConfiguration - Generate a Cubic Configuration
 | 
			
		||||
%
 | 
			
		||||
% Syntax: [stewart] = generateCubicConfiguration(stewart, opts_param)
 | 
			
		||||
% Syntax: [stewart] = generateCubicConfiguration(stewart, args)
 | 
			
		||||
%
 | 
			
		||||
% Inputs:
 | 
			
		||||
%    - stewart - the Stewart struct should have a parameter "H" corresponding to the total height of the platform
 | 
			
		||||
%    - opts_param - Structure with the following parameters
 | 
			
		||||
%    - stewart - A structure with the following fields
 | 
			
		||||
%        - H   [1x1] - Total height of the platform [m]
 | 
			
		||||
%    - args - Can have the following fields:
 | 
			
		||||
%        - Hc  [1x1] - Height of the "useful" part of the cube [m]
 | 
			
		||||
%        - FOc [1x1] - Height of the center of the cute with respect to {F} [m]
 | 
			
		||||
%        - FHa [1x1] - Height of the plane joining the points ai with respect to the frame {F} [m]
 | 
			
		||||
%        - MHb [1x1] - Height of the plane joining the points bi with respect to the frame {M} [m]
 | 
			
		||||
%
 | 
			
		||||
% Outputs:
 | 
			
		||||
%    - stewart - updated Stewart structure with the added parameters:
 | 
			
		||||
%        - Fa [3x6] - Its i'th column is the position vector of joint ai with respect to {F}
 | 
			
		||||
%        - Mb [3x6] - Its i'th column is the position vector of joint bi with respect to {M}
 | 
			
		||||
%    - stewart - updated Stewart structure with the added fields:
 | 
			
		||||
%        - Fa  [3x6] - Its i'th column is the position vector of joint ai with respect to {F}
 | 
			
		||||
%        - Mb  [3x6] - Its i'th column is the position vector of joint bi with respect to {M}
 | 
			
		||||
 | 
			
		||||
opts = struct(  ...
 | 
			
		||||
  'Hc',  60e-3, ... % [m]
 | 
			
		||||
  'FOc', 50e-3, ... % [m]
 | 
			
		||||
  'FHa', 15e-3, ... % [m]
 | 
			
		||||
  'MHb', 15e-3  ... % [m]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
if exist('opts_param','var')
 | 
			
		||||
    for opt = fieldnames(opts_param)'
 | 
			
		||||
        opts.(opt{1}) = opts_param.(opt{1});
 | 
			
		||||
    end
 | 
			
		||||
arguments
 | 
			
		||||
    stewart
 | 
			
		||||
    args.Hc  (1,1) double {mustBeNumeric, mustBePositive} = 60e-3
 | 
			
		||||
    args.FOc (1,1) double {mustBeNumeric, mustBePositive} = 50e-3
 | 
			
		||||
    args.FHa (1,1) double {mustBeNumeric, mustBePositive} = 15e-3
 | 
			
		||||
    args.MHb (1,1) double {mustBeNumeric, mustBePositive} = 15e-3
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
sx = [ 2; -1; -1];
 | 
			
		||||
@@ -35,14 +31,14 @@ sz = [ 1;  1;  1];
 | 
			
		||||
 | 
			
		||||
R = [sx, sy, sz]./vecnorm([sx, sy, sz]);
 | 
			
		||||
 | 
			
		||||
L = opts.Hc*sqrt(3);
 | 
			
		||||
L = args.Hc*sqrt(3);
 | 
			
		||||
 | 
			
		||||
Cc = R'*[[0;0;L],[L;0;L],[L;0;0],[L;L;0],[0;L;0],[0;L;L]] - [0;0;1.5*opts.Hc];
 | 
			
		||||
Cc = R'*[[0;0;L],[L;0;L],[L;0;0],[L;L;0],[0;L;0],[0;L;L]] - [0;0;1.5*args.Hc];
 | 
			
		||||
 | 
			
		||||
CCf = [Cc(:,1), Cc(:,3), Cc(:,3), Cc(:,5), Cc(:,5), Cc(:,1)]; % CCf(:,i) corresponds to the bottom cube's vertice corresponding to the i'th leg
 | 
			
		||||
CCm = [Cc(:,2), Cc(:,2), Cc(:,4), Cc(:,4), Cc(:,6), Cc(:,6)]; % CCm(:,i) corresponds to the top cube's vertice corresponding to the i'th leg
 | 
			
		||||
 | 
			
		||||
CSi = (CCm - CCf)./vecnorm(CCm - CCf);
 | 
			
		||||
 | 
			
		||||
stewart.Fa = CCf + [0; 0; opts.FOc] + ((opts.FHa-(opts.FOc-opts.Hc/2))./CSi(3,:)).*CSi;
 | 
			
		||||
stewart.Mb = CCf + [0; 0; opts.FOc-stewart.H] + ((stewart.H-opts.MHb-(opts.FOc-opts.Hc/2))./CSi(3,:)).*CSi;
 | 
			
		||||
stewart.Fa = CCf + [0; 0; args.FOc] + ((args.FHa-(args.FOc-args.Hc/2))./CSi(3,:)).*CSi;
 | 
			
		||||
stewart.Mb = CCf + [0; 0; args.FOc-stewart.H] + ((stewart.H-args.MHb-(args.FOc-args.Hc/2))./CSi(3,:)).*CSi;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
function [stewart] = initializeFramesPositions(opts_param)
 | 
			
		||||
function [stewart] = initializeFramesPositions(args)
 | 
			
		||||
% initializeFramesPositions - Initialize the positions of frames {A}, {B}, {F} and {M}
 | 
			
		||||
%
 | 
			
		||||
% Syntax: [stewart] = initializeFramesPositions(H, MO_B)
 | 
			
		||||
% Syntax: [stewart] = initializeFramesPositions(args)
 | 
			
		||||
%
 | 
			
		||||
% Inputs:
 | 
			
		||||
%    - opts_param - Structure with the following fields:
 | 
			
		||||
%    - args - Can have the following fields:
 | 
			
		||||
%        - H    [1x1] - Total Height of the Stewart Platform [m]
 | 
			
		||||
%        - MO_B [1x1] - Height of the frame {B} with respect to {M} [m]
 | 
			
		||||
%
 | 
			
		||||
@@ -15,23 +15,17 @@ function [stewart] = initializeFramesPositions(opts_param)
 | 
			
		||||
%        - MO_B [3x1] - Position of {B} with respect to {M} [m]
 | 
			
		||||
%        - FO_A [3x1] - Position of {A} with respect to {F} [m]
 | 
			
		||||
 | 
			
		||||
opts = struct(   ...
 | 
			
		||||
  'H',    90e-3, ... % [m]
 | 
			
		||||
  'MO_B', 50e-3  ... % [m]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
if exist('opts_param','var')
 | 
			
		||||
    for opt = fieldnames(opts_param)'
 | 
			
		||||
        opts.(opt{1}) = opts_param.(opt{1});
 | 
			
		||||
    end
 | 
			
		||||
arguments
 | 
			
		||||
    args.H    (1,1) double {mustBeNumeric, mustBePositive} = 90e-3
 | 
			
		||||
    args.MO_B (1,1) double {mustBeNumeric, mustBePositive} = 50e-3
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
stewart = struct();
 | 
			
		||||
 | 
			
		||||
stewart.H = opts.H; % Total Height of the Stewart Platform [m]
 | 
			
		||||
stewart.H = args.H; % Total Height of the Stewart Platform [m]
 | 
			
		||||
 | 
			
		||||
stewart.FO_M = [0; 0; stewart.H]; % Position of {M} with respect to {F} [m]
 | 
			
		||||
 | 
			
		||||
stewart.MO_B = [0; 0; opts.MO_B]; % Position of {B} with respect to {M} [m]
 | 
			
		||||
stewart.MO_B = [0; 0; args.MO_B]; % Position of {B} with respect to {M} [m]
 | 
			
		||||
 | 
			
		||||
stewart.FO_A = stewart.MO_B + stewart.FO_M; % Position of {A} with respect to {F} [m]
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
function [stewart] = initializeStrutDynamics(stewart, opts_param)
 | 
			
		||||
function [stewart] = initializeStrutDynamics(stewart, args)
 | 
			
		||||
% initializeStrutDynamics - Add Stiffness and Damping properties of each strut
 | 
			
		||||
%
 | 
			
		||||
% Syntax: [stewart] = initializeStrutDynamics(opts_param)
 | 
			
		||||
% Syntax: [stewart] = initializeStrutDynamics(args)
 | 
			
		||||
%
 | 
			
		||||
% Inputs:
 | 
			
		||||
%    - opts_param - Structure with the following fields:
 | 
			
		||||
%    - args - Structure with the following fields:
 | 
			
		||||
%        - Ki [6x1] - Stiffness of each strut [N/m]
 | 
			
		||||
%        - Ci [6x1] - Damping of each strut [N/(m/s)]
 | 
			
		||||
%
 | 
			
		||||
@@ -13,16 +13,11 @@ function [stewart] = initializeStrutDynamics(stewart, opts_param)
 | 
			
		||||
%        - Ki [6x1] - Stiffness of each strut [N/m]
 | 
			
		||||
%        - Ci [6x1] - Damping of each strut [N/(m/s)]
 | 
			
		||||
 | 
			
		||||
opts = struct(  ...
 | 
			
		||||
  'Ki', 1e6*ones(6,1), ... % [N/m]
 | 
			
		||||
  'Ci', 1e2*ones(6,1)  ... % [N/(m/s)]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
if exist('opts_param','var')
 | 
			
		||||
    for opt = fieldnames(opts_param)'
 | 
			
		||||
        opts.(opt{1}) = opts_param.(opt{1});
 | 
			
		||||
    end
 | 
			
		||||
arguments
 | 
			
		||||
    stewart
 | 
			
		||||
    args.Ki (6,1) double {mustBeNumeric, mustBePositive} = 1e6*ones(6,1)
 | 
			
		||||
    args.Ci (6,1) double {mustBeNumeric, mustBePositive} = 1e2*ones(6,1)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
stewart.Ki = opts.Ki;
 | 
			
		||||
stewart.Ci = opts.Ci;
 | 
			
		||||
stewart.Ki = args.Ki;
 | 
			
		||||
stewart.Ci = args.Ci;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user