<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin-top:0cm;
        margin-right:0cm;
        margin-bottom:10.0pt;
        margin-left:0cm;
        line-height:115%;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:-2;
        mso-list-type:simple;
        mso-list-template-ids:958939590;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:*;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:0cm;
        text-indent:0cm;}
@list l0:level1 lfo2
        {mso-level-numbering:continue;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        mso-level-legacy:yes;
        mso-level-legacy-indent:0cm;
        mso-level-legacy-space:0cm;
        margin-left:0cm;
        text-indent:0cm;
        font-family:Symbol;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-NZ" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Hi Martijn,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">In my experience C-MEX S-Functions can be difficult, and even more so with the need to generate real-time code. You might like to start with one of my other packages (jMPC Toolbox) which implements linear MPC
using C-MEX S-Functions:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><a href="http://i2c2.aut.ac.nz/Resources/Software/jMPCToolbox.html">http://i2c2.aut.ac.nz/Resources/Software/jMPCToolbox.html</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">As with the OPTI Toolbox, all source is provided so you can see how to begin implementing an S Function (and even better, MPC). However you will need a C-MEX function which calls IPOPT. You can dynamically link
IPOPT (build a DLL) to a MEX file, or statically link as I have done in OPTI. Compiling IPOPT from source (including all prerequisites) can be tricky on Windows so let me know if you want a static library build, I think I am allowed to distribute it. Just
note the MATLAB interface to IPOPT (by Dr. Carbonetto) is reasonbly complex and this will be need to be reimplemented in a S Function (hope you are a good C++ programmer). Also make sure to use the warm-start functionality of IPOPT, something MPC can greatly
benefit from.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Regarding the need to generate real time code, I'm not sure exactly how this will work with IPOPT. I doubt that will work with the xPC Target, however It should (although I have not tried) work with the Real
Time Windows Target. You are probably best to ask a question in the Matlab User Forum regarding using 3rd party code within it's real time code execution environment.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I would be interested in your progress, so keep me posted on developments!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Jonathan Currie<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt;line-height:normal">
<b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> ipopt-bounces@list.coin-or.org [mailto:ipopt-bounces@list.coin-or.org]
<b>On Behalf Of </b>Martijn Disse<br>
<b>Sent:</b> Wednesday, 30 May 2012 7:53 a.m.<br>
<b>To:</b> ipopt@list.coin-or.org<br>
<b>Subject:</b> [Ipopt] Question: Using IPOPT as an S-function in Simulink<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB">Dear all,<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB">For my thesis work I am using IPOPT as a solver for a Model Predictive Controller. IPOPT is open source and exist of a large collection of files written in C++. I installed the solver to be
used with Matlab via the OPTI-Toolbox (</span><span lang="NL"><a href="http://www.i2c2.aut.ac.nz/Resources/Software/OptiToolbox.html"><span lang="EN-GB">http://www.i2c2.aut.ac.nz/Resources/Software/OptiToolbox.html</span></a></span><span lang="EN-GB">) which
come with a precompiled mex-file that acts as a function to call the solver. This works perfectly. However, since I need to use XPC-target or Windows Real Time Target, I need to implement the solver somehow in a Simulink block.
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB">This is what I've tried so far:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo2;text-autospace:none">
<![if !supportLists]><span lang="EN-GB" style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span lang="EN-GB">Since I already have a mex-file I thought it would be convienent to use that inside a simple 'Matlab Function'-block. This works in Simulink, but the code generator cannot compile the Simulink diagram to a real-time
executable code.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo2;text-autospace:none">
<![if !supportLists]><span lang="EN-GB" style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span lang="EN-GB">Creating an S-function in which I call the .mex function. This code cannot be compiled since the .tlc file is missing.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB">After some search on
<a href="http://www.mathworks.se/matlabcentral/answers/38962-call-a-mex-function-from-simulink">
fora</a> and <a href="http://www.mathworks.com/matlabcentral/answers/36879-calling-mex-function-from-within-simulink">
Matlab central</a>, I found out that I should create a C MEX S-function and compile it. To make life easier, Simulink comes with an S-function builder in which libraries etc. can be added. I failed in constructing one and it is driving me crazy. My question
to you therefor is:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span lang="EN-GB">Who has experience in compiling IPOPT (or any other set of C++ files) to act as an S-function in Simulink and is willing to point me in the right direction?<o:p></o:p></span></b></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB">Your help will be greatly appreciated!<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="NL">Best,<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="NL">Martijn <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="NL"><o:p> </o:p></span></p>
</div>
</body>
</html>