I'm trying to solve an optimal control problem using OCP. I have seen in many posts that to be able to use constraints that depend on the states we should set CG_HARDCODE_CONSTRAINTS to NO.
algo = acado.OptimizationAlgorithm(ocp);
algo.set('CG_HARDCODE_CONSTRAINTS ','NO');
I believe if I use the above setup , I would be able to use state dependent constraints
ocp.subjectTo(0<= u <= .5- x2); such that x2 is the real time state. However this actually didn't work for me.
I would appreciate any help on this issue.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are using an option for the code generation tool ("CG_") outside of this tool, so that will indeed not work.
But why don't you specify your constraints directly as:
ocp.subjectTo( 0 <= u );
ocp.subjectTo( u+x2 <= .5 );
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have another question, putting constraints on the states the way you mentioned make the solver to fail compared to using only fixed constraints (0<=u<=.5). Even with fixed constraints, when increasing the window of optimization from ocp = acado.OCP(0.0, 40, 40) to ocp = acado.OCP(0.0, 168, 100); the solver also fails. I understand increasing the time, increases the number of decision variables and makes the optimization more difficult but is there any other explanation to that. Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to solve an optimal control problem using OCP. I have seen in many posts that to be able to use constraints that depend on the states we should set CG_HARDCODE_CONSTRAINTS to NO.
algo = acado.OptimizationAlgorithm(ocp);
algo.set('CG_HARDCODE_CONSTRAINTS ','NO');
I believe if I use the above setup , I would be able to use state dependent constraints
ocp.subjectTo(0<= u <= .5- x2); such that x2 is the real time state. However this actually didn't work for me.
I would appreciate any help on this issue.
Thanks.
Hi there,
You are using an option for the code generation tool ("CG_") outside of this tool, so that will indeed not work.
But why don't you specify your constraints directly as:
ocp.subjectTo( 0 <= u );
ocp.subjectTo( u+x2 <= .5 );
That's a smarter way to define the constraint and it answers my question. Thank you Rien.
I have another question, putting constraints on the states the way you mentioned make the solver to fail compared to using only fixed constraints (0<=u<=.5). Even with fixed constraints, when increasing the window of optimization from ocp = acado.OCP(0.0, 40, 40) to ocp = acado.OCP(0.0, 168, 100); the solver also fails. I understand increasing the time, increases the number of decision variables and makes the optimization more difficult but is there any other explanation to that. Thank you.