matlab ok
This commit is contained in:
@@ -0,0 +1,713 @@
|
||||
/*
|
||||
* File: control.c
|
||||
*
|
||||
* Code generated for Simulink model 'control'.
|
||||
*
|
||||
* Model version : 1.178
|
||||
* Simulink Coder version : 24.1 (R2024a) 19-Nov-2023
|
||||
* C/C++ source code generated on : Thu Sep 11 17:14:08 2025
|
||||
*
|
||||
* Target selection: ert.tlc
|
||||
* Embedded hardware selection: ARM Compatible->ARM Cortex
|
||||
* Code generation objectives: Unspecified
|
||||
* Validation result: Not run
|
||||
*/
|
||||
|
||||
#include "control.h"
|
||||
#include "rtwtypes.h"
|
||||
#include <math.h>
|
||||
#include "rt_nonfinite.h"
|
||||
#include "RunModeEnumType.h"
|
||||
#include "control_private.h"
|
||||
#include "RunstateEnumType.h"
|
||||
#include "BatteryEnumType.h"
|
||||
#include "control_capi.h"
|
||||
|
||||
/* Named constants for Chart: '<Root>/state' */
|
||||
#define control_IN_BalanceMode ((uint8_T)1U)
|
||||
#define control_IN_CCMode ((uint8_T)2U)
|
||||
#define control_IN_CVMode ((uint8_T)3U)
|
||||
#define control_IN_DischargeMode ((uint8_T)2U)
|
||||
#define control_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
|
||||
#define control_IN_TCMode ((uint8_T)4U)
|
||||
#define control_IN_balance ((uint8_T)1U)
|
||||
#define control_IN_charge ((uint8_T)2U)
|
||||
#define control_IN_deinit ((uint8_T)3U)
|
||||
#define control_IN_discharge ((uint8_T)4U)
|
||||
#define control_IN_init ((uint8_T)5U)
|
||||
#define control_IN_setting ((uint8_T)5U)
|
||||
#define control_IN_stop ((uint8_T)6U)
|
||||
#define control_IN_storage ((uint8_T)6U)
|
||||
#define control_IN_waitBuckVol ((uint8_T)7U)
|
||||
#define control_IN_waitBuckup ((uint8_T)8U)
|
||||
#define control_IN_waitPwrVol ((uint8_T)9U)
|
||||
|
||||
/* Named constants for Chart: '<S2>/Chart' */
|
||||
#define control_IN_run ((uint8_T)1U)
|
||||
#define control_IN_stop_l ((uint8_T)2U)
|
||||
|
||||
/* Block signals (default storage) */
|
||||
B_control_T control_B;
|
||||
|
||||
/* Block states (default storage) */
|
||||
DW_control_T control_DW;
|
||||
|
||||
/* External inputs (root inport signals with default storage) */
|
||||
ExtU_control_T control_U;
|
||||
|
||||
/* External outputs (root outports fed by signals with default storage) */
|
||||
ExtY_control_T control_Y;
|
||||
|
||||
/* Real-time model */
|
||||
static RT_MODEL_control_T control_M_;
|
||||
RT_MODEL_control_T *const control_M = &control_M_;
|
||||
|
||||
/* Forward declaration for local functions */
|
||||
static real_T control_check_vol(real_T flag, real_T x);
|
||||
static void control_charge(void);
|
||||
void mul_wide_s32(int32_T in0, int32_T in1, uint32_T *ptrOutBitsHi, uint32_T
|
||||
*ptrOutBitsLo)
|
||||
{
|
||||
uint32_T absIn0;
|
||||
uint32_T absIn1;
|
||||
uint32_T in0Hi;
|
||||
uint32_T in0Lo;
|
||||
uint32_T in1Hi;
|
||||
uint32_T productHiLo;
|
||||
uint32_T productLoHi;
|
||||
absIn0 = in0 < 0 ? ~(uint32_T)in0 + 1U : (uint32_T)in0;
|
||||
absIn1 = in1 < 0 ? ~(uint32_T)in1 + 1U : (uint32_T)in1;
|
||||
in0Hi = absIn0 >> 16U;
|
||||
in0Lo = absIn0 & 65535U;
|
||||
in1Hi = absIn1 >> 16U;
|
||||
absIn0 = absIn1 & 65535U;
|
||||
productHiLo = in0Hi * absIn0;
|
||||
productLoHi = in0Lo * in1Hi;
|
||||
absIn0 *= in0Lo;
|
||||
absIn1 = 0U;
|
||||
in0Lo = (productLoHi << /*MW:OvBitwiseOk*/ 16U) + /*MW:OvCarryOk*/ absIn0;
|
||||
if (in0Lo < absIn0) {
|
||||
absIn1 = 1U;
|
||||
}
|
||||
|
||||
absIn0 = in0Lo;
|
||||
in0Lo += /*MW:OvCarryOk*/ productHiLo << /*MW:OvBitwiseOk*/ 16U;
|
||||
if (in0Lo < absIn0) {
|
||||
absIn1++;
|
||||
}
|
||||
|
||||
absIn0 = (((productLoHi >> 16U) + (productHiLo >> 16U)) + in0Hi * in1Hi) +
|
||||
absIn1;
|
||||
if ((in0 != 0) && ((in1 != 0) && ((in0 > 0) != (in1 > 0)))) {
|
||||
absIn0 = ~absIn0;
|
||||
in0Lo = ~in0Lo;
|
||||
in0Lo++;
|
||||
if (in0Lo == 0U) {
|
||||
absIn0++;
|
||||
}
|
||||
}
|
||||
|
||||
*ptrOutBitsHi = absIn0;
|
||||
*ptrOutBitsLo = in0Lo;
|
||||
}
|
||||
|
||||
int32_T mul_s32_sat(int32_T a, int32_T b)
|
||||
{
|
||||
int32_T result;
|
||||
uint32_T u32_chi;
|
||||
uint32_T u32_clo;
|
||||
mul_wide_s32(a, b, &u32_chi, &u32_clo);
|
||||
if (((int32_T)u32_chi > 0) || ((u32_chi == 0U) && (u32_clo >= 2147483648U))) {
|
||||
result = MAX_int32_T;
|
||||
} else if (((int32_T)u32_chi < -1) || (((int32_T)u32_chi == -1) && (u32_clo <
|
||||
2147483648U))) {
|
||||
result = MIN_int32_T;
|
||||
} else {
|
||||
result = (int32_T)u32_clo;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Function for Chart: '<Root>/state' */
|
||||
static real_T control_check_vol(real_T flag, real_T x)
|
||||
{
|
||||
real_T y;
|
||||
uint32_T bat_count;
|
||||
bat_count = 0U;
|
||||
y = 0.0;
|
||||
|
||||
/* Inport generated from: '<Root>/bat_num' incorporates:
|
||||
* Inport generated from: '<Root>/In Bus Element6'
|
||||
*/
|
||||
while ((real_T)bat_count <= control_U.bat_num) {
|
||||
bat_count++;
|
||||
if (flag > 0.0) {
|
||||
/* Inport generated from: '<Root>/In Bus Element6' */
|
||||
if (control_U.sens_bat_sv[(int32_T)bat_count - 1] > x) {
|
||||
y++;
|
||||
}
|
||||
} else if (flag < 0.0) {
|
||||
/* Inport generated from: '<Root>/In Bus Element6' */
|
||||
if (control_U.sens_bat_sv[(int32_T)bat_count - 1] < x) {
|
||||
y++;
|
||||
}
|
||||
} else if (fabs(control_U.sens_bat_sv[(int32_T)bat_count - 1] - x) < 0.01) {
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of Inport generated from: '<Root>/bat_num' */
|
||||
return y;
|
||||
}
|
||||
|
||||
real_T rt_roundd_snf(real_T u)
|
||||
{
|
||||
real_T y;
|
||||
if (fabs(u) < 4.503599627370496E+15) {
|
||||
if (u >= 0.5) {
|
||||
y = floor(u + 0.5);
|
||||
} else if (u > -0.5) {
|
||||
y = u * 0.0;
|
||||
} else {
|
||||
y = ceil(u - 0.5);
|
||||
}
|
||||
} else {
|
||||
y = u;
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/* Function for Chart: '<Root>/state' */
|
||||
static void control_charge(void)
|
||||
{
|
||||
real_T tmp;
|
||||
boolean_T guard1;
|
||||
boolean_T guard2;
|
||||
|
||||
/* Inport generated from: '<Root>/mode' incorporates:
|
||||
* Inport generated from: '<Root>/run_state'
|
||||
*/
|
||||
if (control_U.mode == (uint32_T)Init) {
|
||||
control_DW.is_charge = control_IN_NO_ACTIVE_CHILD;
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_c3_control = control_IN_deinit;
|
||||
} else {
|
||||
guard1 = false;
|
||||
guard2 = false;
|
||||
switch (control_DW.is_charge) {
|
||||
case control_IN_BalanceMode:
|
||||
if ((control_U.run_state == Stop) || (control_check_vol(0.0, 4.2) != 0.0) ||
|
||||
(control_DW.temporalCounter_i1 >= 2160000U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_CCMode:
|
||||
if ((control_check_vol(1.0, 4.2) != 0.0) && (control_DW.temporalCounter_i1
|
||||
>= 400U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_CVMode;
|
||||
} else if ((control_U.run_state == Stop) || (control_DW.temporalCounter_i1
|
||||
>= 2160000U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_CVMode:
|
||||
/* Inport generated from: '<Root>/In Bus Element4' incorporates:
|
||||
* Inport generated from: '<Root>/bat_capacity'
|
||||
* Inport generated from: '<Root>/run_state'
|
||||
*/
|
||||
if ((control_U.sens_bat_current < control_U.bat_capacity * 0.05F) ||
|
||||
(control_DW.temporalCounter_i1 >= 2160000U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_BalanceMode;
|
||||
} else if (control_U.run_state == Stop) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
|
||||
/* End of Inport generated from: '<Root>/In Bus Element4' */
|
||||
break;
|
||||
|
||||
case control_IN_TCMode:
|
||||
control_B.cmd_buck_out_relay = 1.0;
|
||||
if (control_DW.temporalCounter_i1 >= 2160000U) {
|
||||
guard1 = true;
|
||||
} else if ((control_check_vol(-1.0, 3.0) != 0.0) &&
|
||||
(control_DW.temporalCounter_i1 >= 200U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_CCMode;
|
||||
} else if (control_U.run_state == Stop) {
|
||||
guard1 = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_setting:
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
if (control_U.run_state == Start) {
|
||||
if (control_U.bat_type == LiHv) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
tmp = rt_roundd_snf((real_T)control_U.bat_num * 4.2);
|
||||
if (tmp < 2.147483648E+9) {
|
||||
if (tmp >= -2.147483648E+9) {
|
||||
control_B.cmd_all_voltage = (real32_T)tmp;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
}
|
||||
} else {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == LiPo) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
tmp = rt_roundd_snf((real_T)control_U.bat_num * 4.26);
|
||||
if (tmp < 2.147483648E+9) {
|
||||
if (tmp >= -2.147483648E+9) {
|
||||
control_B.cmd_all_voltage = (real32_T)tmp;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
}
|
||||
} else {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == Lilon) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
tmp = rt_roundd_snf((real_T)control_U.bat_num * 4.2);
|
||||
if (tmp < 2.147483648E+9) {
|
||||
if (tmp >= -2.147483648E+9) {
|
||||
control_B.cmd_all_voltage = (real32_T)tmp;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
}
|
||||
} else {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == LiFe) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
tmp = rt_roundd_snf((real_T)control_U.bat_num * 4.2);
|
||||
if (tmp < 2.147483648E+9) {
|
||||
if (tmp >= -2.147483648E+9) {
|
||||
control_B.cmd_all_voltage = (real32_T)tmp;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
}
|
||||
} else {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == LiXX) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
tmp = rt_roundd_snf((real_T)control_U.bat_num * 4.2);
|
||||
if (tmp < 2.147483648E+9) {
|
||||
if (tmp >= -2.147483648E+9) {
|
||||
control_B.cmd_all_voltage = (real32_T)tmp;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
}
|
||||
} else {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == NiZn) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
control_B.cmd_all_voltage = (real32_T)mul_s32_sat(control_U.bat_num, 3);
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == NiCd) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
if (control_U.bat_num > 1073741823) {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
} else if (control_U.bat_num <= -1073741824) {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = (real32_T)(control_U.bat_num << 1);
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == NiMH) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
control_B.cmd_all_voltage = (real32_T)mul_s32_sat(control_U.bat_num, 3);
|
||||
guard2 = true;
|
||||
} else if (control_U.bat_type == Pb) {
|
||||
/* Inport generated from: '<Root>/bat_num' */
|
||||
if (control_U.bat_num > 1073741823) {
|
||||
control_B.cmd_all_voltage = 2.14748365E+9F;
|
||||
} else if (control_U.bat_num <= -1073741824) {
|
||||
control_B.cmd_all_voltage = -2.14748365E+9F;
|
||||
} else {
|
||||
control_B.cmd_all_voltage = (real32_T)(control_U.bat_num << 1);
|
||||
}
|
||||
|
||||
guard2 = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_stop:
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
if (control_DW.temporalCounter_i1 >= 200U) {
|
||||
control_DW.is_charge = control_IN_setting;
|
||||
control_B.cmd_all_voltage = 0.0F;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_waitBuckVol:
|
||||
control_B.cmd_buck_in_relay = 1.0;
|
||||
|
||||
/* Inport generated from: '<Root>/In Bus Element2' incorporates:
|
||||
* Inport generated from: '<Root>/run_state'
|
||||
*/
|
||||
if ((control_U.sens_buck_in_voltage >= control_B.cmd_all_voltage) &&
|
||||
(control_DW.temporalCounter_i1 >= 200U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_waitBuckup;
|
||||
control_B.cmd_pwm_en = 1.0;
|
||||
} else if (control_U.run_state == Stop) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
|
||||
/* End of Inport generated from: '<Root>/In Bus Element2' */
|
||||
break;
|
||||
|
||||
case control_IN_waitBuckup:
|
||||
control_B.cmd_pwm_en = 1.0;
|
||||
|
||||
/* Inport generated from: '<Root>/In Bus Element3' incorporates:
|
||||
* Inport generated from: '<Root>/run_state'
|
||||
* Inport generated from: '<Root>/In Bus Element1'
|
||||
*/
|
||||
if ((control_U.sens_buck_out_voltage >= control_U.sens_bat_voltage) &&
|
||||
(control_DW.temporalCounter_i1 >= 200U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_TCMode;
|
||||
control_B.cmd_buck_out_relay = 1.0;
|
||||
} else if (control_U.run_state == Stop) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
|
||||
/* End of Inport generated from: '<Root>/In Bus Element3' */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* case IN_waitPwrVol: */
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
|
||||
/* Inport generated from: '<Root>/In Bus Element' incorporates:
|
||||
* Inport generated from: '<Root>/run_state'
|
||||
*/
|
||||
if ((control_U.sens_pwr_voltage >= control_B.cmd_all_voltage) &&
|
||||
(control_DW.temporalCounter_i1 >= 200U)) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_waitBuckVol;
|
||||
control_B.cmd_buck_in_relay = 1.0;
|
||||
} else if (control_U.run_state == Stop) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
}
|
||||
|
||||
/* End of Inport generated from: '<Root>/In Bus Element' */
|
||||
break;
|
||||
}
|
||||
|
||||
if (guard2) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_waitPwrVol;
|
||||
}
|
||||
|
||||
if (guard1) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_charge = control_IN_stop;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of Inport generated from: '<Root>/mode' */
|
||||
}
|
||||
|
||||
/* Model step function */
|
||||
void control_step(void)
|
||||
{
|
||||
real_T rtb_Switch;
|
||||
int32_T rtb_pwm;
|
||||
|
||||
/* Chart: '<Root>/state' incorporates:
|
||||
* Inport generated from: '<Root>/mode'
|
||||
*/
|
||||
if (control_DW.temporalCounter_i1 < MAX_uint32_T) {
|
||||
control_DW.temporalCounter_i1++;
|
||||
}
|
||||
|
||||
if (control_DW.is_active_c3_control == 0U) {
|
||||
control_DW.is_active_c3_control = 1U;
|
||||
control_DW.is_c3_control = control_IN_init;
|
||||
control_B.cmd_all_voltage = 0.0F;
|
||||
control_B.cmd_temp = 20.0;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
} else {
|
||||
switch (control_DW.is_c3_control) {
|
||||
case control_IN_balance:
|
||||
if (control_U.mode == (uint32_T)Init) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_c3_control = control_IN_deinit;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_charge:
|
||||
control_charge();
|
||||
break;
|
||||
|
||||
case control_IN_deinit:
|
||||
if (control_DW.temporalCounter_i1 >= 200U) {
|
||||
control_DW.is_c3_control = control_IN_init;
|
||||
control_B.cmd_all_voltage = 0.0F;
|
||||
control_B.cmd_temp = 20.0;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_discharge:
|
||||
if (control_U.mode == (uint32_T)Init) {
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_c3_control = control_IN_deinit;
|
||||
}
|
||||
break;
|
||||
|
||||
case control_IN_init:
|
||||
control_B.cmd_temp = 20.0;
|
||||
control_B.cmd_buck_in_relay = 0.0;
|
||||
control_B.cmd_buck_out_relay = 0.0;
|
||||
control_B.cmd_pwm_en = 0.0;
|
||||
if (control_U.mode == (uint32_T)Discharge) {
|
||||
control_DW.is_c3_control = control_IN_discharge;
|
||||
} else if (control_U.mode == (uint32_T)Storage) {
|
||||
control_DW.is_c3_control = control_IN_storage;
|
||||
control_DW.is_storage = control_IN_DischargeMode;
|
||||
} else if (control_U.mode == (uint32_T)Charge) {
|
||||
control_DW.is_c3_control = control_IN_charge;
|
||||
control_DW.is_charge = control_IN_setting;
|
||||
control_B.cmd_all_voltage = 0.0F;
|
||||
} else if (control_U.mode == (uint32_T)Balance) {
|
||||
control_DW.is_c3_control = control_IN_balance;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* case IN_storage: */
|
||||
if (control_U.mode == (uint32_T)Init) {
|
||||
control_DW.is_storage = control_IN_NO_ACTIVE_CHILD;
|
||||
control_DW.temporalCounter_i1 = 0U;
|
||||
control_DW.is_c3_control = control_IN_deinit;
|
||||
} else {
|
||||
switch (control_DW.is_storage) {
|
||||
case control_IN_BalanceMode:
|
||||
break;
|
||||
|
||||
default:
|
||||
/* case IN_DischargeMode: */
|
||||
control_DW.is_storage = control_IN_BalanceMode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of Chart: '<Root>/state' */
|
||||
|
||||
/* Switch: '<S3>/Switch' incorporates:
|
||||
* Constant: '<S3>/Constant1'
|
||||
* Inport generated from: '<Root>/In Bus Element3'
|
||||
* Sum: '<S3>/Sum4'
|
||||
*/
|
||||
if (control_B.cmd_pwm_en > control_P.Switch_Threshold) {
|
||||
rtb_Switch = control_B.cmd_all_voltage - control_U.sens_buck_out_voltage;
|
||||
} else {
|
||||
rtb_Switch = control_P.Constant1_Value;
|
||||
}
|
||||
|
||||
/* End of Switch: '<S3>/Switch' */
|
||||
|
||||
/* Gain: '<S3>/I' incorporates:
|
||||
* Delay: '<S3>/Delay'
|
||||
* Sum: '<S3>/Sum5'
|
||||
*/
|
||||
control_DW.Delay_DSTATE = (rtb_Switch + control_DW.Delay_DSTATE) *
|
||||
control_P.I_Gain;
|
||||
|
||||
/* Saturate: '<S3>/Saturation1' */
|
||||
if (control_DW.Delay_DSTATE > control_P.Saturation1_UpperSat) {
|
||||
/* Gain: '<S3>/I' */
|
||||
control_DW.Delay_DSTATE = control_P.Saturation1_UpperSat;
|
||||
} else if (control_DW.Delay_DSTATE < control_P.Saturation1_LowerSat) {
|
||||
/* Gain: '<S3>/I' */
|
||||
control_DW.Delay_DSTATE = control_P.Saturation1_LowerSat;
|
||||
}
|
||||
|
||||
/* End of Saturate: '<S3>/Saturation1' */
|
||||
|
||||
/* Switch: '<S3>/Switch1' incorporates:
|
||||
* Constant: '<S3>/Constant2'
|
||||
*/
|
||||
if (control_B.cmd_pwm_en > control_P.Switch1_Threshold) {
|
||||
/* Sum: '<S3>/Sum6' incorporates:
|
||||
* Delay: '<S3>/Delay'
|
||||
* Gain: '<S3>/P'
|
||||
*/
|
||||
rtb_Switch = control_P.P_Gain * rtb_Switch + control_DW.Delay_DSTATE;
|
||||
|
||||
/* Saturate: '<S3>/Saturation' */
|
||||
if (rtb_Switch > control_P.Saturation_UpperSat) {
|
||||
rtb_Switch = control_P.Saturation_UpperSat;
|
||||
} else if (rtb_Switch < control_P.Saturation_LowerSat) {
|
||||
rtb_Switch = control_P.Saturation_LowerSat;
|
||||
}
|
||||
|
||||
/* End of Saturate: '<S3>/Saturation' */
|
||||
} else {
|
||||
rtb_Switch = control_P.Constant2_Value;
|
||||
}
|
||||
|
||||
/* End of Switch: '<S3>/Switch1' */
|
||||
|
||||
/* DataTypeConversion: '<Root>/Data Type Conversion' */
|
||||
rtb_Switch = floor(rtb_Switch);
|
||||
if (rtIsNaN(rtb_Switch) || rtIsInf(rtb_Switch)) {
|
||||
rtb_Switch = 0.0;
|
||||
} else {
|
||||
rtb_Switch = fmod(rtb_Switch, 65536.0);
|
||||
}
|
||||
|
||||
control_Y.out.power = (uint16_T)(rtb_Switch < 0.0 ? (int32_T)(uint16_T)
|
||||
-(int16_T)(uint16_T)-rtb_Switch : (int32_T)(uint16_T)rtb_Switch);
|
||||
|
||||
/* End of DataTypeConversion: '<Root>/Data Type Conversion' */
|
||||
|
||||
/* Chart: '<S2>/Chart' incorporates:
|
||||
* Inport generated from: '<Root>/In Bus Element5'
|
||||
*/
|
||||
if (control_DW.temporalCounter_i1_c < 1023U) {
|
||||
control_DW.temporalCounter_i1_c++;
|
||||
}
|
||||
|
||||
if (control_DW.is_active_c1_control == 0U) {
|
||||
control_DW.is_active_c1_control = 1U;
|
||||
control_DW.temporalCounter_i1_c = 0U;
|
||||
control_DW.is_c1_control = control_IN_stop_l;
|
||||
rtb_pwm = 0;
|
||||
} else if (control_DW.is_c1_control == control_IN_run) {
|
||||
if ((control_B.cmd_temp - control_U.sens_temperature >= 0.0) &&
|
||||
(control_DW.temporalCounter_i1_c >= 1000U)) {
|
||||
control_DW.temporalCounter_i1_c = 0U;
|
||||
control_DW.is_c1_control = control_IN_stop_l;
|
||||
rtb_pwm = 0;
|
||||
} else {
|
||||
rtb_pwm = 1;
|
||||
}
|
||||
|
||||
/* case IN_stop: */
|
||||
} else if ((control_B.cmd_temp - control_U.sens_temperature < 0.0) &&
|
||||
(control_DW.temporalCounter_i1_c >= 1000U)) {
|
||||
control_DW.temporalCounter_i1_c = 0U;
|
||||
control_DW.is_c1_control = control_IN_run;
|
||||
rtb_pwm = 1;
|
||||
} else {
|
||||
rtb_pwm = 0;
|
||||
}
|
||||
|
||||
/* End of Chart: '<S2>/Chart' */
|
||||
|
||||
/* DataTypeConversion: '<Root>/Data Type Conversion1' */
|
||||
control_Y.out.fan = (uint16_T)rtb_pwm;
|
||||
|
||||
/* DataTypeConversion: '<Root>/Data Type Conversion2' */
|
||||
rtb_Switch = floor(control_B.cmd_buck_in_relay);
|
||||
if (rtIsNaN(rtb_Switch) || rtIsInf(rtb_Switch)) {
|
||||
rtb_Switch = 0.0;
|
||||
} else {
|
||||
rtb_Switch = fmod(rtb_Switch, 65536.0);
|
||||
}
|
||||
|
||||
control_Y.out.relay_in = (uint16_T)(rtb_Switch < 0.0 ? (int32_T)(uint16_T)
|
||||
-(int16_T)(uint16_T)-rtb_Switch : (int32_T)(uint16_T)rtb_Switch);
|
||||
|
||||
/* End of DataTypeConversion: '<Root>/Data Type Conversion2' */
|
||||
|
||||
/* DataTypeConversion: '<Root>/Data Type Conversion3' */
|
||||
rtb_Switch = floor(control_B.cmd_buck_out_relay);
|
||||
if (rtIsNaN(rtb_Switch) || rtIsInf(rtb_Switch)) {
|
||||
rtb_Switch = 0.0;
|
||||
} else {
|
||||
rtb_Switch = fmod(rtb_Switch, 65536.0);
|
||||
}
|
||||
|
||||
control_Y.out.relay_out = (uint16_T)(rtb_Switch < 0.0 ? (int32_T)(uint16_T)
|
||||
-(int16_T)(uint16_T)-rtb_Switch : (int32_T)(uint16_T)rtb_Switch);
|
||||
|
||||
/* End of DataTypeConversion: '<Root>/Data Type Conversion3' */
|
||||
}
|
||||
|
||||
/* Model initialize function */
|
||||
void control_initialize(void)
|
||||
{
|
||||
/* Registration code */
|
||||
|
||||
/* Initialize DataMapInfo substructure containing ModelMap for C API */
|
||||
control_InitializeDataMapInfo();
|
||||
|
||||
/* InitializeConditions for Gain: '<S3>/I' incorporates:
|
||||
* Delay: '<S3>/Delay'
|
||||
*/
|
||||
control_DW.Delay_DSTATE = control_P.Delay_InitialCondition;
|
||||
}
|
||||
|
||||
/* Model terminate function */
|
||||
void control_terminate(void)
|
||||
{
|
||||
/* (no terminate code required) */
|
||||
}
|
||||
|
||||
/*
|
||||
* File trailer for generated code.
|
||||
*
|
||||
* [EOF]
|
||||
*/
|
||||
Reference in New Issue
Block a user