Leveraging Your MATLAB Models in OPCloud
MATLAB: A Trusted Tool for Engineering
Despite its proprietary nature, MATLAB remains one of the most widely used computing environments in engineering. Known for its matrix manipulation capabilities, MATLAB excels in algorithm implementation and various analytical tasks. The addition of Simulink provides graphical, model-based design and multi-domain simulation for dynamic and embedded systems.
MATLAB As A Microservice
As of 2020, MATLAB has accrued over four million users worldwide. ¹ While MATLAB has been heavily relied on in engineering projects, there may be more specialised tools for other disciplines, such as OPM for MBSE. Instead of accumulating proprietary legacy models and locking in with a vendor, why not make MATLAB one of the components in a multi-platform engineering organisation using a microservice architecture?
In Part 3 of the Simulating Systems with OPCloud series, we’ll explore integrating MATLAB with OPCloud via API.
Missed earlier articles in this series? Check them out:
Part 2: External Computation using API
Step-by-Step Guide to Integrating MATLAB with OPCloud
Taking the development of an embedded system as an example, suppose you’ve now completed the control logic design in MATLAB and wish to verify its functionality and integration with the system. In this case, you can connect MATLAB to your system model in OPCloud in order to simulate the system behaviour under various scenarios.
Using the following three steps, we’ll learn just how easily this can be achieved.
Step 1: Serve Your MATLAB Model
There are many ways of exposing your MATLAB environment to external applications, one of them is to utilise a TCP/IP connection. Since MATLAB provides support for Java networking libraries (e.g. java.net
and java.io
), you can use them directly to configure the connection, see this example from MathWorks File Exchange.
Then, in your MATLAB server script, set up routing logics to direct requests from an external applications to the right functions, along with parameters parsed from the request. Your code should look something like this:
Step 2: Create OPCloud Model
To integrate the MATLAB function, start by creating a process that represents the function. Inputs and outputs to the function are then modelled as objects in OPCloud. After setting the input objects as computational, you can enter the values into their states.
The inputs are typically connected to the process using instrument links, while the outputs are connected using the result links.
Step 3: Configure the API Request
It’s necessary to provide an alias for each computational object you intend to use as inputs to a process in OPCloud. Then, you can configure the process to call a MATLAB function via external computation, with the URL set to the corresponding endpoint and parameters that take their values from the appropriate objects by their aliases.
Finally, run your MATLAB server script and hit the Execute button in OPCloud. And voilà! You’ll see your system running the algorithm designed in MATLAB in real time!
Final Thoughts
While MATLAB continues to be loved by the engineering community, employing a microservice architecture where MATLAB, Python or any other analytical or modelling tools become a component holds immense potential for organisations that require more diverse capabilities in their complex system development. With this approach, system teams can enjoy the autonomy in managing and maintaining their domain models, with the flexibility in the tool or platform that fits their needs best.
Interested in learning more about leveraging MBSE in complex system development with OPCloud? Check out our microcourse on OptimiSE Academy!
Are there any other engineering tools that you’d like to integrate with your MBSE environment? Feel free to share your thoughts below!
¹ The MathWorks (February 2020). “Company Overview” (PDF).
Leave a Reply