function [necessary_gear]=necessary_gear_calculator(curr_speed,percent_throttle)
% curr_speed -> Valor da velocidade actual, em [km/hr];
% percent_throttle -> Valor da aceleração actual.


% curr_speed=10
% percent_throttle=0

curve_throttle_1_2=[0,30,65,100];
curve_throttle_2_3=[0,35,70,100];
curve_throttle_3_4=[0,30,70,100];
curve_throttle_4_5=[0,30,75,100];

curve_speed_1_2=[40,40,50,50];
curve_speed_2_3=[50,50,65,65];
curve_speed_3_4=[60,60,75,75];
curve_speed_4_5=[75,75,100,100];

%plot(curve_throttle_1_2,curve_speed_1_2,'r');
%hold on
%plot(curve_throttle_2_3,curve_speed_2_3,'g');
%plot(curve_throttle_3_4,curve_speed_3_4,'b');
%plot(curve_throttle_4_5,curve_speed_4_5,'k');

% Vector de nterpolações:
k=[interp1(curve_throttle_1_2,curve_speed_1_2,percent_throttle),interp1(curve_throttle_2_3,curve_speed_2_3,percent_throttle),interp1(curve_throttle_3_4,curve_speed_3_4,percent_throttle),interp1(curve_throttle_4_5,curve_speed_4_5,percent_throttle)];
gears=[1,2,3,4];

necessary_gear=ceil(interp1(k,gears,curr_speed));
if curr_speed>max(k)
    necessary_gear=5;
elseif curr_speed<min(k)
    necessary_gear=1;
end