Files
foc/OpenController/Open0.c
2026-02-23 21:13:00 +08:00

341 lines
9.7 KiB
C

/*
* Academic License - for use in teaching, academic research, and meeting
* course requirements at degree granting institutions only. Not for
* government, commercial, or other organizational use.
*
* File: Open0.c
*
* Code generated for Simulink model 'Open0'.
*
* Model version : 2.23
* Simulink Coder version : 25.1 (R2025a) 21-Nov-2024
* C/C++ source code generated on : Sat Jun 14 14:25:03 2025
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex-M
* Code generation objectives:
* 1. Execution efficiency
* 2. RAM efficiency
* Validation result: Not run
*/
#include "include/Open0.h"
#include <math.h>
#include "include/rtwtypes.h"
/* External inputs (root inport signals with default storage) */
ExtU rtU;
/* External outputs (root outports fed by signals with default storage) */
ExtY rtY;
/* Real-time model */
static RT_MODEL rtM_;
RT_MODEL *const rtM = &rtM_;
/* Model step function */
void Open0_step(void)
{
real_T rtb_Switch_idx_0;
real_T rtb_convert_pu;
real_T rtb_sum_beta;
real32_T T_idx_0;
real32_T T_idx_1;
real32_T T_idx_3;
real32_T T_idx_4;
real32_T d_Temp;
uint16_T rtb_Get_Integer;
/* Gain: '<S11>/convert_pu' incorporates:
* Inport: '<Root>/theta'
*/
rtb_convert_pu = 0.15915494309189535 * rtU.theta;
/* If: '<S11>/If' incorporates:
* Constant: '<S13>/Constant'
* DataTypeConversion: '<S14>/Convert_back'
* DataTypeConversion: '<S14>/Convert_uint16'
* DataTypeConversion: '<S15>/Convert_back'
* DataTypeConversion: '<S15>/Convert_uint16'
* Gain: '<S9>/indexing'
* RelationalOperator: '<S13>/Compare'
* Sum: '<S14>/Sum'
* Sum: '<S15>/Sum'
*/
if (rtb_convert_pu < 0.0) {
/* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem' incorporates:
* ActionPort: '<S14>/Action Port'
*/
rtb_Switch_idx_0 = rtb_convert_pu - (real_T)(int16_T)floor(rtb_convert_pu);
/* End of Outputs for SubSystem: '<S11>/If Action Subsystem' */
} else {
/* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem1' incorporates:
* ActionPort: '<S15>/Action Port'
*/
rtb_Switch_idx_0 = rtb_convert_pu - (real_T)(int16_T)rtb_convert_pu;
/* End of Outputs for SubSystem: '<S11>/If Action Subsystem1' */
}
rtb_convert_pu = 800.0 * rtb_Switch_idx_0;
/* End of If: '<S11>/If' */
/* DataTypeConversion: '<S9>/Get_Integer' */
rtb_Get_Integer = (uint16_T)rtb_convert_pu;
/* Sum: '<S9>/Sum2' incorporates:
* DataTypeConversion: '<S9>/Data Type Conversion1'
* DataTypeConversion: '<S9>/Get_Integer'
*/
rtb_sum_beta = rtb_convert_pu - (real_T)(uint16_T)rtb_convert_pu;
/* Selector: '<S9>/Lookup' incorporates:
* Constant: '<S9>/sine_table_values'
* DataTypeConversion: '<S9>/Get_Integer'
*/
rtb_Switch_idx_0 = rtConstP.sine_table_values_Value[(uint16_T)rtb_convert_pu];
/* Sum: '<S10>/Sum4' incorporates:
* Constant: '<S9>/offset'
* Constant: '<S9>/sine_table_values'
* DataTypeConversion: '<S9>/Get_Integer'
* Product: '<S10>/Product'
* Selector: '<S9>/Lookup'
* Sum: '<S10>/Sum3'
* Sum: '<S9>/Sum'
*/
rtb_convert_pu = (rtConstP.sine_table_values_Value[(int32_T)((uint16_T)
rtb_convert_pu + 1U)] - rtb_Switch_idx_0) * rtb_sum_beta + rtb_Switch_idx_0;
/* Selector: '<S9>/Lookup' incorporates:
* Constant: '<S9>/offset'
* Constant: '<S9>/sine_table_values'
* Sum: '<S10>/Sum5'
* Sum: '<S9>/Sum'
*/
rtb_Switch_idx_0 = rtConstP.sine_table_values_Value[(int32_T)(rtb_Get_Integer
+ 200U)];
/* Sum: '<S10>/Sum6' incorporates:
* Constant: '<S9>/offset'
* Constant: '<S9>/sine_table_values'
* Product: '<S10>/Product1'
* Selector: '<S9>/Lookup'
* Sum: '<S10>/Sum5'
* Sum: '<S9>/Sum'
*/
rtb_sum_beta = (rtConstP.sine_table_values_Value[(int32_T)(rtb_Get_Integer +
201U)] - rtb_Switch_idx_0) * rtb_sum_beta + rtb_Switch_idx_0;
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
/* Switch: '<S17>/Switch' incorporates:
* Inport: '<Root>/Ud'
* Inport: '<Root>/Uq'
* Product: '<S8>/dcos'
* Product: '<S8>/dsin'
* Product: '<S8>/qcos'
* Product: '<S8>/qsin'
* Sum: '<S8>/sum_alpha'
* Sum: '<S8>/sum_beta'
*/
rtb_Switch_idx_0 = rtU.Ud * rtb_sum_beta - rtU.Uq * rtb_convert_pu;
rtb_convert_pu = rtU.Uq * rtb_sum_beta + rtU.Ud * rtb_convert_pu;
/* MATLAB Function: '<S3>/MATLAB Function2' incorporates:
* AlgorithmDescriptorDelegate generated from: '<S8>/a16'
*/
switch (((((real32_T)rtb_convert_pu - (real32_T)rtb_Switch_idx_0 * 1.73205078F
> 0.0F) << 2) + (((real32_T)rtb_Switch_idx_0 * 1.73205078F +
(real32_T)rtb_convert_pu > 0.0F) << 1)) + ((real32_T)rtb_convert_pu
<= 0.0F)) {
case 1:
T_idx_0 = 5.0F;
break;
case 2:
T_idx_0 = 1.0F;
break;
case 3:
T_idx_0 = 6.0F;
break;
case 4:
T_idx_0 = 3.0F;
break;
case 5:
T_idx_0 = 4.0F;
break;
case 6:
T_idx_0 = 2.0F;
break;
default:
T_idx_0 = -1.0F;
break;
}
/* End of MATLAB Function: '<S3>/MATLAB Function2' */
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
/* MATLAB Function: '<S3>/MATLAB Function1' incorporates:
* AlgorithmDescriptorDelegate generated from: '<S8>/a16'
* Constant: '<S3>/Constant'
* Constant: '<S3>/Constant1'
*/
switch ((int32_T)T_idx_0) {
case 1:
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
T_idx_4 = (real32_T)(2.0 * rtb_convert_pu) * 1800.0F / 1.73205078F / 8.0F;
T_idx_3 = (real32_T)(rtb_Switch_idx_0 - rtb_convert_pu / 1.7320508075688772)
* 1800.0F / 8.0F;
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
T_idx_1 = T_idx_4;
d_Temp = T_idx_3 + T_idx_4;
if (d_Temp > 1800.0F) {
d_Temp = 1800.0F / d_Temp;
T_idx_3 *= d_Temp;
T_idx_1 = T_idx_4 * d_Temp;
}
d_Temp = ((1800.0F - T_idx_3) - T_idx_1) / 2.0F;
T_idx_3 = (T_idx_3 + T_idx_1) + d_Temp;
T_idx_1 += d_Temp;
break;
case 2:
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
rtb_convert_pu /= 1.7320508075688772;
T_idx_1 = (real32_T)(rtb_convert_pu - rtb_Switch_idx_0) * 1800.0F / 8.0F;
T_idx_4 = (real32_T)(rtb_convert_pu + rtb_Switch_idx_0) * 1800.0F / 8.0F;
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
d_Temp = T_idx_1 + T_idx_4;
if (d_Temp > 1800.0F) {
d_Temp = 1800.0F / d_Temp;
T_idx_1 *= d_Temp;
T_idx_4 *= d_Temp;
}
d_Temp = ((1800.0F - T_idx_1) - T_idx_4) / 2.0F;
T_idx_3 = T_idx_4 + d_Temp;
T_idx_1 = (T_idx_1 + T_idx_4) + d_Temp;
break;
case 3:
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
T_idx_1 = (real32_T)(1.7320508075688772 * rtb_convert_pu) * 1800.0F / 12.0F;
T_idx_4 = -((real32_T)(1.5 * rtb_Switch_idx_0 + 0.8660254037844386 *
rtb_convert_pu) * 150.0F);
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
d_Temp = T_idx_1 + T_idx_4;
if (d_Temp > 1800.0F) {
d_Temp = 1800.0F / d_Temp;
T_idx_1 *= d_Temp;
T_idx_4 *= d_Temp;
}
d_Temp = ((1800.0F - T_idx_1) - T_idx_4) / 2.0F;
T_idx_3 = d_Temp;
T_idx_1 = (T_idx_1 + T_idx_4) + d_Temp;
d_Temp += T_idx_4;
break;
case 4:
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
T_idx_0 = (real32_T)(-2.0 * rtb_convert_pu) * 1800.0F / 1.73205078F / 8.0F;
T_idx_4 = (real32_T)(rtb_convert_pu / 1.7320508075688772 - rtb_Switch_idx_0)
* 1800.0F / 8.0F;
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
d_Temp = T_idx_0 + T_idx_4;
if (d_Temp > 1800.0F) {
d_Temp = 1800.0F / d_Temp;
T_idx_0 *= d_Temp;
T_idx_4 *= d_Temp;
}
d_Temp = ((1800.0F - T_idx_0) - T_idx_4) / 2.0F;
T_idx_3 = d_Temp;
T_idx_1 = T_idx_4 + d_Temp;
d_Temp += T_idx_0 + T_idx_4;
break;
case 5:
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
rtb_convert_pu = -rtb_convert_pu / 1.7320508075688772;
T_idx_0 = (real32_T)(rtb_convert_pu - rtb_Switch_idx_0) * 1800.0F / 8.0F;
T_idx_4 = (real32_T)(rtb_convert_pu + rtb_Switch_idx_0) * 1800.0F / 8.0F;
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
d_Temp = T_idx_0 + T_idx_4;
if (d_Temp > 1800.0F) {
d_Temp = 1800.0F / d_Temp;
T_idx_0 *= d_Temp;
T_idx_4 *= d_Temp;
}
d_Temp = ((1800.0F - T_idx_0) - T_idx_4) / 2.0F;
T_idx_3 = T_idx_4 + d_Temp;
T_idx_1 = d_Temp;
d_Temp += T_idx_0 + T_idx_4;
break;
case 6:
/* Outputs for Atomic SubSystem: '<S6>/Two inputs CRL' */
T_idx_4 = (real32_T)(-2.0 * rtb_convert_pu) * 1800.0F / 1.73205078F / 8.0F;
T_idx_3 = (real32_T)(rtb_convert_pu / 1.7320508075688772 + rtb_Switch_idx_0)
* 1800.0F / 8.0F;
/* End of Outputs for SubSystem: '<S6>/Two inputs CRL' */
d_Temp = T_idx_3 + T_idx_4;
if (d_Temp > 1800.0F) {
d_Temp = 1800.0F / d_Temp;
T_idx_3 *= d_Temp;
T_idx_4 *= d_Temp;
}
d_Temp = ((1800.0F - T_idx_3) - T_idx_4) / 2.0F;
T_idx_3 = (T_idx_3 + T_idx_4) + d_Temp;
T_idx_1 = d_Temp;
d_Temp += T_idx_4;
break;
}
/* Outport: '<Root>/CCR1' incorporates:
* Constant: '<S3>/Constant1'
* MATLAB Function: '<S3>/MATLAB Function1'
*/
rtY.CCR1 = (1800.0F - T_idx_3) / 2.0F;
/* Outport: '<Root>/CCR2' incorporates:
* Constant: '<S3>/Constant1'
* MATLAB Function: '<S3>/MATLAB Function1'
*/
rtY.CCR2 = (1800.0F - T_idx_1) / 2.0F;
/* Outport: '<Root>/CCR3' incorporates:
* Constant: '<S3>/Constant1'
* MATLAB Function: '<S3>/MATLAB Function1'
*/
rtY.CCR3 = (1800.0F - d_Temp) / 2.0F;
}
/* Model initialize function */
void Open0_initialize(void)
{
/* (no initialization code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/