function [iae_r tv_r] = simrun(kc, ti, type, plot_on)

global gc stepvalue disturbancevalue t y r

if type == 1
    stepvalue = 1;       %    Activating the step
    disturbancevalue= 0; %    Deactivating the disturbance
elseif type == 2
    stepvalue = 0;       %  Deactivating the step
    disturbancevalue= 1; %   Activating the disturbance
else
    disp('Error: Not a correct simulation type input')
    return
end
    
    
    gc = controller(1,kc,ti); % Retrieves the controller tf
    
    sim('system_model')     % Running the simulation in simulink
    
    iae_r = iae(t,e);  % Using the funtion iae to calculate 
                        % the absolute integrated error (iae) for the 
                        % setpoint responce
    
    tv_r  = tv(u);     % Using the funtion tv to calculate the total
                
   
if plot_on == 1
    if type == 1 
        figure(1)
            subplot(3,1,2)
            plot(t,y,t,r);
            title('Setpoint Responce')
    elseif type == 2
        figure(1)
            subplot(3,1,3);
            plot(t,y,t,r);
            title('Disturbance Responce')
    end
end
   

    
end