function [Vin,Iin,PinWatts,PoutHP,EtaMotor,ifig]=MotorInputs(PoutWatts,RPM,Kv,Kt,R,Io,ifig)
%function [Vin,Iin,PinWatts,PoutHP,EtaMotor,ifig]=MotorInputs(PoutWatts,RPM,Kv,Kt,R,Io,ifig)
% Computes Vin(volts), Iin(amperes) from PoutWatts(watts), RPM(rpm).
% Requires motor constants Kv,Kt,R,Io.
%   Kv= RPM/volt
%   Kt= inch-ounce per ampere
%   R= Ohms
%   Io= amperes
%
% ifig in the current figure number and is not used in this function.

KvKt=12*16*60/(2*pi*1.355818); % This is by definition
Kt=KvKt/Kv;  % Doing this improves accuracy
Poutftlbfsec=PoutWatts/1.355818; % ft-lbf/sec
Omegarps=RPM*2*pi/60;          % radians per sec
Torqueftlbf=Poutftlbfsec/Omegarps; % ft-lbf
Torqueozin=Torqueftlbf*12*16;      % oz-in
Iin=Torqueozin/Kt+Io; % amps
Vin=RPM/Kv+Iin*R; % volts
PinWatts=Iin*Vin; % watts
PoutHP=PoutWatts/745.7; % Convert output power from watts to hp
EtaMotor=PoutWatts/PinWatts; % non-dimensional

