Simulink's PLC Code generator and automatic generated lines meaning
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to take a simulink stateflow chart, and use the PLC Code generator to transform my chart into a PLC code in ST.
Now, everytime I do this, a bunch of code lines, that have nothing to do with the original chart, are added.
The new variables added are:
"ssMethodType: SINT;"
"is_active_c3_Chart: USINT;"
"is_c3_Chart: USINT;"
Which afterwards in a case expression with two more newly
CASE ssMethodType OF
SS_INITIALIZE:
(* SystemInitialize for Chart: '<Root>/Chart' *)
is_active_c3_Chart := 0;
is_c3_Chart := Chart_IN_NO_ACTIVE_CHILD;
SS_STEP:
(* Chart: '<Root>/Chart' incorporates:
* Outport: '<Root>/Out1'
* Outport: '<Root>/Out2' *)
(* Gateway: Chart *)
(* During: Chart *)
IF is_active_c3_Chart = 0 THEN
(* Entry: Chart *)
is_active_c3_Chart := 1;
(* Entry Internal: Chart *)
is_c3_Chart := Chart_IN_State0
Now I don't understand any of this to be honest. What is the purpose of those "ss" variables and what is the meaning of this case expression? And what is "Chart_IN_NO_ACTIVE_CHILD;" supposed to mean? I'm new to Simulink, and couln't find the answer online.
Thank you very much
0 个评论
回答(1 个)
Uday Pradhan
2020-12-15
编辑:Uday Pradhan
2020-12-15
Hi Leonardo,
You can more information about these variables from this documentation page. As an overview: ssMethodType enables you to execute code for Simulink Subsystem block methods such as initialization and computation steps. The generated code executes the associated CASE statement based on the value passed in for this argument. The CASE statement block is where the logical flow of your chart, internal states and state transitions are implemented.
The values of SS_INITIALIZE and SS_STEP are usually defined at the bottom of the generated PLC code. The Chart_IN_NO_ACTIVE_CHILD is usually a variable that denotes that the chart has no active internal states. This is the initial value for is_c3_Chart. The is_c3_chart variable will change values as we transition from one internal state to other. All the internal states have distinct values assigned to them. As an example:
VAR_GLOBAL CONSTANT
Chart_IN_NO_ACTIVE_CHILD: USINT := 0;
Chart_IN_Seeking: USINT := 1;
Chart_IN_Seeking2: USINT := 2;
Chart_IN_Tracking: USINT := 3;
Chart_IN_Waiting: USINT := 4;
SS_INITIALIZE: SINT := 0;
SS_STEP: SINT := 1;
END_VAR
In this case, I have states which are internal to the chart I generated PLC code for(see attched screenshot of chart). These states are namely: Seeking, Seeking2, Tracking, Waiting and hence the corresponding variables in the Structured Text generated by the Coder. The is_c3_Chart variable switches values between these variables according to the transition conditions and logic implemented in the Chart.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!