function base_speed = mcb_getBaseSpeed(pmsm,inverter,varargin)
% mcb_getBaseSpeed   Compute base speed for PMSM
% 
%   mcb_getBaseSpeed calculates the base speed for PMSM at rated voltage and
%   rated load. This is helpful in control algorithm development for the motor. 
% 
%   base_speed = mcb_getBaseSpeed(pmsm,inverter) returns the base speed for 
%   the given combination of PMSM and Inverter using approximate equations. 
%   base_speed = mcb_getBaseSpeed(pmsm,inverter,"actual") returns the base speed for 
%   the given combination of PMSM and Inverter using actual equations.
%   The function accepts following inputs:
%   a pmsm object, an inverter object, and an optional argument 'actual'
%
% See also mcbPMSMCharacteristics, mcbPMSMSpeeds


% Copyright 2020-2022 The MathWorks, Inc.

%%
p = inputParser;
addRequired(p,'pmsm',@(x) (isstruct(x)&&min(isfield(x,{'p','Rs','Ld','Lq','FluxPM','B','I_rated'}))) || (all(cellfun(@(y) isprop(x,y),{'p','Rs','Ld','Lq','FluxPM','B','I_rated'}))));
addRequired(p,'inverter',@(x) isstruct(x)&&min(isfield(x,{'V_dc'})));
addOptional(p,'voltEqn','approximate',@(x) any(ismember(lower(x),{'actual','approximate'})));
parse(p,pmsm,inverter,varargin{:});
warning('off','MATLAB:structOnObject');
pmsm=struct(p.Results.pmsm);
warning('on','MATLAB:structOnObject');
inverter=p.Results.inverter;
voltEqn=p.Results.voltEqn;

milestone_speeds=mcbPMSMSpeeds(pmsm,inverter,voltageEquation=voltEqn);
base_speed=milestone_speeds(1);

end