VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Veristand phar lab custom C controller

Solved!
Go to solution

Hello,

For my project i require to run Non Linear Model Predictive Control (NMPC) on a real time simulation.
the simulation is run on a real time target through veristand.

My first attempts were simple controllers (constant input, pid) exported from simulink to DLL models which ran on the target successfully.
Unfortunately i did not succeed in generating c code from my own NMPC matlab code which utilizes matlab's fmincon.

Next i attempted creating my own simulink s-code block build from c code based on the NLOpt toolbox.
This ran successfully in simulink but did again not export to a DLL for veristand.

Now i am attempting to directly compile my c-code for Veristand to run on the target.
But until now i have not yet succeeded in compiling any c-code for the target.
I tried multiple examples in the c:/veristand/modelinterface folder, but none run successfully on the target.
-I attempted this tutorial using "eclipse", but the ".o" file was not accepted by veristand (error:307703 failed to load).
-I attempted This tutorial using "labwindows", this gave a compile error "Undefined symbol _USER_Modelstart in codegen.c" combined with "build failed"
but it did generated a random.DLL which ran successfully in veristand on windows, but would not run on my target (instantly disconnecting).
The terminal shows some data (as it does always) but too quick to read and then returns to its main screen.
The gateway status however does give a error (307703 incompatible model).
-I attempted to compile the code using supplied make files (as described in "NI_VStand_Model_Framework_Guide.pdf")
this resulted in the make command returning "nothing to be done with random.mak".

to be short i have the following questions:
-Is there a way i debug random.dll so that it hopefully runs on the target? and prevents the disconnection?
-What is the procedure to generate c code using make files as described in the veristand interface guide?
-Are there any other suggestions on how to implement a non linear optimization algorithm on the target?

Best regards,
Thomas

specs:
windows 7
matlab/simulink 2015b
veristand 2014
PXIe-8880 running NI Real-Time Phar Lap ETS 13.1 and veristand engine 2014
Mingw compiler

 

attachments:
Veristand interface guide
the log from Veristand when failure to deploy
the files as found in c:/veristand containing the examples.

0 Kudos
Message 1 of 17
(5,324 Views)

Tuesday, June 5, 2018

10:37 AM

Is there a way I debug random.dll so that it hopefully runs on the target? And prevents the disconnection?

Some ideas are on this are found on VeriStand in Help » Search the NI VeriStand Help » Integrating and Executing Models » Troubleshooting Issues in Models.

 

It is best to compile a DLL and verify that it is executable on PhapLap with this tool:

 

Verify Your DLL Is Executable in LabVIEW Real-Time on NI PharLap ETS

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019M0tSAE

 

 

What is the procedure to generate c code using make files as described in the VeriStand interface guide?

On page 5 of the guide you attached you are led to find examples and to know what files are required for this. And on page 6 you there are other

 

 

Are there any other suggestions on how to implement a nonlinear optimization algorithm on the target?

Is this perhaps more of a control theory related question?

0 Kudos
Message 2 of 17
(5,281 Views)

Thanks for the reply,

Since my original message i have made some progress.
Using "Visual studio command prompt (2010) command line interface" i successfully compiled the "random" Example .
By running "nmake random.mak" the dll get compiled and import into Veristand fine, and also on the target they run.
I also successfully adapted the template.c file with my own code (just a simple test) so the compiling is successful.

Now however i run into the issue of implementing the NLOpt toolbox, compiling goes fine but Veristand says it is incompatible,using the DLL checker that you suggested reveals a series of bad imports.

My code runs when simplified to just take the input and route it to the output, even with the nlopt library included.
But as soon as i add a function from the nlopt toolbox it no longer imports into veristand.

The dll checker shows that without the nlopt function a series of badimports from kernel32.DLL but still runs as expected
When checking the dll compiled with a function from nlopt a single bad import is added from msvcrt.dll
"__setusermatherr (__setusermatherr)"
Thus i believe the dependencies on MSVCRT.dll causes the import error.

Is there anyway to implement this DLL in Veristand?
Or is there an way during compiling to avoid this dependency? 

Another option is to either create my own optimizer, or alter the sourcecode of the nlopt toolbox.
Doing my own optimizer would disable the easy option of changing optimizer algorithms on command.
And recompiling the source code i also expect issues.

