clc
clear
close all

%% estimated parameters

J_spool_est = 0.00024541;
k_fv_spool_est = 7.3202e-05;

%% parameters

tau_sp1 = 0.3778;
tau_sp2 = 0.2807;
tau_sp3 = 0.4529;

% simulink

Ts = 1e-3;
ticks = 2048;
phi = 2*pi/ticks/4; 
n_max = 2000;

% ultrasonic sensor

phi_max = deg2rad(21.9);        % max value of phi [rad]
u_max = 5;                      % max value of sensor output [V]

% Ud = 13.00 V
u_la_min = 2.42;
u_la_mid = 5.58;
u_la_amp = u_la_mid - u_la_min;

sensor_gain_us = phi_max/u_max;    % gain costant for volts to radians conversion
sensor_gain_la = phi_max/u_la_amp;

% DC motor

k_fd = 7e-3;                    % dry friction
k_fv = (2*pi/60)*1.5e-6;        % viscous friction

J_rotor = 380e-7;
k_torque = 63.6e-3;
k_emf = 0.064;

R_a = 1.4;
L_a = 1.7e-3;

J_spool = 0;
k_fv_spool = 0;
k_fd_spool = 0;

% regulator

duty_max = 0.9;
duty_min = 0.1;
action_max = 3500; %rpm 
regulator_gain = (duty_max-duty_min)/action_max;