필터 지우기
필터 지우기

Is it possible to have a user defined sample time for compiled Simulink code?

조회 수: 3 (최근 30일)
Setup:
My process consists of building Simulink models, followed by building the code (ie. generating the C-code from Simulink), and finally compiling the C-code in a separate environment (such as Linux).
Problem statement:
I would like follow the above process, however the "ask" is that the final compilation be able to work on 2 systems, each with their own distinct sample time. One solution on my part would be to make two executables, each compiled with their own sample time. Alternatively, would it be possible to have the sample time as an input for the executable? So that I would have 1 executable package and the user could specify whatever sample time was needed.

답변 (1개)

Raghava S N
Raghava S N 2023년 7월 14일
Yes, it is possible to make the sample time of your Simulink model configurable at runtime, allowing the user to specify the desired sample time when executing the generated code. This approach would enable you to have a single executable package that can work with different sample times.
Here's a suggested approach to achieve this:
  1. Design your Simulink model: Build your Simulink model with a configurable sample time parameter. You can use a MATLAB workspace variable or a Simulink block parameter to represent the sample time.
  2. Generate C code: Use Simulink Coder to generate the C code from your Simulink model. Ensure that the sample time parameter is appropriately propagated to the generated code.
  3. Create a command-line interface: Develop a command-line interface or a user interface that allows the user to input the desired sample time value. This can be done using MATLAB functions or external tools, depending on your preference.
  4. Modify the generated code: Within the generated C code, modify the section that sets the sample time to retrieve the user-specified value. This can be done by reading the input from the command-line interface or any other method you choose.
  5. Compile the code: Compile the modified C code using your desired build environment (e.g., Linux). Ensure that the necessary dependencies and libraries are included during the compilation process.
By following this approach, you will have a single executable package that can be used on different systems with distinct sample times. The user will be able to specify the sample time as an input when executing the compiled code.
It's important to note that this approach requires additional development and customization beyond the standard Simulink code generation process. You will need to modify the generated code and create the necessary user interface to handle the sample time input.
  댓글 수: 1
Travis Thomson
Travis Thomson 2023년 7월 14일
편집: Travis Thomson 2023년 7월 14일
Thank you Raghava, I think the step i had missed was setting the sample time variable storage class to "ImportedExtern" after selecting "Build Model" in Simulink. Using "ImportedExtern" retains the sample time variable in C-code (as opposed to the default "Inlined" which replaces all variable instances with the value itself in the C-code. Your solution worked.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by