Group Abstract Group Abstract

Message Boards Message Boards

Importing Systemmodeler models into Mathematica

Posted 11 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
Posted 11 years ago

Here is the output after setting the baud to 115200:

Starting simulation of experiment "Model1 1" at 08:16:13 
[ModelPlug.Firmata]: Available ports:
- /dev/ttyACM0
[ModelPlug.Firmata]: Using port /dev/ttyACM0 with baud rate 57600
[GENERAL]: Server listening on 127.0.0.1:37645
[GENERAL]: Initialization finished.
[ModelPlug.Firmata]: /dev/ttyACM0 StandardFirmata.ino-2.3
[ModelPlug.Firmata]: Setting sampling interval to 10 ms for board /dev/ttyACM0
[ModelPlug.Firmata]: /dev/ttyACM0 setting pin 13 to mode 1
[ModelPlug.Firmata]: Board /dev/ttyACM0 capabilities
- Pin 2 supports:  DigitalInput - DigitalOutput - Servo
- Pin 3 supports:  DigitalInput - DigitalOutput - AnalogOutput - Servo
- Pin 4 supports:  DigitalInput - DigitalOutput - Servo
- Pin 5 supports:  DigitalInput - DigitalOutput - AnalogOutput - Servo
- Pin 6 supports:  DigitalInput - DigitalOutput - AnalogOutput - Servo
- Pin 7 supports:  DigitalInput - DigitalOutput - Servo
- Pin 8 supports:  DigitalInput - DigitalOutput - Servo
- Pin 9 supports:  DigitalInput - DigitalOutput - AnalogOutput - Servo
- Pin 10 supports:  DigitalInput - DigitalOutput - AnalogOutput - Servo
- Pin 11 supports:  DigitalInput - DigitalOutput - AnalogOutput - Servo
- Pin 12 supports:  DigitalInput - DigitalOutput - Servo
- Pin 13 supports:  DigitalInput - DigitalOutput - Servo
- Pin 14 supports:  DigitalInput - DigitalOutput - AnalogInput(A0)
- Pin 15 supports:  DigitalInput - DigitalOutput - AnalogInput(A1)
- Pin 16 supports:  DigitalInput - DigitalOutput - AnalogInput(A2)
- Pin 17 supports:  DigitalInput - DigitalOutput - AnalogInput(A3)
- Pin 18 supports:  DigitalInput - DigitalOutput - AnalogInput(A4)
- Pin 19 supports:  DigitalInput - DigitalOutput - AnalogInput(A5)
- Pin 20 supports: 
[GENERAL]: Simulation stopped at time = 10.
[GENERAL]: Simulation took 9.99968 seconds of CPU time.
[GENERAL]: Total number of function evaluations: 6127
[warning]: Real-time synchronization overshot 0.1 % of all deadlines with an average of 0.005 ms.
[GENERAL]: Total number of events: 1000
[GENERAL]: Total number of step events (dynamic state switches): 0
Simulation exited at 08:16:23

In this example, 1/2 second on/off pulses are sent to the arduino's pin 13 LED starting at t=0 to t=10 seconds. You would expect 20 flashes; but in reality it tales approximately 4 seconds to upload the code to the arduino and querry its capabilities. If you set the booleanPulse component to use a startTime of 5 seconds, that seems to be enough time to upload the code and query the capabilities, and you will see all 10 flashes of the LED from time t=5 to 10 sec. I would suppose this is the case in Windows as well; and not an issue with my serial port - just the arduino taking an amount of time to initilize?

POSTED BY: Chris Pemberton
Posted 11 years ago
POSTED BY: Chris Pemberton

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