Mulitple inputs

349 views
Skip to first unread message

Michael Jacob Mathew

unread,
Jan 26, 2016, 1:11:16 AM1/26/16
to CasADi
I am new to Casadi, in the examples given, vdp_singleshooting.py, how to modify the file exactly if I had multiple inputs u[0] and u[1]?


u = SX.sym("u",2)

xdot = vertcat([(1-x[1]*x[1])*x[0] -x[1] + u[0], x[0]+u[1]])
qdot = x[0]*x[0] + x[1]*x[1] + u[0]*u[0] + u[1]*u[1]

I am basicaly trying to figure out, how to incorporate multiple inputs to the recurssive integrator line inside it and also, how to add in the limits?

Michael Jacob Mathew

unread,
Jan 26, 2016, 1:41:15 AM1/26/16
to CasADi
Or if somebody could direct me an example that uses multiple inputs, in a system.

I followed the direct collocation method and wrote a code for a optimal control problem  with 6 inputs, though the code didn't produce any error, the output produced was incorrect. The same formulation produced results in correct output in ACCADO. So I am guessing something wrong with the way I coded it.


Joel Andersson

unread,
Jan 26, 2016, 10:16:45 AM1/26/16
to CasADi
Hi Michael!

I simplified the single shooting code a bit and replaced the "vertsplit" operation in the formulation with a list of decision variables and a vertcat at the end:

https://github.com/casadi/casadi/commit/d206860d30387d5f10bb65b0013a34885ddda2f0

It should be straightforward to extend that to vector-valued u.

This change is for CasADi 3.0, but the same should work for CasADi 2.4 and (I think) CasADi 2.3. It's also the potentially more efficient and more readable way to do it.

Best regads,
Joel

Joel Andersson

unread,
Jan 26, 2016, 11:48:52 AM1/26/16
to CasADi
Hi again,

I just made an iteration on both the direct single shooting and the direct multiple shooting examples in CasADi. Might be of interest to you:


Note that direct multiple shooting is usually preferable to direct single shooting.

Best regards,
Joel

Michael Jacob Mathew

unread,
Jan 27, 2016, 8:31:59 AM1/27/16
to CasADi
thanks for the code links, I would going through it. I am particularly interested in direct collocation. So I was trying to understand others as well. As said earlier, my code doesn't produce any error. But the solution is incorrect.  Attached is the code that is given for the following system. The system has to reach from 0,0,0 to 5,0,pi configuration. I did get the correct solution in accado. It would be very helpful if you could suggest anything in right direction.







fingerManipulationDirCol.py

Joel Andersson

unread,
Jan 27, 2016, 10:08:27 AM1/27/16
to casadi...@googlegroups.com
Hi!

Since you know the solution, try starting very close to it and make sure that it doesn't wander somewhere else. You can also tighten the bounds.

Joel

Joel Andersson

unread,
Jan 27, 2016, 10:33:01 AM1/27/16
to CasADi
If you're trying out collocation, make sure you're able to simulate the system using the optimizer. That is, by fixing all u (set upper and lower bounds equal).

Joel

Michael Jacob Mathew

unread,
Jan 28, 2016, 9:44:53 AM1/28/16
to CasADi
thanks for that simplified code. it cleared all problems.

Just one problem remains, when I try the ma27 solver, I get the error: (but the collocation works with "max iteration" option.

Exception message: Selected linear solver MA27 not available.
Tried to obtain MA27 from shared library "libhsl.so", but the following error occured:
libhsl.so: cannot open shared object file: No such file or directory


Joel Andersson

unread,
Jan 28, 2016, 12:25:32 PM1/28/16
to CasADi
Hi!

In the vdp_collocation.py example, the linear solver option is being set (pre 3.0 syntax: "linear_solver", post 3.0 syntax: "ipopt.linear_solver") to "ma27". This only works if you have HSL installed:


Best regards,
Joel

Michael Jacob Mathew

unread,
Jan 31, 2016, 5:27:09 PM1/31/16
to CasADi
If I have a polynomial constraint (involving differential states and not algebraic variables), should I be declaring it as an additional state along with other differential equations and then specify its limits (like Mayer term being one of the state of the ode)?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages