function [max_speed] = mcbPMSMMaxSpeed(pmsm,inverter,varargin)
% mcbPMSMMaxSpeed   Compute the maximum achievable speed for PMSM
%
%   mcbPMSMMaxSpeed calculates the maximum achievable speed for PMSM
%  with no-load at rated DC bus voltage. This is helpful in control
%  algorithm development.
%
%   max_speed = mcbPMSMMaxSpeed(pmsm,inverter) returns the maximum
%  achievable speed (rpm) for the given combination of PMSM and Inverter.
%   
%   The function accepts following inputs: a pmsm object and an inverter
%  object, and an optional name-value pairs. The possible name-value pairs
%  are the following (default value is mentioned first):
%        'voltageEquation'        -> 'actual' or 'approximate'
%        'FWCMethod'              -> 'vclmt' or 'none' or 'cvcp' or 'cccp'
%
%    To use the actual voltage equations, use 'voltageEquation' and 'actual'
%   as the optional name value pair arguments. To use approximate voltage
%   equations, use 'approximate' as the value.
% 		actual equations:
% 			vd=id*r-w*Lq*iq; vq=iq*r+w*Ld*id+w*fluxPM; Vmax=Vdc/sqrt(3);
% 		approximate equations:
% 			vd=-w*Lq*iq; vq=w*Ld*id+w*fluxPM; Vmax=(Vdc/sqrt(3))-irated*r;
%    Optional argument for SPMSM is 'FWCMethod' followed by
%   'cvcp' implements constant-voltage-constant-power method for FW region,
%   'cccp' implements constant-current-constant-power method for FW region,
%   'none' implements no field weakening. The (default) optional value
%   'vclmt' implements voltage-current-limited-maximum-torque method
%   for FW region. The option is set to vclmt for the IPMSM type machines.
%
%   Example:
%       inverter = mcb_SetInverterParameters( 'BoostXL-DRV8305');
%       pmsm     = mcb_SetPMSMMotorParameters('BLY171D');
%       disp(mcbPMSMMaxSpeed(pmsm,inverter,"voltageEquation","actual", ...
%           "FWCMethod","vclmt"))
%
% See also mcbPMSMCharacteristics, mcbPMSMSpeeds

%   Copyright 2022 The MathWorks, Inc.

%%

[milestone_speeds] = mcb.internal.PMSMSpeedComputation(pmsm,inverter,varargin{:});
max_speed=milestone_speeds(end);

