Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Rouleau committed Jun 21, 2022
0 parents commit 4e22071
Show file tree
Hide file tree
Showing 414 changed files with 2,071 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
*.fig binary
*.mat binary
*.mdl binary diff merge=mlAutoMerge
*.mdlp binary
*.mexa64 binary
*.mexw64 binary
*.mexmaci64 binary
*.mlapp binary
*.mldatx binary
*.mlproj binary
*.mlx binary
*.p binary
*.sfx binary
*.sldd binary
*.slreqx binary merge=mlAutoMerge
*.slmx binary merge=mlAutoMerge
*.sltx binary
*.slxc binary
*.slx binary merge=mlAutoMerge
*.slxp binary

## Other common binary file types
*.docx binary
*.exe binary
*.jpg binary
*.pdf binary
*.png binary
*.xlsx binary
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributing

>_If you believe you have discovered a security vulnerability, please **do not** open an issue or make a pull request. Follow the instructions in the [SECURITY.MD](SECURITY.MD) file in this repository._
Thank you for your interest in contributing to a MathWorks repository! We encourage contributions large and small to this repository.

**Contributions do not have to be code!** If you see a way to explain things more clearly or a great example of how to use something, please contribute it (or a link to your content). We welcome issues even if you don't code the solution. We also welcome pull requests to resolve issues that we haven't gotten to yet!

## How to contribute

* **Open an issue:** Start by [creating an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue) in the repository that you're interested in. That will start a conversation with the maintainer. When you are creating a bug report, please include as many details as possible. Please remember that other people do not have your background or understanding of the issue; make sure you are clear and complete in your description.
* **Work in your own public fork:** If you choose to make a contribution, you should [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo). This creates an editable copy on GitHub where you can write, test, and refine your changes. We suggest that you keep your changes small and focused on the issue you submitted.
* **Sign a Contributor License Agreement (CLA):** We require that all outside contributors sign a [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement) before we can accept your contribution. When you create a pull request (see below), we'll reach out to you if you do not already have one on file. Essentially, the CLA gives us permission to publish your contribution as part of the repository.
* **Make a pull request:** "[Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)" is a confusing term, but it means exactly what it says: You're requesting that the maintainers of the repository pull your changes in. If you don't have a CLA on file, we'll reach out to you. Your contribution will be reviewed, and we may ask you to revise your pull request based on our feedback. Once everyone is satisfied, we'll merge your pull request into the repository.

## Guidelines

We don't have best practices for writing MATLAB code, but we do have some recommendations:

