How to implement discrete constraints and boundary conditions per time step using casadi.Opti()

288 views
Skip to first unread message

Leo Bakker

unread,
Feb 12, 2020, 7:38:27 AM2/12/20
to CasADi
Dear all,

I like to create an MPC using a vector with discrete constraints and do not know how to implement this using casadi.Opti()

(In my MPC I have hourly values for set points and boundary conditions as solar radiation and outdoor temperatures). 

Please let me clarify my question using the Slot car racing problem (https://web.casadi.org/blog/ocp/): 


opti = casadi.Opti(); % Optimization problem
limit = @(pos) 1-sin(2*pi*pos)/2;
opti.subject_to(speed<=limit(pos)); % track speed limit
opti.subject_to(0<=U<=1);           % contrDear all,

Here the speed limit is a function of position (pos). 

My question is how can I replace this function with a vector with discrete values in the time horizon.

And how can I do the same in the cost function.

Thanks in advance for answering my question.

Leo Bakker 

Joris Gillis

unread,
Feb 12, 2020, 8:04:57 AM2/12/20
to CasADi
Dear Leo,

Speed is a vector; just put a vector at the right-hand side as well:
opti.subject_to(speed<=[1 2 3 4 8 ... ]);
Probably, you want to use an opti.parameter instead of hard-coded numerial values.

Best,
  Joris







opti.subject_to(speed<=limit(pos));

Leo Bakker

unread,
Mar 19, 2020, 8:58:31 AM3/19/20
to CasADi
Thanks !!! 

That works if I use for instance: 

limitt = [1.1]*21
opti.subject_to(speed.T<=limitt)

I need to use the transposed value  (speed.T) to make it work.

My next question is if it is possible to add controllable variables (e.g. breaking power) ? 
and how to implement this ?

Thanks in advance,
Leo Bakker    


Joris Gillis

unread,
Apr 2, 2020, 5:26:23 PM4/2/20
to CasADi
Dear Leo,

What do you mean with controllable variables?

Best regards,
  Joris
Reply all
Reply to author
Forward
0 new messages