-
Notifications
You must be signed in to change notification settings - Fork 3
Add autogen for AMDC article in control with AMDC folder #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Daehoon-Sung
wants to merge
135
commits into
main
Choose a base branch
from
feature/add-autogen-control-with-AMDC-article
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
135 commits
Select commit
Hold shift + click to select a range
efef0a4
Add indexme file for the Autogen
Daehoon-Sung 52120e3
Save the setup matlab file and simulink model
Daehoon-Sung 37cda4a
Update the matlab code
Daehoon-Sung 8be0727
Add gitignore and update the simulink
Daehoon-Sung 5155e62
Add auatogen code
Daehoon-Sung 0637235
Update the simulink
Daehoon-Sung 968d3bb
Update the images
Daehoon-Sung c8b9457
Update the images
Daehoon-Sung 983a023
Revise index.md for Simulink code generation guide
Daehoon-Sung 8599a94
Revise Simulink model setup and C-code generation steps
Daehoon-Sung 2977772
Update image width in autogen index markdown
Daehoon-Sung 0c425e7
Update image width for integrator model in index.md
Daehoon-Sung 620303f
Update index.md
Daehoon-Sung 23000c9
Rename files
noguchi-takahiro 378b580
Update m code in the article
noguchi-takahiro 59594ee
Rename images and update document
noguchi-takahiro 4426256
Update readme
noguchi-takahiro f5abcd8
Update bullet points
noguchi-takahiro af99cff
Update size of figure
noguchi-takahiro b5670f8
Add overview of Autogen
noguchi-takahiro 6b48e2b
Update README
noguchi-takahiro 16ed4ff
Update readme
noguchi-takahiro 2fa6045
Update README
noguchi-takahiro 798529b
Update readme
noguchi-takahiro 213c357
Update indent
noguchi-takahiro 4afe976
Add period
noguchi-takahiro a2e5724
Update readme
noguchi-takahiro cd8ac9e
Update readme
noguchi-takahiro 142ebd0
Update REAMDE
noguchi-takahiro a6f53a9
Update article
noguchi-takahiro f1a9485
Remove not used picture
noguchi-takahiro 0a2d06c
Add autogen for AMDC article in control with AMDC folder
Daehoon-Sung 18ed30f
Enhance clarity and structure of AMDC control documentation
Daehoon-Sung a514784
Revise documentation for Simulink and AMDC integration
Daehoon-Sung 413ce16
Expand documentation on Simulink Autogen workflow
Daehoon-Sung 9a8d050
Clarify example model and Simulink integration details
Daehoon-Sung dbcb2e8
Update AMDC integration details in index.md
Daehoon-Sung 2d49b3e
Update index.md for Autogen and path constraints
Daehoon-Sung d0cfc3a
Fix minor grammatical issues in index.md
Daehoon-Sung 2622d53
Fix formatting and punctuation in index.md
Daehoon-Sung a311d0a
Change image format for autogen example diagram
Daehoon-Sung 92bc771
Add the example code and simulink file
Daehoon-Sung ae76806
Refine conclusion in index.md
Daehoon-Sung eadd04c
Change the name of the file
Daehoon-Sung 3e16a9c
Fix image reference in auto-gen documentation
Daehoon-Sung 9b069f2
Refine documentation on Simulink Autogen code structure
Daehoon-Sung 9ebd0ac
Add control algorithm function to documentation
Daehoon-Sung 5f2501f
Fix spacing
noguchi-takahiro 380dc81
Update source/getting-started/control-with-amdc/auto-gen/index.md
Daehoon-Sung 257320f
Update source/getting-started/control-with-amdc/auto-gen/index.md
Daehoon-Sung cf3f57e
Update source/getting-started/control-with-amdc/auto-gen/index.md
Daehoon-Sung 48e38a0
Update source/getting-started/control-with-amdc/auto-gen/index.md
Daehoon-Sung bc2db18
Update source/getting-started/control-with-amdc/auto-gen/index.md
Daehoon-Sung d05c1a0
Update index.md with development environment details
Daehoon-Sung be7c52b
Revise folder structure for autogenerated files
Daehoon-Sung 57125f5
Refactor integration notes and file constraints section
Daehoon-Sung 7761e4e
Move autogen article to tutorial folder
noguchi-takahiro 44db7bb
Rename folder
noguchi-takahiro 5172b6d
Update index
noguchi-takahiro 7126b87
Merge branch 'feature/add-autogen' into feature/add-autogen-control-w…
noguchi-takahiro 118af07
Update index
noguchi-takahiro 09fea6b
Update README
noguchi-takahiro c704c03
Update index
noguchi-takahiro 1119a87
Remove integrator and add duty ratio block
noguchi-takahiro 5a64baf
Add image, check out this commit to edit the image
noguchi-takahiro 9b9258a
Create subsystem, check out this to update image 2
noguchi-takahiro 1db7955
Update function
noguchi-takahiro 0536387
Update index
noguchi-takahiro b5fc409
Export model as r2024b
noguchi-takahiro f513bf5
Update REAMDE
noguchi-takahiro a6607e9
Update readme
noguchi-takahiro 1dad987
Update readme
noguchi-takahiro 70b2e6f
Update README
noguchi-takahiro 8a74150
Update index
noguchi-takahiro c2f5c9b
Update index
noguchi-takahiro 6b34a95
Fix link
noguchi-takahiro 93e6f4d
Update index
noguchi-takahiro 95b0753
Updte model
noguchi-takahiro 53f89f5
Update model
noguchi-takahiro 8404248
Update image
noguchi-takahiro 02759fc
Update index
noguchi-takahiro 6995237
Add block diagram image
noguchi-takahiro fed8f71
Refactor background section for clarity and conciseness
Daehoon-Sung f69fa48
Rephrase explanation of Automatic Code Generation
Daehoon-Sung 4ad88be
Clarify description of Automatic Code Generation process
Daehoon-Sung 0590f1a
Clarify Automatic Code Generation process for AMDC
Daehoon-Sung 6d689be
Enhance documentation with link to discrete time blocks
Daehoon-Sung 649747c
Enhance workflow steps with additional details
Daehoon-Sung 7838a47
Update wording for referenced models information
Daehoon-Sung 6b6d241
Fix grammar in integration step for AMDC project
Daehoon-Sung f405aa3
Update links and formatting in index.md
Daehoon-Sung 7bc06b4
Merge branch 'feature/add-autogen-control-with-AMDC-article' of https…
noguchi-takahiro a3a5d07
Enhance documentation with links for clarity
Daehoon-Sung 389d147
Enhance documentation on Simulink and AMDC workflow
Daehoon-Sung bcffa3c
Merge branch 'feature/add-autogen-control-with-AMDC-article' of https…
noguchi-takahiro a69752a
Add block diagram
noguchi-takahiro 949eef5
Update index
noguchi-takahiro 2f7d0ce
Update autogen path
noguchi-takahiro 41665b0
Update path
noguchi-takahiro 544001a
Update variables
noguchi-takahiro 13d5807
Update and works
noguchi-takahiro 522b5b8
Update comment
noguchi-takahiro f8efbeb
Fix typo
noguchi-takahiro b1d9601
Update README
noguchi-takahiro 97b9ecf
Remobe old images
noguchi-takahiro 9203f44
Update figure
noguchi-takahiro 5c9c42b
Update images
noguchi-takahiro 2de1ed8
Export as 2024b
noguchi-takahiro 7e8bf47
Update tutorial index
noguchi-takahiro 874f222
Update index for Autogen article
noguchi-takahiro 527243a
Revise sentence based on reviewer
noguchi-takahiro 66b0998
Update source/getting-started/tutorials/autogen/index.md
noguchi-takahiro 6cbfb15
Update autogen code
noguchi-takahiro e2f017c
Merge branch 'feature/add-autogen-control-with-AMDC-article' of https…
noguchi-takahiro a3a04f0
Fix link
noguchi-takahiro c7cf610
Rename the variables to follow naming convention
mhmokhtarabadi 1218931
Update the tutorial based on new variable names
mhmokhtarabadi 2cf1960
Add dark version of block diagram figure
mhmokhtarabadi 718612b
Update model figures based on new simulations
mhmokhtarabadi fdc4c11
Merge branch 'main' into feature/add-autogen-control-with-AMDC-article
mhmokhtarabadi 883ff1d
Add dark-mode image
mhmokhtarabadi 68a9f76
Change variable name in C-code based on changes in model
mhmokhtarabadi 389f456
Update images
noguchi-takahiro 186a23a
Update index article
noguchi-takahiro 378507d
Update tutorial index
noguchi-takahiro f2f53d5
Update index
noguchi-takahiro ad9323e
Update index
noguchi-takahiro e8dd7d0
Update index
noguchi-takahiro 58be2fe
Update index
noguchi-takahiro 3dc0c22
Update index
noguchi-takahiro 93083ae
Fix typo
noguchi-takahiro 4d0b99d
Update article title
noguchi-takahiro 89a2151
Update images
noguchi-takahiro d73a175
Fix typo
noguchi-takahiro 6592d70
Merge branch 'main' into feature/add-autogen-control-with-AMDC-article
noguchi-takahiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Firmware Development Using Simulink Code Generation | ||
|
|
||
| ## Background | ||
|
|
||
| Simulink provides a MATLAB-based graphical environment for modeling and simulating control systems. It is extensively used to model, simulate, and analyze complex dynamical systems, including motor drives. Its user-friendly block diagram environment in Simulink allows control algorithm to be developed and validated in simulation before they are implemented on the embedded hardware. | ||
|
|
||
| To apply the controller developed in Simulink to the AMDC platform, we use Simulink [Code Generation](https://www.mathworks.com/help/simulink/code-generation.html) and [Embedded Coder](https://www.mathworks.com/help/ecoder/index.html) capabilities provided by MathWorks to generate C code from Simulink models for embedded implementation. This article describes how these MathWorks code generation practices can be applied to the AMDC platform. In this article, this workflow is referred to as **Autogen** (Automatic Code Generation). | ||
|
|
||
| ## Development Approach with Simulink and AMDC | ||
|
|
||
| The figure below shows the Simulink + AMDC workflow, which separates control development into two domains: | ||
|
|
||
| - **Design domain (Simulink):** | ||
| The control algorithm is developed and validated using a graphical model. | ||
|
|
||
| - **Execution domain (AMDC):** | ||
| The generated C code is executed in real time on the embedded controller at a fixed time interval. | ||
|
|
||
| ```{image} resources/block-diagram.svg | ||
| :height: 10em | ||
| :class: only-light | ||
| ``` | ||
|
|
||
| ```{image} resources/block-diagram-dark.svg | ||
| :height: 10em | ||
| :class: only-dark | ||
| ``` | ||
|
|
||
| Structure the Simulink model into three subsystems, as follows: | ||
|
|
||
|
noguchi-takahiro marked this conversation as resolved.
|
||
| 1. **Input/Output (I/O):** Use this for simulation and visualization only | ||
| 2. **Plant:** Use this subsystem to represent the physical system for simulation | ||
| 3. **Controller:** Place the control algorithm to be deployed in this subsystem | ||
|
|
||
| Within the AMDC domain, the deployed controller is implemented in the DSP user app. The user app communicate with the FPGA-based sensor and PWM interfaces. See the related articles for more information on [User Apps](../../../firmware/arch/index.md#user-apps) and [PWM interface](https://docs.amdc.dev/getting-started/tutorials/vsi/index.html). | ||
|
|
||
| ### Recommended Workflow | ||
|
|
||
| The recommended workflow for developing control code is: | ||
|
|
||
| 1. Develop and validate the control algorithm in Simulink. | ||
| 2. Convert the controller to an atomic subsystem and then to a [referenced model](https://www.mathworks.com/help/simulink/model-reference.html). | ||
| 3. Generate C code using Simulink Autogen. | ||
| 4. Integrate the generated code into the AMDC project. | ||
| 5. Execute and validate on hardware. | ||
|
|
||
| ## Key Implementation Requirements and Best Practices | ||
|
|
||
| For successful development and integration of control code, follow the implementations requirements and best practices below: | ||
|
|
||
| - **Discrete-Time Implementation**: All blocks within the controller must be [discrete-time](https://www.mathworks.com/help/simulink/discrete.html), since the AMDC executes control logic at fixed sampling intervals. | ||
| - **Fixed-Step Solver**: The Simulink model must use a [fixed-step solver](https://www.mathworks.com/help/simulink/ug/fixed-step-solvers-in-simulink.html) to ensure compatibility with real-time execution. | ||
| - **Consistent Sample Time**: The entire controller subsystem should operate at a single, well-defined sample time before converting to an atomic subsystem and creating a referenced model. | ||
| - **Code Generation Settings**: The code generation target should be set to Embedded Coder (`ert.tlc`). The build configuration should enable "Generate Code Only". | ||
| - **Referenced Model Usage**: The controller subsystem should be converted to an [atomic subsystem](https://www.mathworks.com/help/simulink/slref/subsystem.html#mw_f323006c-a286-47ea-85e6-a692c87bdabe), then converted to a referenced model. Any updates to model settings should be performed after opening the referenced model as the top model. | ||
| - **AMDC Integration Details** | ||
| - All generated source (`*.c`) and header (`*.h`) files must be included in the AMDC project. | ||
| - The autogenerated folder must be added to the compiler include paths. | ||
| - Do not delete any generated files, as some auxiliary files may be required during compilation. | ||
| - **File and Path Constraints** | ||
| - File paths must not contain whitespace. | ||
| - The path to the folder containing the MATLAB script and the Simulink model, as well as any parent directory, must not include whitespace. Otherwise, it will result in a build error. | ||
|
|
||
| This organization ensures that the autogenerated controller code is correctly compiled and integrated into the AMDC firmware. | ||
|
|
||
| ## Example Model | ||
|
|
||
| An example tutorial, [Tutorial: Autogen](../../tutorials/autogen/index.md), is provided to demonstrate the Simulink Autogen workflow for control implementation and its integration with the AMDC. | ||
|
|
||
| ## Conclusion | ||
|
|
||
| The Simulink Autogen workflow provides a structured and efficient approach for implementing control algorithms on the AMDC. By separating control design from embedded implementation, this approach enables: | ||
|
|
||
| - Rapid development and iteration | ||
| - Improved reliability through simulation | ||
| - Clear mapping between design and execution | ||
|
|
||
| This methodology is recommended for developing advanced control systems on the AMDC platform. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.