giaf / hpipm

High-performance interior-point-method QP and QCQP solvers
Other
552 stars 130 forks source link

MATLAB #57

Open PranjalBiswas opened 5 years ago

PranjalBiswas commented 5 years ago

Hi @giaf ,

I wanted to know if I could use this solver within a MATLAB/Simulink environment. Is it possible? If it is possible, how should I proceed with it? Maybe some starting points will help a lot. Looking forward to hear from you.

Kind regards Pranjal Biswas

giaf commented 5 years ago

Hi, there is a matlab interfaced (which is currently based on the python interface) to interactively use the solver from matlab.

There is not a simulink interface yet, but maybe @zanellia may give you some suggestion to get started with that.

PranjalBiswas commented 5 years ago

Thanks @giaf.

Hi @zanellia, it will be great if you can provide me some suggestions regarding using hpipm in Simulink.

zanellia commented 5 years ago

Hey @PranjaLBiswas27, thanks for your interest in HPIPM! A Simulink interface could be indeed a useful bit to be added to the codebase. Can you give us a bit more details about what are your needs? I haven't put any concrete thought into how to build such an interface, but I guess in principle you could call the MATLAB interface from Simulink?

PranjalBiswas commented 5 years ago

Hi @zanellia,

Thanks for getting back to me. To be honest I am really trying to figure out what my needs are and thus the solver I require. As of now my requirement is to implement MPCC, for which @alexliniger from ETH has referenced this repository. So I was wondering if HPIPM works similarly to quadprog or mpcqp in MATLAB, at least in terms of using it within a MATLAB code and not how it solves the QP. Also my initial idea was to use it within a s-function or MATLAB function itself if possible. What do you think?

Kind Regards Pranjal Biswas

zanellia commented 5 years ago

@PranjaLBiswas27 if performance/embeddability (QP solutions will be very fast, but you might loose some performance with the interaction between Simulink-MATLAB and the HPIPM shared library) are not the main focus, calling the MATLAB interface from Simulink might be the quickest/easiest solution. I can assist you with this. Otherwise we need to set up something a bit more structured.

zanellia commented 5 years ago

Just to be more specific, do you need to run on anything like dSPACE or Beckhoff systems?

PranjalBiswas commented 5 years ago

@zanellia, thanks. Yes, I do think I will require to generate C-code of Simulink model using the code builder that is provided with MATLAB to be able to implement in real time in a HIL setup. This might require me to work with d-space but I am not sure as of now.

Also, for simulation purposes the performance is not a consideration but it is important while running real-time though. What exactly do you mean by a more structured approach, like making a Simulink block all-together?

zanellia commented 5 years ago

The MATLAB interface runs MATLAB and Python code that, most likely, you don't want to deploy on the embedded unit. In order to go embedded we would need to compile everything (both HPIPM and the calls to the C API) in a shared library and an S-Function that you can also crosscompile.

PranjalBiswas commented 5 years ago

Sorry if I am a bit naive, but HIL does not necessarily mean emebedded?

Also, is it possible to use hpipm within a s-function and generate C code using the code builder? Will it lead to any issues considering hpipm runs python code?

zanellia commented 5 years ago

If you want to use Simulink Coder, I would be surprised if you could generate C code from a MATLAB function that calls the Python interpreter. I can spend some time to look into this in the next days, a Simulink/MATLAB/Python to embedded interface is anyway something useful. @giaf Do you think something like what we did in acados with templated C code would be a solution?

PranjalBiswas commented 5 years ago

@zanellia, is there a C version also of hpipm? In that case maybe it will then be possible to use the Simulink coder?

zanellia commented 5 years ago

Yes, of course :) If you are willing to use the C interface you can have a look at the C examples: https://github.com/giaf/hpipm/tree/master/examples/c. Ideally this code could be generated directly from from MATLAB/Simulink/Python. That's the slightly longer term solution I would think about.

PranjalBiswas commented 5 years ago

Ahh, I thought using the C interface will be a faster way to implement as Python does not comes into the picture. Although I dont have experience with Simulink Coder but I feel using the C interface by calling it in a s-function can work, unless I am really missing out on something which I am not aware of.

Other than that anyway my main concern is being able to use hpipm irrespective of C or python interpreter in Simulink. What will you suggest to do considering the following points: 1) I am a novice :) 2) Would like to go for the approach (C or Python) which ever is relatively simpler. 3) Be able to generate C-code of my Simulink model while being able to use hpipm.

zanellia commented 5 years ago

Ahh, I thought using the C interface will be a faster way to implement as Python does not comes into the picture. Although I dont have experience with Simulink Coder but I feel using the C interface by calling it in a s-function can work, unless I am really missing out on something which I am not aware of.

This approach is definitely possible and will allow you in principle to use Simulink Coder to deploy on embedded platforms like dSPACE or Beckhoff. In the not-so-long run, we will support automatic generation of the S-Function from Python/MATLAB.

PranjalBiswas commented 5 years ago

Thanks for the clarification. Also, looking forward to the automatic generation of the s-function, it will be really handy. Is there any expected date for it?

giaf commented 5 years ago

@zanellia any new with a s-function prototype?

zanellia commented 5 years ago

@PranjaLBiswas27, @giaf sorry for the loose response. I am working on it on this branch: https://github.com/zanellia/hpipm/tree/simulink_interface/interfaces/simulink - it's work in progress.

PranjalBiswas commented 5 years ago

@zanellia do you already have the Simulink interface working?

giaf commented 5 years ago

@zanellia is currently on holiday, but back on the Simulink interface in one week from now :) Soon ready!