some additional info:
-the nlopt libary is compiled using VS2010 with the "lib /def:libnlopt-0.def" command
-for including the library in the dll the link command in the .mak also needs to link to the .lib file
-i'm using the cl compiler 32bit v16 (still windows 7 64 bit os though)


Thanks for the suggestion of the DLL checker, it helped me identify the dependency.



0 Kudos
Message 3 of 17
(5,272 Views)
Solution
Accepted by topic author ThomJ

Ideally you should work with a DLL that passes the test.

I think your idea to reverse engineer the function based on the library you are currently using is the way to go if you want to compile correctly, the functions themselves are simply not supported, but you might still be able to implement them on your own. And you are also right about the tradeoff here, flexibility and of course dev time.

Message 4 of 17
(5,267 Views)

I have successfully recompiled the toolbox to work without dependencies according to the DLL tool.
The toolbox luckily came with compilation instructions, which allowed me to compile it using nmake with the "/mt" marker
Now i still have the issue that Veristand does not accept the compiled dll, i believe the dependency on the toolbox does not transfer.

Would you be aware on how to point Veristand to the toolbox.dll, or any means of combining my script with the toolbox?

Attached is the results of the dll checker.

Download All
0 Kudos
Message 5 of 17
(5,261 Views)

Copy the dependency dll to <target>/ni-rt/system . That's the default search path for on PharLap for the dependencies.

CLA, CTA, CLED

0 Kudos
Message 6 of 17
(5,251 Views)

Hello,

Veristand does not allow me to import my own model, and states it is incompatible.
This is the same aforementioned "opti.dll" which is a simple script which can be imported fine when i comment out the one function from the nlopt toolbox.

To upload the model i recompiled the dll with the function commented out.
Then i imported the dll, and recompiled it with the function while the path was still present in Veristand.
Once changed it does no longer run locally or on the target.
I also tried to put the dependency on the target in /ni-rt/system folder.
This did not allow for the model to deploy, it still gives the "incompatible model"error

I tried compiling with visual studio 2010 twice, once with the /MD flag the other the /MT flag (determines dynamic linking if i'm correct)
Same for VC 6.0 (according to the make file of the modelframework this is required when using /mt flag)

The Veristand error suggest checking the console, but it shows the same info.
Below the software is used for the compiling and the error i get from Veristand.
And attached the code i'm trying to deploy.

Are there any more suggestions on how to run a custom made C model in Veristand on a Pharlab target with a dependency on a external library?
Or on how to troubleshoot  the deployment process?

compilers:
2010:
CL v16.00.40219.01
Link v10.00.40219.01

VC 6.0
CL v12.00.8168
Link  V6.00.8168

veristand error

System error encountered.
:::Details:::
Error code: -307703
Error Message: NI VeriStand: The specified model is incompatible with NI VeriSta
nd. If you are trying to deploy the model to an RT target, launch the Console Vie
wer tool to display the console output of the target, which includes information
about the source of the error.
=========================

NI VeriStand: Failed to load C:\ni-rt\NIVeriStand\Models\opti.dll

0 Kudos
Message 7 of 17
(5,233 Views)

small update,

i got veristand to correctly import the dll, the trick was to put the dll's in the same folder as the veristand project file.
i was running my code on a separate folder, thus i assume the dependency could not be found.
however deploying the code on the target still gives the same error.
i tried putting the dependency in the ni-rt folder but it has no result.

0 Kudos
Message 8 of 17
(5,218 Views)
Solution
Accepted by topic author ThomJ

Final update

I got the code to deploy successfully.
The first trick was to switch compilers to Visual studio 2008.
And then once more completely recompile the dependency and my own code.

Tips for people with similar problems:
-Run compile commands from the VS developer prompt (not regular command prompt), this also is important for starting additional compile programs (like cmake)
-put your code+dll's+veristand files in 1 folder on your pc, i had my dll and code in separate folder from my veristand work folder.
-put dependency dll's on the target in the c:/no-rt/system folder.
-check dll's with the dll checker (correct year corresponding to the version of veristand)

Thanks to the users Notanae and Jiri_k for the help provided.


0 Kudos
Message 9 of 17
(5,206 Views)

Hello,

please, I need to help me. I did not succeed to run Non-Linear Model Predictive Control (NMPC) on Simulink s-code block build from c code based on the NLOpt toolbox

Please how to implement a non-linear MPC on Simulink ?.

 

Best regards,
KOUKI

0 Kudos
Message 10 of 17
(4,917 Views)