Menu

Error: The integration routine stopped as the required accuracy can not be obtained

2018-11-21
2022-08-02
  • Derek Biega

    Derek Biega - 2018-11-21

    I am using the ACADO toolkit to minimize the time for a small aircraft to go from takeoff to cruise. I have 4 differential states: velocity, range, height, and flight path angle, and 1 control: u. When I run the code, I get an error:

    [ACADO] Error: The integration routine stopped as the required accuracy can not be obtained
    Code: (RET_UNSUCCESSFUL_RETURN_FROM_INTEGRATOR_RK45)

    Consequently, I also get several other errors stating that the NLP Solver Fails, and that the initialization of the optimization algorithm failed. I'm not exactly sure what I am doing wrong that the algorithm is not working. This is my first time using ACADO, and I am struggling to find good resources. Code below:

    BEGIN_ACADO;                                % Always start with "BEGIN_ACADO".
    
        acadoSet('problemname', 'stackOverflow');
    
        DifferentialState v;                    % Velocity [m/s]
        DifferentialState r;                    % Range [m]
        DifferentialState h;                    % Height [m]
        DifferentialState gamma;                % Flight Path Angle [deg]
        Parameter T;                            % Minimize Time
        Control u;                              % Control input = Pitch angle
    
        alpha = minus(u,gamma);            % Angle of attack [deg]
        thrust = mtimes(plus(.0088,mtimes(.000842,mtimes(alpha,pi/180))),v^2);   % Thrust [N]
        m = double(4.2);                  % mass [kg]
        g = double(9.81);                 % gravity [m/s^2]
    
        %% Diferential Equation
        f = acado.DifferentialEquation(0, T);   % Set the differential equation object
    
        % Write down the ODE
        f.add(dot(v) == (1/m)*(thrust*cos(alpha)-thrust-(m*g*sin(gamma))));
        f.add(dot(r) == v*cos(gamma));                   
        f.add(dot(h) == v*sin(gamma));            
        f.add(dot(gamma) == 1/(m*v)*(thrust*sin(alpha)-thrust-m*g*sin(gamma)));
    
        %% Optimal Control Problem
        ocp = acado.OCP(0.0, T);                % Set up the Optimal Control Problem (OCP)                                    
        ocp.minimizeMayerTerm(T);               % Minimize the consumed energy
        ocp.subjectTo( f );                     % Optimize w.r.t your differential equation
    
        ocp.subjectTo( 'AT_START', r ==  0.0 );  % r(0) = 0
        ocp.subjectTo( 'AT_START', v ==  0.0 );  % v(0) = 0
        ocp.subjectTo( 'AT_START', h ==  10.0 ); % h(0) = 1
        ocp.subjectTo( 'AT_START', gamma ==  0.0 ); % gamma(0) = 1
    
        ocp.subjectTo( 'AT_END'  , h == 61.0 ); % h(T) = Cruise Altitude
        ocp.subjectTo( 'AT_END'  , v == 24.0 ); % v(T) = Cruise Velocity
        ocp.subjectTo( 'AT_END'  , gamma == 0.0 ); % gamma(T) = Cruise Flight Angle
    
        ocp.subjectTo( 14.013 <= v <= 27.0 );       % path constraint on speed
        ocp.subjectTo( 0 <= v*sin(gamma) <= 3.33 ); % Restrict the max. rate of climb
        ocp.subjectTo( 3 <= alpha <= 3.3 );     % Possible cruise windows for stability
    
        %% Optimization Algorithm
        algo =acado.OptimizationAlgorithm(ocp); % Set up the optimization algorithm, link it to your OCP
        algo.set( 'KKT_TOLERANCE', 1e-8 );     % Set a custom KKT tolerance
    
    END_ACADO;
    
    % Run the test
    out = stackOverflow_RUN();
    
     
  • Derek Biega

    Derek Biega - 2018-11-21

    To add to this post, the cost function I am trying to solve is below. I suspect that I am using the incorrect method to solve this, as there is nowhere to define the weighted matrices, but I still do not understand why my program is failing. The insert image functionality does not seem to work in these forums, so the imgur link below is a way to see the cost function.
    https://imgur.com/a/wAJAm89

     

    Last edit: Derek Biega 2018-11-21
  • Derek Biega

    Derek Biega - 2018-11-21

    I've also tried implementing this function using LSQ, and am receiving the exact same error. I have no idea what could be wrong. here is that altered code:

    clear; clc; close all;
    
    BEGIN_ACADO;                                % Always start with "BEGIN_ACADO". 
    
        acadoSet('problemname', 'stackOverflow');
    
        DifferentialState v;                    % Velocity [m/s]
        DifferentialState r;                    % Range [m]
        DifferentialState h;                    % Height [m]
        DifferentialState gamma;                % Flight Path Angle [deg]
    
        Parameter T;                            % We would like to minize the T, so T is a parameter
    
        Control u;                              % Control input = Pitch angle [deg]
    
        alpha = minus(u,gamma);            % Angle of attack [deg] ( will be constrained)
        thrust = mtimes(plus(.0088,mtimes(.000842,mtimes(alpha,pi/180))),v^2);   % Thrust [N]
        m = 4.2;                  % mass [kg]
        g = 9.81;                 % gravity [m/s^2]
    
        %% Diferential Equation
        f = acado.DifferentialEquation(0, T);   % Set the differential equation object. We would like to minize the time.
        f.linkMatlabODE('ode');             % Link to a Matlab ODE
    
        %% Optimal Control Problem
        ocp = acado.OCP(0.0, T, 50);    % Set up the Optimal Control Problem (OCP)
                                        % Start at 0, go to T, 50 intervals
    
        Q = [.01 0 0 0; 0 1 0 0; 0 0 0 0; 0 0 0 0];
        obj = {v, r, h, gamma};                     % the LSQ-Function
        R = zeros(1,4);                         % The reference
    
        ocp.minimizeLSQ( Q, obj, R );             % Minimize this Least Squares Term
        ocp.subjectTo( f );                     % Optimize with respect to your differential equation
    
        ocp.subjectTo( 'AT_START', r ==  0.0 );  % r(0) = 0
        ocp.subjectTo( 'AT_START', v ==  0.0 );  % v(0) = 0
        ocp.subjectTo( 'AT_START', h ==  10.0 ); % h(0) = 1
        ocp.subjectTo( 'AT_START', gamma ==  0.0 ); % gamma(0) = 1
    
        ocp.subjectTo( 'AT_END'  , h == 61.0 ); % h(T) = Cruise Altitude
        ocp.subjectTo( 'AT_END'  , v == 24.0 ); % v(T) = Cruise Velocity
        ocp.subjectTo( 'AT_END'  , gamma == 0.0 ); % gamma(T) = Cruise Flight (Should be 0 at cruise)
    
        ocp.subjectTo( 14.013 <= v <= 27.0 );       % path constraint on speed
        ocp.subjectTo( 0 <= v*sin(gamma) <= 3.33 ); % Restrict the max. rate of climb
        ocp.subjectTo( 3 <= alpha <= 3.3 );     % Possible cruise windows for stability
    
        %% Optimization Algorithm
        algo = acado.OptimizationAlgorithm(ocp); % Set up the optimization algorithm, link it to your OCP
        algo.set( 'INTEGRATOR_TOLERANCE', 1e-8 );     % Set a custom KKT tolerance
        algo.set( 'KKT_TOLERANCE', 1e-4 );     % Set a custom KKT tolerance
    
    END_ACADO;     
    
    % Run the test
    out = stackOverflowTest_RUN();    
    

    Full error output:
    [ACADO] Error: The integration routine stopped as the required accuracy can not be obtained
    Code: (RET_UNSUCCESSFUL_RETURN_FROM_INTEGRATOR_RK45)
    File: C:\Users\djbie\ACADOtoolkit\acado\integrator\integrator_runge_kutta.cpp
    Line: 1394

    [ACADO] Error: Initialization of NLP solver failed
    Code: (RET_UNABLE_TO_INTEGRATE_SYSTEM)
    File: C:\Users\djbie\ACADOtoolkit\acado\dynamic_discretization\shooting_method.cpp
    Line: 279

    [ACADO] Error: Initialization of NLP solver failed
    Code: (RET_NLP_INIT_FAILED)
    File: C:\Users\djbie\ACADOtoolkit\acado\nlp_solver\scp_method.cpp
    Line: 217

    [ACADO] Error: Initialization of optimization algorithm failed
    Code: (RET_OPTALG_INIT_FAILED)
    File: C:\Users\djbie\ACADOtoolkit\acado\optimization_algorithm\optimization_algorithm_base.cpp
    Line: 587

     
  • Derek Biega

    Derek Biega - 2018-11-21

    Update:

    So I've found out that this error is being triggered due to the values I select for my constraints. However, I do not understand why my selected values are flagging the system as such.

     
  • Imane

    Imane - 2019-02-19

    Hi,

    I actually receive the same errors as you. I don't know if you figured it out.

    Thank you!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.