This repo demonstrates how to use SystemsOfSystems.jl to model a control system and simulate it.
If you don't already have Julia installed (v1.12 or greater), install Julia. This is a one-liner from the console and should just take a few minutes.
Clone this repo somewhere on your system. Navigate to that location in the console and run:
julia setup.jl
This may take a few minutes to compile a bunch of stuff.
Note that this setup doesn't change anything on your system; it only applies to this directory.
The sim can run two different ways. We'll start with the command-line version. Run the following to set up the models shown in the in/demo.yaml file (a simple closed-loop control system with a plant, noisy sensor, controller, and actuator). You will see a progress bar as it runs. When it's done, the output files will be in out/.
julia --project=. demo-shell.jl --input in/demo.yaml --output out/
The out directory will now have plots and an HDF5 file. You could open that HDF5 file in many major languages (Python, MATLAB, C++) and look around if you like. Below are some example arrays in that HDF5 file.
Here was a top-level continuous-time output:
/timeseries/control_error/title
/timeseries/control_error/time
/timeseries/control_error/data
/timeseries/control_error/units
Here's the plant's continuous-time position:
/models/plant/timeseries/position/title
/models/plant/timeseries/position/time
/models/plant/timeseries/position/data
/models/plant/timeseries/position/units
The sensor outputs its measurement (a structured type with a field for sample time, t, and the measured position, position), resulting in:
/models/sensor/timeseries/measurement/title
/models/sensor/timeseries/measurement/units
/models/sensor/timeseries/measurement/time
/models/sensor/timeseries/measurement/data/data/t/data
/models/sensor/timeseries/measurement/data/data/position/data
Feel free to examine the file to see the other signals.
Ok, that's it. You ran a sim. If you just want a system that can run like an executable, mapping an input file to output files, then this is all you need.
We can also run the sim without input files. demo.jl shows the code to run the sim where all of the models are set up in Julia. It's pretty easy to read, and it does the same this as running with input files. You can run it like so:
julia --project=. -i demo.jl
(The -i argument here means "run in interactive mode". When the simulation is done, it will drop you off in Julia so you can examine plots, interact with things, etc. When the sim is done, you may have to switch windows to see the plots. When you're done, back in Julia, press ctrl+d to quit.)
All of the models used in this example are defined in models.jl. We'll put together a modeling tutorial soon. Even without one, it's pretty easy to see what kinds of things are going on with the models in this sim. SystemsOfSystems.jl features a concise, expressive, and very general modeling language, and we can use it to build up large-scale models with flexible levels of fidelity, easy configuration, and tons of outputs.
For general inspection:
demo-shell.jl- The Julia script to run from the command line with inputs from an input filedemo.jl- A script that configures the model parameters directlyin/demo.yaml- The input file we use heremodels.jl- Where all of the models are definedout/...- The results of the simulationsetup.jl- The script used to set up a local Julia project for this repo
For developers
demo-timing.jl- Used for assessing the runtime of the simProject.toml- Defines what Julia packages are used by this projectManifest.toml- An autogenerated file that specifies exactly what versions of all packages are being used here