* You should not have any warnings or errors in the [code analyzer report](http://www.mathworks.com/help/matlab/matlab_prog/matlab-code-analyzer-report.html)
* [Loren Shure's blog](https://blogs.mathworks.com/loren) has [great advice on improving your MATLAB code](https://blogs.mathworks.com/loren/category/best-practice/)
* Examples should be written as [live scripts](https://www.mathworks.com/help/matlab/matlab_prog/what-is-a-live-script-or-function.html) and then [exported as HTML](https://www.mathworks.com/help/matlab/matlab_prog/share-live-scripts.html).
* We adhere to the [CommonMark](https://commonmark.org/) specification where it does not conflict with GitHub rendering. If you edit your Markdown in Visual Studio Code or a similar editor, it uses [markdownlint](https://github.com/DavidAnson/markdownlint) to highlight issues in your Markdown.

**Again, thanks for contributing, and we look forward to your issues and pull requests!**
10 changes: 10 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Copyright (c) 2022, The MathWorks, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Unifying MATLAB and Simulink Example
<!-- This is the "Title of the contribution" that was approved during the Community Contribution Review Process -->

[![View <File Exchange Title> on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/####-file-exchange-title)
<!-- Add this icon to the README if this repo also appears on File Exchange via the "Connect to GitHub" feature -->

This repository contains two examples accompanying the series of blog posts titled [Unifying MATLAB and Simulink: A User Story](https://blogs.mathworks.com/simulink/2022/04/22/unifying-matlab-and-simulink-a-user-story-part-1) on [Guy on Simulink](https://blogs.mathworks.com/simulink/).

The workflow illustrated in this example systematically combines a MATLAB class and a Simulink Subsystem into a fundamental unit called **Simulink Part**.

![Unifying MATLAB and Simulink](https://blogs.mathworks.com/images/simulink/2022Q2/ML_SL.png)


The MATLAB class contains the data needed by the Simulink model along with methods. It can also include methods to pre- and post-process the data needed by and produced by the model.

![Parameterizing Simulink with MATLAB objects](https://blogs.mathworks.com/images/simulink/2022Q2/ClassUSedInModel.png)


Once the Simulink Part is placed in a model, the corresponding MATLAB object knows where it is being used, thanks to callbacks defined in a library of template blocks.

Simulink Parts can be assembled in a hierarchical manner, where a Simulink Part can become a property (child) of another Simulink Part. You can imagine the analogy with a garage or workshop with mechanical parts on shelves. Basic components like gears, nuts, bolts, springs and dampers can be assembled in systems like transmissions and suspensions, which can then be assembled into vehicles.

![A hierarchhy of Simulink Parts](https://blogs.mathworks.com/simulink/files/maskingEvolutionChapter1_13.png)

The model and corresponding MATLAB object can be configured using MATLAB code. See the walkthrough.mxl live scripts included in the project for examples:

![Live script describing how to configure the model programmatically](https://blogs.mathworks.com/images/simulink/2022Q2/liveScriptExample.png)


The model can also be configured using an app:

![System Confiurator App](https://blogs.mathworks.com/images/simulink/2022Q2/usingTheApp.png)

Copyright 2022 The MathWorks, Inc.

## Setup
To Run:
1. Execute **openSimulinkExample.m** or **openSimscapeExample.m** to open the corresponding project.
2. Each project contains a file "walkthrough.slx", see this file to get started

Additional information about the repository can be found on [Guy on Simulink](https://blogs.mathworks.com/simulink/2022/06/14/unifying-matlab-and-simulink-a-user-story-part-5/):

### MathWorks Products (http://www.mathworks.com)

Requires MATLAB release R2022a or newer
- [MATLAB](https://www.mathworks.com/products/matlab.html)
- [Simulink](https://www.mathworks.com/products/simulink.html)

Optional Products:
- [Simscape](https://www.mathworks.com/products/simscape.html)
- [Simscape Driveline](https://www.mathworks.com/products/simscape-driveline.html)


## Getting Started
To get started, execute **openSimulinkExample.m** or **openSimscapeExample.m** to open the corresponding project. Each project contains a live script walkthrough.mlx with details on how to get started.


## License

The license for [Unifying MATLAB and Simulink Example](https://github.com/mathworks/Unifying-MATLAB-and-Simulink-Example) is available in the [LICENSE.TXT](LICENSE.TXT) file in this GitHub repository.

## Community Support
[MATLAB Central](https://www.mathworks.com/matlabcentral)

6 changes: 6 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Reporting Security Vulnerabilities

If you believe you have discovered a security vulnerability, please report it to
[[email protected]](mailto:[email protected]). Please see
[MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html)
for additional information.
19 changes: 19 additions & 0 deletions SimscapeExample/+battery/Battery.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
classdef Battery < slPart
properties
BatteryVoltage
OutputVoltage
end

methods
function obj = Battery
obj.BatteryVoltage = 201.6;
obj.OutputVoltage = 500;
end

function plotPower(obj)
plot(obj.Log.get('power').Values)
end
end

end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+battery/Battery100Ah.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Battery100Ah < battery.Battery
methods
function obj = Battery100Ah
obj.BatteryVoltage = 201.6;
obj.OutputVoltage = 500;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+battery/Battery150Ah.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Battery150Ah < battery.Battery
methods
function obj = Battery150Ah
obj.BatteryVoltage = 201.6;
obj.OutputVoltage = 500;
end
end
end
% Copyright 2022 The MathWorks, Inc.
16 changes: 16 additions & 0 deletions SimscapeExample/+body/Body.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
classdef Body < slPart
properties
Mass
WheelRadius
InitialVelocity
end

methods
function obj = Body
obj.Mass = 1200;
obj.WheelRadius = 0.3;
obj.InitialVelocity = 15;
end
end
end
% Copyright 2022 The MathWorks, Inc.
10 changes: 10 additions & 0 deletions SimscapeExample/+body/CompactSedan.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
classdef CompactSedan < body.Body
methods
function obj = CompactSedan
obj.Mass = 800;
obj.WheelRadius = 0.25;
obj.InitialVelocity = 15;
end
end
end
% Copyright 2022 The MathWorks, Inc.
10 changes: 10 additions & 0 deletions SimscapeExample/+body/SUV.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
classdef SUV < body.Body
methods
function obj = SUV
obj.Mass = 2000;
obj.WheelRadius = 0.45;
obj.InitialVelocity = 15;
end
end
end
% Copyright 2022 The MathWorks, Inc.
10 changes: 10 additions & 0 deletions SimscapeExample/+body/Sedan.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
classdef Sedan < body.Body
methods
function obj = Sedan
obj.Mass = 1200;
obj.WheelRadius = 0.3;
obj.InitialVelocity = 15;
end
end
end
% Copyright 2022 The MathWorks, Inc.
14 changes: 14 additions & 0 deletions SimscapeExample/+drivetrain/+generator/Generator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef Generator < slPart
properties
MaximumPower
Efficiency
end

methods
function obj = Generator
obj.MaximumPower = 200;
obj.Efficiency = 97;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/+generator/Generator200kW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Generator200kW < drivetrain.generator.Generator
methods
function obj = Generator200kW
obj.MaximumPower = 200;
obj.Efficiency = 97;
end
end
end
% Copyright 2022 The MathWorks, Inc.
Binary file not shown.
14 changes: 14 additions & 0 deletions SimscapeExample/+drivetrain/+motor/Motor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef Motor < slPart
properties
MaximumPower
Efficiency
end

methods
function obj = Motor
obj.MaximumPower = 200;
obj.Efficiency = 97;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/+motor/Motor200kW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Motor200kW < drivetrain.motor.Motor
methods
function obj = Motor200kW
obj.MaximumPower = 200;
obj.Efficiency = 97;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/+motor/Motor300kW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Motor300kW < drivetrain.motor.Motor
methods
function obj = Motor300kW
obj.MaximumPower = 300;
obj.Efficiency = 97;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/+motor/Motor450kW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Motor450kW < drivetrain.motor.Motor
methods
function obj = Motor450kW
obj.MaximumPower = 450;
obj.Efficiency = 97;
end
end
end
% Copyright 2022 The MathWorks, Inc.
Binary file not shown.
14 changes: 14 additions & 0 deletions SimscapeExample/+drivetrain/Drivetrain.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef Drivetrain < slPart
properties
Motor {mustBeA(Motor,'drivetrain.motor.Motor')} = drivetrain.motor.Motor200kW
Generator
end

methods
function obj = Drivetrain
obj.Motor = drivetrain.motor.Motor200kW;
obj.Generator = drivetrain.generator.Generator200kW;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/Parallel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Parallel < drivetrain.Drivetrain
methods
function obj = Parallel
obj.Motor = drivetrain.motor.Motor200kW;
obj.Generator = [];
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/Series.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Series < drivetrain.Drivetrain
methods
function obj = Series
obj.Motor = drivetrain.motor.Motor200kW;
obj.Generator = drivetrain.generator.Generator200kW;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+drivetrain/Split.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Split < drivetrain.Drivetrain
methods
function obj = Split
obj.Motor = drivetrain.motor.Motor200kW;
obj.Generator = drivetrain.generator.Generator200kW;
end
end
end
% Copyright 2022 The MathWorks, Inc.
14 changes: 14 additions & 0 deletions SimscapeExample/+engine/Engine.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef Engine < slPart
properties
MaximumPower
Initial_rpm
end

methods
function obj = Engine
obj.MaximumPower = 50;
obj.Initial_rpm = 2000;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+engine/Engine100kW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Engine100kW < engine.Engine
methods
function obj = Engine100kW
obj.MaximumPower = 100;
obj.Initial_rpm = 2000;
end
end
end
% Copyright 2022 The MathWorks, Inc.
9 changes: 9 additions & 0 deletions SimscapeExample/+engine/Engine50kW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef Engine50kW < engine.Engine
methods
function obj = Engine50kW
obj.MaximumPower = 50;
obj.Initial_rpm = 2000;
end
end
end
% Copyright 2022 The MathWorks, Inc.
Loading

0 comments on commit 4e22071

Please sign in to comment.