示例#1
0
USING_NAMESPACE_ACADO

#include <mex.h>


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) 
 { 
 
    MatlabConsoleStreamBuf mybuf;
    RedirectStream redirect(std::cout, mybuf);
    clearAllStaticCounters( ); 
 
    mexPrintf("\nACADO Toolkit for Matlab - Developed by David Ariens and Rien Quirynen, 2009-2013 \n"); 
    mexPrintf("Support available at http://www.acadotoolkit.org/matlab \n \n"); 

    if (nrhs != 0){ 
      mexErrMsgTxt("This problem expects 0 right hand side argument(s) since you have defined 0 MexInput(s)");
    } 
 
    TIME autotime;
    DifferentialState xT;
    DifferentialState vT;
    DifferentialState xL;
    DifferentialState vL;
    DifferentialState uT;
    DifferentialState uL;
    DifferentialState phi;
    DifferentialState omega;
    Control duT;
    Control duL;
    DMatrix acadodata_M1;
    acadodata_M1.read( "crane_data_acadodata_M1.txt" );
    DMatrix acadodata_M2;
    acadodata_M2.read( "crane_data_acadodata_M2.txt" );
    SIMexport ExportModule1( 1, 0.2 );
    ExportModule1.set( GENERATE_MATLAB_INTERFACE, 1 );
    uint options_flag;
    options_flag = ExportModule1.set( INTEGRATOR_TYPE, INT_IRK_GL4 );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: INTEGRATOR_TYPE");
    options_flag = ExportModule1.set( DYNAMIC_SENSITIVITY, FORWARD );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: DYNAMIC_SENSITIVITY");
    options_flag = ExportModule1.set( NUM_INTEGRATOR_STEPS, 1 );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: NUM_INTEGRATOR_STEPS");
    DifferentialEquation acadodata_f1;
    acadodata_f1 << dot(phi) == omega;
    acadodata_f1 << dot(omega) == (-((-7.818238E+01)*vT+3.707268E+00*uT)*cos(phi)+(-9.810000E+00)*sin(phi)-2.000000E+00*omega*vL)/xL;

    ExportModule1.setLinearInput( acadodata_M1, acadodata_M2 );
    ExportModule1.setModel( acadodata_f1 );

    uint export_flag = 0;
    ExportModule1.setTimingSteps( 0 );
    export_flag = ExportModule1.exportCode( "sim_export" );
    if(export_flag != 0) mexErrMsgTxt("ACADO export failed because of the above error(s)!");


    clearAllStaticCounters( ); 
 
} 
示例#2
0
USING_NAMESPACE_ACADO

#include <mex.h>


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) 
 { 
 
    MatlabConsoleStreamBuf mybuf;
    RedirectStream redirect(std::cout, mybuf);
    clearAllStaticCounters( ); 
 
    mexPrintf("\nACADO Toolkit for Matlab - Developed by David Ariens and Rien Quirynen, 2009-2013 \n"); 
    mexPrintf("Support available at http://www.acadotoolkit.org/matlab \n \n"); 

    if (nrhs != 0){ 
      mexErrMsgTxt("This problem expects 0 right hand side argument(s) since you have defined 0 MexInput(s)");
    } 
 
    TIME autotime;
    DifferentialState u;
    DifferentialState v;
    DifferentialState w;
    DifferentialState p;
    DifferentialState q;
    DifferentialState r;
    DifferentialState phi;
    DifferentialState theta;
    DifferentialState intg_V;
    DifferentialState x_w2_uT;
    DifferentialState x_w2_uE;
    DifferentialState x_w2_uA;
    DifferentialState x_w2_uR;
    DifferentialState x_w2_sv;
    Control uT;
    Control uE;
    Control uA;
    Control uR;
    Control sv;
    OnlineData Aw2; 
    OnlineData Bw2; 
    OnlineData Cw2; 
    OnlineData Dw2; 
    OnlineData kiV; 
    BMatrix acadodata_M1;
    acadodata_M1.read( "nmpc_ext_data_acadodata_M1.txt" );
    BMatrix acadodata_M2;
    acadodata_M2.read( "nmpc_ext_data_acadodata_M2.txt" );
    OCP ocp1(0, 0.5, 10);
    ocp1.minimizeLSQ(acadodata_M1, "evaluateLSQ");
    ocp1.minimizeLSQEndTerm(acadodata_M2, "evaluateLSQEndTerm");
    ocp1.subjectTo(1.000000E-01 <= uT <= 1.000000E+00);
    ocp1.subjectTo((-3.490659E-01) <= uE <= 3.490659E-01);
    ocp1.subjectTo((-3.490659E-01) <= uA <= 3.490659E-01);
    ocp1.subjectTo((-3.490659E-01) <= uR <= 3.490659E-01);
    ocp1.subjectTo((-1.047198E+00) <= phi <= 1.047198E+00);
    ocp1.subjectTo((-7.853982E-01) <= theta <= 7.853982E-01);
    ocp1.subjectTo((-3.490659E-02) <= (atan(1/u*w)+sv));
    ocp1.subjectTo((atan(1/u*w)-sv) <= 1.745329E-01);
    ocp1.subjectTo(0.000000E+00 <= sv <= 5.235988E-02);
    ocp1.setNOD( 5 );
    ocp1.setNP( 0 );
    ocp1.setNU( 5 );
    ocp1.setModel( "model", "rhs", "rhs_jac" );
    ocp1.setDimensions( 0, 14, 0, 0, 0, 5, 5, 0 );


    OCPexport ExportModule1( ocp1 );
    ExportModule1.set( GENERATE_MATLAB_INTERFACE, 1 );
    uint options_flag;
    options_flag = ExportModule1.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: HESSIAN_APPROXIMATION");
    options_flag = ExportModule1.set( DISCRETIZATION_TYPE, MULTIPLE_SHOOTING );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: DISCRETIZATION_TYPE");
    options_flag = ExportModule1.set( SPARSE_QP_SOLUTION, FULL_CONDENSING );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: SPARSE_QP_SOLUTION");
    options_flag = ExportModule1.set( INTEGRATOR_TYPE, INT_IRK_GL4 );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: INTEGRATOR_TYPE");
    options_flag = ExportModule1.set( NUM_INTEGRATOR_STEPS, 10 );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: NUM_INTEGRATOR_STEPS");
    options_flag = ExportModule1.set( QP_SOLVER, QP_QPOASES );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: QP_SOLVER");
    options_flag = ExportModule1.set( HOTSTART_QP, NO );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: HOTSTART_QP");
    options_flag = ExportModule1.set( LEVENBERG_MARQUARDT, 1.000000E-10 );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: LEVENBERG_MARQUARDT");
    options_flag = ExportModule1.set( GENERATE_MAKE_FILE, YES );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: GENERATE_MAKE_FILE");
    options_flag = ExportModule1.set( GENERATE_TEST_FILE, YES );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: GENERATE_TEST_FILE");
    options_flag = ExportModule1.set( GENERATE_SIMULINK_INTERFACE, YES );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: GENERATE_SIMULINK_INTERFACE");
    options_flag = ExportModule1.set( CG_HARDCODE_CONSTRAINT_VALUES, YES );
    if(options_flag != 0) mexErrMsgTxt("ACADO export failed when setting the following option: CG_HARDCODE_CONSTRAINT_VALUES");
    uint export_flag;
    export_flag = ExportModule1.exportCode( "export_nmpc_ext" );
    if(export_flag != 0) mexErrMsgTxt("ACADO export failed because of the above error(s)!");


    clearAllStaticCounters( ); 
 
}