Message Boards Message Boards

Use MMA nb interface to monitor the Arduino during the model run in SM?


I have successfully used SystemModeler and the ModelPlug library to run a model in a Arduino with analog and digital I/O.

Is it possible to use the Mathematica Notebook interface to monitor the Arduino during the model run? I tried to use "WSMRealTimeSimulate" and I get the error :

"The program can't start because modelPlugFirmata.dll is missing from your computer. Try reinstalling the program to fix this problem"

I have re-installed the modelPlug library, but it still does not work.

Any suggestions?


POSTED BY: Wayne Weaver
1 year ago

I know this works -- we used it for our demonstration at the Wolfram Conference 2016 Using SystemModeler to Rapidly Build and Verify Hardware Control Systems.

We used the WSMRealTimeSimulate to launch the simulation from Mathematica, then we were actually able to change parameters live on the Arduino while the simulation was running.

One suggestion: Try going into SystemModeler Preferences and click on Mathematica and reconfigure the link and make sure that the correct directory is in the path there. This has caused issues for me in the past. Sometimes just clicking the link fixes things. If this does not work then you may have to wait for the WSM team to wake up in Sweden tomorrow morning.

As to controlling simulations:

A useful command is the Built-in Templates in WSMLink for doing operations. For example:

WSMCreateTemplateCells["Model_Name",  "ChangeRealTimeParameter"]

This will setup a dynamic manipulate in Mathematica to let you change a live parameter in the simulation (which, in turn, sends the information to the Arduino) You can also do real time plotting while the simulation is running with a command like WSMRealTimePlot[conn, {"block.k"}]

I know I am not helping your specific problem but maybe by indicating it should work, you can successfully debug it on your machine. (Are you on a PC or a Mac?)

POSTED BY: Neil Singer
1 year ago

This looks like Windows and with SystemModeler 4.3 it's possible to configure the simulation to be built as a 64-bit application. However, the current version of ModelPlug was released before SystemModeler 4.3 and therefore it's supporting library (modelPlugFirmata.dll) is only available in 32-bit version. So to use ModelPlug on Windows one has to make sure to have a 32-bit compiler configured (in Tools > Options > Global > Compiler).

However, having the wrong compiler configured would result in a build error so that's not the issue you are seeing. As Neil says this should work and it does indeed work for me on OS X.

POSTED BY: Otto Tronarp
1 year ago

There seems to be a bug when launching simulations with external code on some Windows machines.

As a workaround, you can evaluate this after loading WSMLink, but before running your simulation:

WSMLink`ML`AuxKernel`StartRemote[cmd_, externalPaths_] := 
 Module[{environment = Association[GetEnvironment[]]},
  If[externalPaths =!= {},
    "Path" -> 
       Riffle[WSMLink`ML`AuxKernel`Private`safeFilePath /@ 
         externalPaths, ";"], ";", 
       Replace[Environment["Path"], $Failed -> ""]], ";"]]
  StartProcess[cmd, ProcessEnvironment -> environment]

This should get rid of the error message and make the simulation work.

Note that this is only a bug on Windows, and if you evaluate the fix on other platforms, you will break all simulations.

POSTED BY: Malte Lenz
1 year ago

Malte, your suggested code seems to fix the issue. I am able to run a realtime simulation with ModelPlug now.


POSTED BY: Wayne Weaver
1 year ago

Good to hear! I'll make sure the issue is fixed for real in the next version of SystemModeler.

POSTED BY: Malte Lenz
1 year ago

Group Abstract Group Abstract