Menu

Online Data as constraints in ACADO Matlab Code Generation

arnim
2016-02-29
2025-05-28
  • arnim

    arnim - 2016-02-29

    Dear comunity,

    I am using the ACADO Code Generation tool with the Matlab interface in order to solve an NMPC problem.
    First of all: I am really impressed by the tool, so thanks for the fine job!

    Unfortunately, I have still problems implementing variable constraints using the OnlineData data type. I think I would be satisfied with simple box constraints but need them to be adjustable before each call of the controler.

    The Controler is working fine until I add an OnlineData variable to the constraints.
    Then it crashs with

    Error in acado.AcadoMatlab/generateCPP (line 102)
            eval(sprintf(regexprep(ACADO_.mexcall, '\\', '\\\\'), fileIN, fileOUT));
    
    Error in GEN_ACADO (line 41)
    ACADO_.helper.generateCPP();
    
    Error in acado.ExportModule/exportCode (line 90)
                GEN_ACADO;
    
    Error in ...
        mpc.exportCode( '...' );
    

    I know this was topic of discussion before (e.g. here ) but I did not completely understand the solution/work around.

    I.e. in more detail (c.f. link):

    • I do not understand how to manually set the number of OD variables (NOD). How and where in the program do I call the mentioned function setNOD? Is it a Matlab or C function and where is it defined? If somebody can give me a bit more detailed instructions on what to do, maybe it would already help me to solve the problem.
    • Also I do not totally understand how to apply the before mentioned workaround here.

      ...I solved the issue, temporarily, by pausing between the nmpc.exportCode step, and manually changing the declaration of ACADO_NOD in acado_common.h and make_acado_solver_sfunction.m before continuing with make_acado_solver(' ')...

    • When do you stop the program for the and I also didn't find make_acado_solver_sfunction.m. Guess I am not so good in finding functions...

    Every help and any other solution too, of course, is highly appreciated! Thanks!

     
  • Rien Quirynen

    Rien Quirynen - 2016-03-01

    Hi there,

    if you want your bounds to be adjustable, you can simply set the following option instead of using online data:

    mpc.set( 'CG_HARDCODE_CONSTRAINT_VALUES', 'NO' );

    From MATLAB, this will result in additional inputs (lbValues/ubValues for the lower and upper bounds on the variables and lbAValues/ubAValues for the affine contraints) to the MEX interface to set the bound values.

    Rien

     
  • arnim

    arnim - 2016-03-01

    Hi Rien,

    Thank you very much for your help. The 'CG_HARDCODE_CONSTRAINT_VALUES' property was also something I was wondering about. However, I think it only sets limits for the controls (for which it works fine), is that right?
    I probably forgot to mention that I want to set limits for states, too.

    Would it suffice to call the setNOD function in order to set the correct number of OD variables and then use ODs in constraints (box or general constraints)?
    If so, could you tell me how and at which point in the program I have to use this function, please?

    Thanks, Armin.

     
  • Rien Quirynen

    Rien Quirynen - 2016-03-01

    Hey,

    You can also add state constraints of which the bound values can then be changed in the lbAValues and ubAValues inputs. The reason for this is that condensing will eliminate the state variables from the QP problem such that such simple bounds become affine constraints for the QP solver.

    Rien

     
  • arnim

    arnim - 2016-03-02

    Hi Rien,

    Great, thanks!
    I thought the lbAValues were only used for setting limits to affine controls.
    Now it gets clearer.
    One last question; Can I also set variable box constraints to algebraic variables in a DAE in a similar way? They are probably not affine after condesing, are they?
    I.e. something for the problem

    min J(u,x,z)
    
    w.r.t. dot(x) = f(u,x,z)
               0  = g(u,x,z)
    ...
              -z  < z_min(t)
               z  < z_max(t)
    
    where u... controls
          x... state variables
          z... algebraic variables
    
     
  • dongdong.chen

    dongdong.chen - 2025-05-28

    OnlineData delta_limit omega_limit;
    delta_limit = 0.2;
    omega_limit = 0.3;

    % 使用固定约束
    ocp.subjectTo(- delta_limit <= delta <= delta_limit);
    ocp.subjectTo(-omega_limit <= omega <= omega_limit);

    % 设置硬编码选项
    mpc.addOption('CG_HARDCODE_CONSTRAINT_VALUES', 'YES');

    code generation failure with above and error message as below:

    Requested function is not yet implemented ~

     
  • dongdong.chen

    dongdong.chen - 2025-05-28

    OnlineData delta_limit omega_limit;
    delta_limit = 0.2;
    omega_limit = 0.3;

    % 使用固定约束
    ocp.subjectTo(- delta_limit <= delta <= delta_limit);
    ocp.subjectTo(-omega_limit <= omega <= omega_limit);

    % 设置硬编码选项
    mpc.addOption('CG_HARDCODE_CONSTRAINT_VALUES', 'YES');

    code generation failure with above and error message as below:

    Requested function is not yet implemented ~

     
  • dongdong.chen

    dongdong.chen - 2025-05-28

    code print log as :

     

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.