function [EssStep,Kp,EssRamp,Kv,EssParabola,Ka,type]=ErrorConst(SISOsys)
% function [EssStep,Kp,EssRamp,Kv,EssParabola,Ka,type]=ErrorConst(SISOsys)
% SISOsys is a single input single output open loop system to be
% placed in a unity feedback situation.
% EssStep is the steady state error to a step input.
% Kp is the static position error.
% EssRamp is the steady state error to a unit ramp output.
% Kv is the static velocity error constant.
% Essparabola is the steady state output to a unit parabolic input.
% Ka is the static acceleration error constant.
% type is the type of the system (the number of free s in the denominator).
% Pole zero cancellations are removed first by minreal.

% SYSr = MINREAL(SYS)
SISOsysR=minreal(SISOsys);
% [NUM,DEN] = TFDATA(SYS,'v')
[num,den]=tfdata(SISOsysR,'v');
jzero=find(den==0);
jnonzero=find(den~=0);
lastnonzero=jnonzero(length(jnonzero));
j3=find(jzero>lastnonzero);
type=length(j3);

den0=den(length(den));

% Position errors
if den0==0
	Kp=Inf;
	EssStep=0;
else
	Kp=num(length(num))/den0;
	EssStep=1/(1+Kp);
end

% Velocity errors
if den(length(den))==0;
	den2=den(1:(length(den)-1));
	num2=num;
else
	den2=den;
	num2=[num 0];
end
%num2
%den2

den20=den2(length(den2));
if den20==0
	Kv=Inf;
	EssRamp=0;
else
	Kv=num2(length(num2))/den20;
	EssRamp=1/Kv;
end

% Acceleration errors
if den2(length(den2))==0;
	den3=den2(1:(length(den2)-1));
	num3=num2;
else
	den3=den2;
	num3=[num2 0];
end

%num3
%den3
den30=den3(length(den3));
if den30==0
	Ka=Inf;
	EssParabola=0;
else
	Ka=num3(length(num3))/den30;
	if Ka==0; EssParabola=Inf; else EssParabola=1/Ka; end
end
