Simulink Autosar code generation for Algebraic loop

2 visualizzazioni (ultimi 30 giorni)
Tejas
Tejas il 21 Set 2023
Risposto: Tejas il 27 Set 2023
Hello,
I have this demo model, which I generated Autosar code from the model.... How I can check in the code generated from simulink will execute the algebraic loop.... When I checked the code, there is no loop is executing, I mean it's just adding input constant 1 with delay block only....How to be sure the output from the loop is adding with input?
#include "Test_case1.h"
#include "Test_case1_private.h"
/* Block states (default storage) */
DW_Test_case1_T Test_case1_DW;
/* Model step function */
void Test_case1_Step(void)
{
/* If: '<Root>/If1' incorporates:
* Constant: '<Root>/Constant'
* Inport: '<S1>/In1'
* Sum: '<Root>/Add1'
* UnitDelay: '<Root>/Unit Delay1'
*/
if (((float32)(Test_case1_DW.UnitDelay1_DSTATE + 1.0) < 0.0F) ||
((Test_case1_ConstB.DataTypeConversion <= 1.0F) ||
(Test_case1_ConstB.DataTypeConversion >= 3.0F))) {
/* Outputs for IfAction SubSystem: '<Root>/If Action Subsystem3' incorporates:
* ActionPort: '<S2>/Action Port'
*/
/* SignalConversion generated from: '<S2>/output1' incorporates:
* Constant: '<S2>/Constant'
*/
Test_case1_DW.UnitDelay1_DSTATE = 0.0F;
/* End of Outputs for SubSystem: '<Root>/If Action Subsystem3' */
} else {
/* Outputs for IfAction SubSystem: '<Root>/If Action Subsystem1' incorporates:
* ActionPort: '<S1>/Action Port'
*/
Test_case1_DW.UnitDelay1_DSTATE = (float32)(Test_case1_DW.UnitDelay1_DSTATE
+ 1.0);
/* End of Outputs for SubSystem: '<Root>/If Action Subsystem1' */
}
/* End of If: '<Root>/If1' */
}
/* Model initialize function */
void Test_case1_Init(void)
{
/* (no initialization code required) */
}
/*
anyfeedabck appreciated, thank you!

Risposte (2)

Yatharth
Yatharth il 27 Set 2023
Hi Tejas,
I understand that you are not able to find algebraic loop in the generated code and want to know a way to confirm whether the loop was implemented in the generated code.
Based on the code you provided, it seems that the algebraic loop in your Simulink model has been resolved during the code generation process. In the generated code, the output of the loop is not explicitly added to the input, but it is updated based on the conditions specified in the "If" statement.
According to Simulink Documentation you cannot directly generate code of a Simulink model that contains algebraic loops, hence using certain configurations the algebraic loops are removed from the model.
You can read more about it here.
A summary of what is happening with your code:
  1. When you generated the code from your Simulink model, the code generation process resolved the algebraic loop by transforming it into a sequence of calculations.
  2. In the generated code, you will not see a direct loop structure. Instead, you will find conditional statements that determine how the output is updated based on the input.
  3. The code you provided shows an "If" statement that checks certain conditions. If the conditions are met, the output variable “Test_case1_DW.UnitDelay1_DSTATE ” is updated accordingly.
To verify that the output from the loop is being added to the input, you can follow these steps:
  1. Identify the input and output variables in your Simulink model.
  2. Locate the corresponding variables in the generated code. In this case, the input variable is likely to be “Test_case1_ConstB.DataTypeConversion” and the output variable is “Test_case1_DW.UnitDelay1_DSTATE”.
  3. Look for the section of code where the output variable is updated. In this case, it is updated in the "If Action Subsystem1" block.
  4. Check if the output variable is being modified based on the input variable. In this case, it is incremented by 1 “Test_case1_DW.UnitDelay1_DSTATE”.
By examining the code, you can confirm that the output from the loop is being updated based on the input, even though there is no explicit addition operation.
I hope this helps.

Tejas
Tejas il 27 Set 2023
Thanks alot for the detailed answer.... I see, I need to track back the code input/output signals to check whether it's getting right output or not.

Categorie

Scopri di più su AUTOSAR Blockset in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by