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?

Attachments:
POSTED BY: Wayne Weaver
5 Replies

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

Thanks!!

POSTED BY: Wayne Weaver

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

POSTED BY: Malte Lenz

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:

ClearAll[WSMLink`ML`AuxKernel`StartRemote];
WSMLink`ML`AuxKernel`StartRemote[cmd_, externalPaths_] := 
 Module[{environment = Association[GetEnvironment[]]},
  If[externalPaths =!= {},
   AssociateTo[environment, 
    "Path" -> 
     StringTrim[
      StringJoin[
       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

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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract