Message Boards Message Boards

Importing Systemmodeler models into Mathematica

Posted 10 years ago

I am comfortable creating and saving my models within SystemModeler.

I'd like to load my saved model (/home/cjpembo/Documents/SimpleFourBarLinkage.mo) into Mathematica. I've tried the following:

Needs["WSMLink`"];
myModel = WSMSimulate[
 SystemOpen["/home/cjpembo/Documents/SimpleFourBarLinkage.mo"]];

This will launch SystemModeler and load my saved model within that external program, but Mathematica is not yet ready to access my model. It returns the following:

WSMSimulate[Null]

I must run the command a second time, now using the model name only:

WSMSimulate["SimpleFourBarLinkage"]

I can now fully access my model from within Mathematica.

I'm certain there is a simple way to accomplish this... but the documentation seems to only address loading models that are already included as examples in SystemModeler, or models that are already loaded in a running SystemModeler session.

So to be more clear: I want to open a saved model from within Mathematica without having to load it twice; just like in the example documentation.

Thanks!

POSTED BY: Chris Pemberton
3 Replies

SystemModeler and your Mathematica session actually share a common state of loaded models, if they are both running.

To load a .mo file and then simulate it in Mathematica without launching SystemModeler:

(* Load SystemModeler functionality *)
Needs["WSMLink`"];
(* Load the model you want to simulate *)
myModel = Import["/home/cjpembo/Documents/SimpleFourBarLinkage.mo", "ModelicaModel"];
(* Simulate the model *)
WSMSimulate[myModel]

Documentation is here: http://reference.wolfram.com/system-modeler/WSMLink/ref/format/MO.html

POSTED BY: Malte Lenz
Posted 10 years ago

Thanks; that is what I was looking for.

I've been expiramenting with an arduino (uno and mega) and Wolfram's ModelPlug addon. I'm in linux and SystemModeler gave me the following errors when I ran the BlinkLED example:

Starting simulation of experiment "Model1 1" at 07:53:22 
[ModelPlug.Firmata]: Available ports:
- /dev/ttyACM0
[ModelPlug.Firmata]: ERROR The port ttyACM0 does not exist
[GENERAL]: Server listening on 127.0.0.1:38993
[GENERAL]: Initialization finished.
[GENERAL]: Simulation stopped at time = 10.
[GENERAL]: Simulation took 0.028844 seconds of CPU time.
[GENERAL]: Total number of function evaluations: 8024
[GENERAL]: Total number of events: 1000
[GENERAL]: Total number of step events (dynamic state switches): 0
Simulation exited at 07:53:23

Port /dev/ttyACM0 does exist and my user account has the correct permissions to use it. I've solved the problem: I "think" that linux (in my case Archlinux) sets the port to 9600 baud by default and this borks SystemModeler somehow. I've tried setting/unsetting the arduino component parameter "ShowPinCapabilities", but it still fails. The following command will set the baud higher and then SystemModeler seems to work fine (in my limited testing).

stty -F /dev/ttyACM0 115200

I've been reading the source code that comes with ModelPlug and it seems the author has several comments stating that serial emulation in linux is very challenging. Perhaps ModelPlug could include a parameter to manually set the baud?

POSTED BY: Chris Pemberton
Posted 10 years ago
POSTED BY: Chris Pemberton
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