function [delta_f, delta_r] = steer(kappa)
% INPUTS
ux = 25;         % speed [m/s]
%kappa = 1;      % curvature [1/m] 
%kappa = [0,.5,1]

% function params
ratio_max_force = .8;  % between 0 and .99, max allowed slip on tire curve
                       % Do NOT set to 1.0 or above
max_steer_angle = .43; % max steering angle [rad]                     

% tire params
c_f = 150000;   % [N/rad]
mu_f = .95;     % [unitless]
c_r = 150000;   % [N/rad]
mu_r = .95;      % [unitless]

% vehicle params
m = 2270;       % mass [kg]
a = 1.185;      % cg to front axle distance [m]
b = 1.185;      % cg to rear axle distance [m]


% ALGORITHM
% max steady state tire force
maxf_f = m * 9.81 * b / (b+a) * mu_f;
maxf_r = m * 9.81 * a / (b+a) * mu_r;

% generate front tire table
alpha_slide_f = abs(atan(3*maxf_f/c_f));
alpha_table_f = linspace(-alpha_slide_f,alpha_slide_f, 21);
ta = tan(alpha_table_f);
fy_table_f = -c_f.*ta + c_f^2.*abs(ta).*ta./(3*maxf_f) - c_f^3.*ta.^3./(27.*maxf_f^2); 

% generate rear tire table
alpha_slide_r = abs(atan(3*maxf_r/c_r));
alpha_table_r = linspace(-alpha_slide_r,alpha_slide_r, 21);
ta = tan(alpha_table_r);
fy_table_r = -c_r.*ta + c_r^2.*abs(ta).*ta./(3*maxf_r) - c_r^3.*ta.^3./(27.*maxf_r^2); 

% determine forces
fy_f = m * b / (a+b) * ux^2 .* kappa;
fy_r = m * a / (a+b) * ux^2 .* kappa;
fyf = mb/L * fyr / (ma/L)

% limit forces
if abs(fy_f) > ratio_max_force*maxf_f
    fy_f = ratio_max_force.*sign(fy_f) .* maxf_f;
end
if abs(fy_r) > maxf_r
    fy_r = ratio_max_force.*sign(fy_r) .* maxf_r;
end

% get alpha from force
alpha_f = interp1(fy_table_f, alpha_table_f, fy_f);
alpha_r = interp1(fy_table_r, alpha_table_r, fy_r);

% determine steering command

%b_ss = 0.0
%b_ss[i] = kappa*b
%b_ss[i] = 1.2 * alpha_r + (b + .2*a + .2*b)*kappa - .2*alpha_f
%b_ss[i] = b * kappa + alpha_r # 2ws

delta_f = kappa * a - alpha_f; % + b_ss 
delta_r = -kappa * b - alpha_f; % + b_ss %%% ALPHA_R

% limit steering angles
if abs(delta_f) > max_steer_angle
    delta_f = sign(delta_f) .* max_steer_angle;
end
if abs(delta_r) > max_steer_angle
    delta_r = sign(delta_r) .* max_steer_angle;
end
end
