Merge pull request #37 from Dev-KATECH/Workspace

시뮬링크 속도제어로직 파일 삽입
This commit is contained in:
S2-CHICKEN 2024-09-26 10:06:15 +09:00 committed by GitHub
commit 617f56895a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 871 additions and 1 deletions

View File

@ -120,6 +120,7 @@
"./src/MCU/Motor_logic.o"
"./src/MCU/NO_MCU_SIG.o"
"./src/MCU/SPEED.o"
"./src/Motor_Dymics_Logic/wheelSpd2.o"
"./src/Operation_Mode_Layer/Operation_Mode.o"
"./src/RWA/Angle_RateLimit.o"
"./src/RWA/Angle_Speed.o"

View File

@ -85,7 +85,7 @@ c:/nxp/s32ds.3.4/s32ds/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/bin/../lib/gcc/ar
c:/nxp/s32ds.3.4/s32ds/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/bin/../lib/gcc/arm-none-eabi/9.2.0/thumb/v7e-m/nofp\libgcc.a(_arm_muldivdf3.o)
./src/board.o (__aeabi_ddiv)
c:/nxp/s32ds.3.4/s32ds/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/bin/../lib/gcc/arm-none-eabi/9.2.0/thumb/v7e-m/nofp\libgcc.a(_arm_cmpdf2.o)
C:/NXP/S32DS.3.4/S32DS/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/arm-none-eabi/newlib/lib/thumb/v7e-m/nofp\libc_nano.a(lib_a-nano-vfprintf_float.o) (__aeabi_dcmpeq)
./src/Motor_Dymics_Logic/wheelSpd2.o (__aeabi_dcmpeq)
c:/nxp/s32ds.3.4/s32ds/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/bin/../lib/gcc/arm-none-eabi/9.2.0/thumb/v7e-m/nofp\libgcc.a(_arm_unorddf2.o)
C:/NXP/S32DS.3.4/S32DS/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/arm-none-eabi/newlib/lib/thumb/v7e-m/nofp\libc_nano.a(lib_a-nano-vfprintf_float.o) (__aeabi_dcmpun)
c:/nxp/s32ds.3.4/s32ds/build_tools/gcc_v9.2/gcc-9.2-arm32-eabi/bin/../lib/gcc/arm-none-eabi/9.2.0/thumb/v7e-m/nofp\libgcc.a(_arm_fixdfsi.o)
@ -8615,6 +8615,30 @@ Discarded input sections
.debug_macro 0x00000000 0xde ./src/MCU/SPEED.o
.debug_macro 0x00000000 0x4bf ./src/MCU/SPEED.o
.debug_macro 0x00000000 0x7a ./src/MCU/SPEED.o
.group 0x00000000 0xc ./src/Motor_Dymics_Logic/wheelSpd2.o
.group 0x00000000 0xc ./src/Motor_Dymics_Logic/wheelSpd2.o
.group 0x00000000 0xc ./src/Motor_Dymics_Logic/wheelSpd2.o
.group 0x00000000 0xc ./src/Motor_Dymics_Logic/wheelSpd2.o
.text 0x00000000 0xa10 ./src/Motor_Dymics_Logic/wheelSpd2.o
.data 0x00000000 0x0 ./src/Motor_Dymics_Logic/wheelSpd2.o
.bss 0x00000000 0x15c ./src/Motor_Dymics_Logic/wheelSpd2.o
.rodata 0x00000000 0x4 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_info 0x00000000 0x53c ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_abbrev 0x00000000 0x131 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_loc 0x00000000 0x5bf ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_aranges
0x00000000 0x20 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_macro 0x00000000 0x28 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_macro 0x00000000 0xaa8 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_macro 0x00000000 0x10 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_macro 0x00000000 0x5e ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_macro 0x00000000 0x10 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_line 0x00000000 0x5e5 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_str 0x00000000 0x373a ./src/Motor_Dymics_Logic/wheelSpd2.o
.comment 0x00000000 0x81 ./src/Motor_Dymics_Logic/wheelSpd2.o
.debug_frame 0x00000000 0x54 ./src/Motor_Dymics_Logic/wheelSpd2.o
.ARM.attributes
0x00000000 0x2e ./src/Motor_Dymics_Logic/wheelSpd2.o
.group 0x00000000 0xc ./src/Operation_Mode_Layer/Operation_Mode.o
.group 0x00000000 0xc ./src/Operation_Mode_Layer/Operation_Mode.o
.group 0x00000000 0xc ./src/Operation_Mode_Layer/Operation_Mode.o
@ -9789,6 +9813,7 @@ LOAD ./src/MCU/Low_SOC_mode.o
LOAD ./src/MCU/Motor_logic.o
LOAD ./src/MCU/NO_MCU_SIG.o
LOAD ./src/MCU/SPEED.o
LOAD ./src/Motor_Dymics_Logic/wheelSpd2.o
LOAD ./src/Operation_Mode_Layer/Operation_Mode.o
LOAD ./src/RWA/Angle_RateLimit.o
LOAD ./src/RWA/Angle_Speed.o

View File

@ -15,6 +15,7 @@ RM := rm -rf
-include src/VCU/subdir.mk
-include src/RWA/subdir.mk
-include src/Operation_Mode_Layer/subdir.mk
-include src/Motor_Dymics_Logic/subdir.mk
-include src/MCU/subdir.mk
-include src/IDB_RCU/subdir.mk
-include src/HAL/watchdog_hal/src/subdir.mk

View File

@ -33,6 +33,7 @@ src \
src/HAL/watchdog_hal/src \
src/IDB_RCU \
src/MCU \
src/Motor_Dymics_Logic \
src/Operation_Mode_Layer \
src/RWA \
src/VCU \

View File

@ -0,0 +1,99 @@
/*
* 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: rtwtypes.h
*
* Code generated for Simulink model 'wheelSpd2'.
*
* Model version : 1.9
* Simulink Coder version : 9.9 (R2023a) 19-Nov-2022
* C/C++ source code generated on : Wed Sep 25 21:14:33 2024
*/
#ifndef RTWTYPES_H
#define RTWTYPES_H
/* Logical type definitions */
#if (!defined(__cplusplus))
#ifndef false
#define false (0U)
#endif
#ifndef true
#define true (1U)
#endif
#endif
/*=======================================================================*
* Target hardware information
* Device type: NXP->Cortex-M4
* Number of bits: char: 8 short: 16 int: 32
* long: 32 long long: 64
* native word size: 32
* Byte ordering: LittleEndian
* Signed integer division rounds to: Zero
* Shift right on a signed integer as arithmetic shift: on
*=======================================================================*/
/*=======================================================================*
* Fixed width word size data types: *
* int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
* uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
* real32_T, real64_T - 32 and 64 bit floating point numbers *
*=======================================================================*/
typedef signed char int8_T;
typedef unsigned char uint8_T;
typedef short int16_T;
typedef unsigned short uint16_T;
typedef int int32_T;
typedef unsigned int uint32_T;
typedef long long int64_T;
typedef unsigned long long uint64_T;
typedef float real32_T;
typedef double real64_T;
/*===========================================================================*
* Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T, *
* real_T, time_T, ulong_T, ulonglong_T. *
*===========================================================================*/
typedef double real_T;
typedef double time_T;
typedef unsigned char boolean_T;
typedef int int_T;
typedef unsigned int uint_T;
typedef unsigned long ulong_T;
typedef unsigned long long ulonglong_T;
typedef char char_T;
typedef unsigned char uchar_T;
typedef char_T byte_T;
/*=======================================================================*
* Min and Max: *
* int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
* uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
*=======================================================================*/
#define MAX_int8_T ((int8_T)(127))
#define MIN_int8_T ((int8_T)(-128))
#define MAX_uint8_T ((uint8_T)(255U))
#define MAX_int16_T ((int16_T)(32767))
#define MIN_int16_T ((int16_T)(-32768))
#define MAX_uint16_T ((uint16_T)(65535U))
#define MAX_int32_T ((int32_T)(2147483647))
#define MIN_int32_T ((int32_T)(-2147483647-1))
#define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU))
#define MAX_int64_T ((int64_T)(9223372036854775807LL))
#define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL))
#define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL))
/* Block D-Work pointer type */
typedef void * pointer_T;
#endif /* RTWTYPES_H */
/*
* File trailer for generated code.
*
* [EOF]
*/

View File

@ -0,0 +1,558 @@
/*
* 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: wheelSpd2.c
*
* Code generated for Simulink model 'wheelSpd2'.
*
* Model version : 1.9
* Simulink Coder version : 9.9 (R2023a) 19-Nov-2022
* C/C++ source code generated on : Wed Sep 25 21:15:56 2024
*
* Target selection: ert.tlc
* Embedded hardware selection: NXP->Cortex-M4
* Code generation objectives:
* 1. Execution efficiency
* 2. Debugging
* Validation result: Not run
*/
#include "wheelSpd2.h"
#include "rtwtypes.h"
/* Block signals and states (default storage) */
Dynamics_DW Dynamics_rtDW;
/* External inputs (root inport signals with default storage) */
Dynamics_ExtU Dynamics_rtU;
/* External outputs (root outports fed by signals with default storage) */
Dynamics_ExtY Dynamics_rtY;
/* Real-time model */
static Dynamics_RT_MODEL Dynamics_rtM_;
Dynamics_RT_MODEL *const Dynamics_rtM = &Dynamics_rtM_;
/* Model step function */
void wheelSpd2_step(void)
{
real_T Dynamics_u0;
real_T rtb_Dynamics_Add3;
real_T rtb_Dynamics_Error;
real_T rtb_Dynamics_Gain;
real_T rtb_Dynamics_MultiportSwitch1;
real_T rtb_Dynamics_Product1;
real_T rtb_Dynamics_Product1_d;
real_T rtb_Dynamics_Product1_g;
real_T rtb_Dynamics_Product1_hh;
real_T rtb_Dynamics_Product4_d;
real_T rtb_Dynamics_Subtract2;
real_T rtb_Dynamics_Sum1_ap;
real_T rtb_Dynamics_Sum1_ig;
real_T rtb_Dynamics_Sum1_jm;
real_T rtb_Dynamics_Sum1_l;
real_T rtb_Dynamics_Sum1_n;
real_T rtb_Dynamics_Vx_Output;
int32_T Dynamics_tmp;
/* MATLAB Function: '<S9>/Vx_OutPut_Function' incorporates:
* Inport: '<Root>/<Vx_Cmd>'
* Inport: '<Root>/<Vx_Limit>'
*/
if (Dynamics_rtU.Dynamics_Vx_Limit <= Dynamics_rtU.Dynamics_Vx_Cmd) {
rtb_Dynamics_Vx_Output = Dynamics_rtU.Dynamics_Vx_Limit;
} else {
rtb_Dynamics_Vx_Output = Dynamics_rtU.Dynamics_Vx_Cmd;
}
/* End of MATLAB Function: '<S9>/Vx_OutPut_Function' */
/* RateLimiter: '<Root>/Input_Vx_RateLimiter' */
rtb_Dynamics_Sum1_jm = rtb_Dynamics_Vx_Output - Dynamics_rtDW.Dynamics_PrevY;
if (rtb_Dynamics_Sum1_jm > 0.004) {
rtb_Dynamics_Vx_Output = Dynamics_rtDW.Dynamics_PrevY + 0.004;
} else if (rtb_Dynamics_Sum1_jm < -0.004) {
rtb_Dynamics_Vx_Output = Dynamics_rtDW.Dynamics_PrevY - 0.004;
} else {
/* no actions */
}
Dynamics_rtDW.Dynamics_PrevY = rtb_Dynamics_Vx_Output;
/* End of RateLimiter: '<Root>/Input_Vx_RateLimiter' */
/* MATLAB Function: '<Root>/Target_RPM' incorporates:
* Inport: '<Root>/<RC_GearPosition>'
*/
if (Dynamics_rtU.Dynamics_RC_GearPosition == 0.0) {
Dynamics_tmp = 0;
} else if (Dynamics_rtU.Dynamics_RC_GearPosition == 2.0) {
Dynamics_tmp = 0;
} else if (Dynamics_rtU.Dynamics_RC_GearPosition == 1.0) {
Dynamics_tmp = -1;
} else {
Dynamics_tmp = (Dynamics_rtU.Dynamics_RC_GearPosition == 3.0) ? ((int32_T)1)
: ((int32_T)0);
}
rtb_Dynamics_Vx_Output = (((((rtb_Dynamics_Vx_Output * 1000.0) / 3600.0) *
11.93) * 60.0) / 1.7013672006633955) * ((real_T)Dynamics_tmp);
/* End of MATLAB Function: '<Root>/Target_RPM' */
/* RateLimiter: '<Root>/TargetSpd_RateLimiter' */
rtb_Dynamics_Sum1_jm = rtb_Dynamics_Vx_Output - Dynamics_rtDW.Dynamics_PrevY_e;
if (rtb_Dynamics_Sum1_jm > 0.4) {
rtb_Dynamics_Vx_Output = Dynamics_rtDW.Dynamics_PrevY_e + 0.4;
} else if (rtb_Dynamics_Sum1_jm < -0.4) {
rtb_Dynamics_Vx_Output = Dynamics_rtDW.Dynamics_PrevY_e - 0.4;
} else {
/* no actions */
}
Dynamics_rtDW.Dynamics_PrevY_e = rtb_Dynamics_Vx_Output;
/* End of RateLimiter: '<Root>/TargetSpd_RateLimiter' */
/* Product: '<S7>/Product1' incorporates:
* Constant: '<S7>/Constant'
* Gain: '<S7>/gain'
* Product: '<S7>/Product11'
* Sum: '<S7>/Sum1'
* Sum: '<S7>/Sum2'
* Sum: '<S7>/Sum3'
* Sum: '<S7>/Sum4'
* UnitDelay: '<S7>/d'
* UnitDelay: '<S7>/d1'
*/
rtb_Dynamics_Product1 = (((rtb_Dynamics_Vx_Output +
Dynamics_rtDW.Dynamics_d1_DSTATE) * 0.002) + (0.1041032953945969 *
Dynamics_rtDW.Dynamics_d_DSTATE)) / 0.1081032953945969;
/* Sum: '<Root>/Subtract' incorporates:
* Inport: '<Root>/<RPM>'
*/
rtb_Dynamics_Error = rtb_Dynamics_Product1 - Dynamics_rtU.Dynamics_RPM;
/* Saturate: '<Root>/Error_Saturation' */
if (rtb_Dynamics_Error > 2000.0) {
rtb_Dynamics_Error = 2000.0;
} else if (rtb_Dynamics_Error < -2000.0) {
rtb_Dynamics_Error = -2000.0;
} else {
/* no actions */
}
/* End of Saturate: '<Root>/Error_Saturation' */
/* MATLAB Function: '<Root>/GearCondition_Brake' incorporates:
* Inport: '<Root>/<RC_GearPosition>'
*/
if (Dynamics_rtU.Dynamics_RC_GearPosition == 1.0) {
Dynamics_tmp = -1;
} else {
Dynamics_tmp = (Dynamics_rtU.Dynamics_RC_GearPosition == 3.0) ? ((int32_T)1)
: ((int32_T)0);
}
/* Switch: '<Root>/Switch1' incorporates:
* Constant: '<Root>/Constant4'
*/
if (rtb_Dynamics_Error > 0.0) {
rtb_Dynamics_MultiportSwitch1 = 0.0;
} else {
rtb_Dynamics_MultiportSwitch1 = rtb_Dynamics_Error;
}
/* Product: '<Root>/Multiply2' incorporates:
* Gain: '<Root>/Brake_GAIN'
* MATLAB Function: '<Root>/GearCondition_Brake'
* Switch: '<Root>/Switch1'
*/
rtb_Dynamics_MultiportSwitch1 = (-0.8 * rtb_Dynamics_MultiportSwitch1) *
((real_T)Dynamics_tmp);
/* RateLimiter: '<Root>/Brake_Out_RateLimiter' */
rtb_Dynamics_Sum1_jm = rtb_Dynamics_MultiportSwitch1 -
Dynamics_rtDW.Dynamics_PrevY_f;
if (rtb_Dynamics_Sum1_jm > 3.0) {
rtb_Dynamics_MultiportSwitch1 = Dynamics_rtDW.Dynamics_PrevY_f + 3.0;
} else if (rtb_Dynamics_Sum1_jm < -3.0) {
rtb_Dynamics_MultiportSwitch1 = Dynamics_rtDW.Dynamics_PrevY_f - 3.0;
} else {
/* no actions */
}
Dynamics_rtDW.Dynamics_PrevY_f = rtb_Dynamics_MultiportSwitch1;
/* End of RateLimiter: '<Root>/Brake_Out_RateLimiter' */
/* Saturate: '<Root>/Brake_Saturation' */
if (rtb_Dynamics_MultiportSwitch1 > 1000.0) {
/* Outport: '<Root>/Brake_cmd_out' */
Dynamics_rtY.Dynamics_Brake_cmd_out = 1000.0;
} else if (rtb_Dynamics_MultiportSwitch1 < 0.0) {
/* Outport: '<Root>/Brake_cmd_out' */
Dynamics_rtY.Dynamics_Brake_cmd_out = 0.0;
} else {
/* Outport: '<Root>/Brake_cmd_out' */
Dynamics_rtY.Dynamics_Brake_cmd_out = rtb_Dynamics_MultiportSwitch1;
}
/* End of Saturate: '<Root>/Brake_Saturation' */
/* DeadZone: '<S4>/Dead Zone' incorporates:
* MultiPortSwitch: '<S15>/Multiport Switch1'
*/
if (rtb_Dynamics_Error > 50.0) {
rtb_Dynamics_MultiportSwitch1 = rtb_Dynamics_Error - 50.0;
} else if (rtb_Dynamics_Error >= -50.0) {
rtb_Dynamics_MultiportSwitch1 = 0.0;
} else {
rtb_Dynamics_MultiportSwitch1 = rtb_Dynamics_Error - -50.0;
}
/* Sum: '<S18>/Sum1' incorporates:
* Gain: '<S18>/gain'
* Sum: '<S18>/Sum2'
* UnitDelay: '<S18>/d'
* UnitDelay: '<S18>/d1'
*/
rtb_Dynamics_Sum1_jm = ((rtb_Dynamics_Product1 -
Dynamics_rtDW.Dynamics_d_DSTATE_c) * 1000.0) -
Dynamics_rtDW.Dynamics_d1_DSTATE_e;
/* Sum: '<S19>/Sum1' incorporates:
* Gain: '<S19>/gain'
* Sum: '<S19>/Sum2'
* UnitDelay: '<S19>/d'
* UnitDelay: '<S19>/d1'
*/
rtb_Dynamics_Error = ((rtb_Dynamics_Sum1_jm -
Dynamics_rtDW.Dynamics_d_DSTATE_h) * 1000.0) -
Dynamics_rtDW.Dynamics_d1_DSTATE_p;
/* Sum: '<S20>/Sum1' incorporates:
* Gain: '<S20>/gain'
* Sum: '<S20>/Sum2'
* UnitDelay: '<S20>/d'
* UnitDelay: '<S20>/d1'
*/
rtb_Dynamics_Sum1_n = ((rtb_Dynamics_Error - Dynamics_rtDW.Dynamics_d_DSTATE_g)
* 1000.0) - Dynamics_rtDW.Dynamics_d1_DSTATE_a;
/* Gain: '<S16>/Gain' incorporates:
* Constant: '<S16>/Constant3'
* Constant: '<S16>/Constant4'
* Constant: '<S16>/Constant5'
* Product: '<S16>/Product'
* Product: '<S16>/Product1'
* Product: '<S16>/Product2'
* Sum: '<S16>/Add5'
*/
rtb_Dynamics_Gain = ((((156.8 * rtb_Dynamics_Product1) + (212.8 *
rtb_Dynamics_Sum1_jm)) + (21.8 * rtb_Dynamics_Error)) + rtb_Dynamics_Sum1_n)
* 9.44822373393802E-6;
/* Product: '<S22>/Product1' incorporates:
* Constant: '<S22>/Constant1'
* Constant: '<S22>/Constant2'
* Delay: '<S22>/Delay'
* Delay: '<S22>/Delay1'
* Delay: '<S22>/Delay2'
* Delay: '<S22>/Delay3'
* Gain: '<S22>/gain1'
* Gain: '<S22>/gain3'
* Product: '<S22>/x(n), x(n-1), x(n-2)'
* Product: '<S22>/y(n-1)'
* Product: '<S22>/y(n-2)'
* Sum: '<S22>/Sum1'
* Sum: '<S22>/Sum2'
* Sum: '<S22>/Sum3'
* Sum: '<S22>/Sum4'
* Sum: '<S22>/Sum5'
* Sum: '<S22>/Sum6'
*/
rtb_Dynamics_Product1_g = ((((((2.0 * Dynamics_rtDW.Dynamics_Delay1_DSTATE) +
rtb_Dynamics_Gain) + Dynamics_rtDW.Dynamics_Delay_DSTATE[0]) *
0.39478417604357435) - (-7.2104316479128512 *
Dynamics_rtDW.Dynamics_Delay2_DSTATE)) - (2.6178993711731877 *
Dynamics_rtDW.Dynamics_Delay3_DSTATE[0])) / 6.1716689809139611;
/* Product: '<S21>/Product1' incorporates:
* Constant: '<S21>/Constant'
* Gain: '<S21>/gain'
* Product: '<S21>/Product11'
* Sum: '<S21>/Sum1'
* Sum: '<S21>/Sum2'
* Sum: '<S21>/Sum3'
* Sum: '<S21>/Sum4'
* UnitDelay: '<S21>/d'
* UnitDelay: '<S21>/d1'
*/
rtb_Dynamics_Product1_hh = (((rtb_Dynamics_Product1_g +
Dynamics_rtDW.Dynamics_d1_DSTATE_b) * 0.002) + (0.00861032953945969 *
Dynamics_rtDW.Dynamics_d_DSTATE_b)) / 0.01261032953945969;
/* Sum: '<S10>/Sum1' incorporates:
* Gain: '<S10>/gain'
* Sum: '<S10>/Sum2'
* UnitDelay: '<S10>/d'
* UnitDelay: '<S10>/d1'
*/
rtb_Dynamics_Sum1_ig = ((rtb_Dynamics_Product1 -
Dynamics_rtDW.Dynamics_d_DSTATE_hu) * 1000.0) -
Dynamics_rtDW.Dynamics_d1_DSTATE_ad;
/* Sum: '<S11>/Sum1' incorporates:
* Gain: '<S11>/gain'
* Sum: '<S11>/Sum2'
* UnitDelay: '<S11>/d'
* UnitDelay: '<S11>/d1'
*/
rtb_Dynamics_Sum1_l = ((rtb_Dynamics_Sum1_ig -
Dynamics_rtDW.Dynamics_d_DSTATE_c4) * 1000.0) -
Dynamics_rtDW.Dynamics_d1_DSTATE_i;
/* Sum: '<S12>/Sum1' incorporates:
* Gain: '<S12>/gain'
* Sum: '<S12>/Sum2'
* UnitDelay: '<S12>/d'
* UnitDelay: '<S12>/d1'
*/
rtb_Dynamics_Sum1_ap = ((rtb_Dynamics_Sum1_l -
Dynamics_rtDW.Dynamics_d_DSTATE_d) * 1000.0) -
Dynamics_rtDW.Dynamics_d1_DSTATE_e0;
/* Sum: '<S1>/Add3' incorporates:
* Constant: '<S1>/Constant3'
* Constant: '<S1>/Constant4'
* Constant: '<S1>/Constant5'
* Gain: '<S1>/Gain'
* Memory: '<Root>/Memory'
* Product: '<S1>/Product2'
* Product: '<S1>/Product3'
* Product: '<S1>/Product4'
* Sum: '<S1>/Add2'
*/
rtb_Dynamics_Add3 = (((((156.8 * rtb_Dynamics_Product1) + (212.8 *
rtb_Dynamics_Sum1_ig)) + (21.8 * rtb_Dynamics_Sum1_l)) +
rtb_Dynamics_Sum1_ap) * 9.44822373393802E-6) -
Dynamics_rtDW.Dynamics_Memory_PreviousInput;
/* Product: '<S13>/Product1' incorporates:
* Constant: '<S13>/Constant'
* Gain: '<S13>/gain'
* Product: '<S13>/Product11'
* Sum: '<S13>/Sum1'
* Sum: '<S13>/Sum2'
* Sum: '<S13>/Sum3'
* Sum: '<S13>/Sum4'
* UnitDelay: '<S13>/d'
* UnitDelay: '<S13>/d1'
*/
rtb_Dynamics_Product1_d = (((rtb_Dynamics_Add3 +
Dynamics_rtDW.Dynamics_d1_DSTATE_h) * 0.002) + (0.029830988618379066 *
Dynamics_rtDW.Dynamics_d_DSTATE_l)) / 0.03383098861837907;
/* Product: '<S14>/Product1' incorporates:
* Constant: '<S14>/Constant1'
* Constant: '<S14>/Constant2'
* Delay: '<S14>/Delay'
* Delay: '<S14>/Delay1'
* Delay: '<S14>/Delay2'
* Delay: '<S14>/Delay3'
* Gain: '<S14>/gain1'
* Gain: '<S14>/gain3'
* Product: '<S14>/x(n), x(n-1), x(n-2)'
* Product: '<S14>/y(n-1)'
* Product: '<S14>/y(n-2)'
* Sum: '<S14>/Sum1'
* Sum: '<S14>/Sum2'
* Sum: '<S14>/Sum3'
* Sum: '<S14>/Sum4'
* Sum: '<S14>/Sum5'
* Sum: '<S14>/Sum6'
*/
rtb_Dynamics_Product4_d = ((((((2.0 * Dynamics_rtDW.Dynamics_Delay1_DSTATE_a)
+ rtb_Dynamics_Product1_d) + Dynamics_rtDW.Dynamics_Delay_DSTATE_f[0]) *
0.00035530575843921691) - (-7.9992893884831213 *
Dynamics_rtDW.Dynamics_Delay2_DSTATE_b)) - (3.9470487616123275 *
Dynamics_rtDW.Dynamics_Delay3_DSTATE_d[0])) / 4.0536618499045511;
/* MATLAB Function: '<Root>/DOB_Gain' incorporates:
* Inport: '<Root>/<VCU_Vx_Fbk>'
*/
if (Dynamics_rtU.Dynamics_VCU_Vx_Fbk < 5.0) {
rtb_Dynamics_Subtract2 = 0.0;
} else {
rtb_Dynamics_Subtract2 = (Dynamics_rtU.Dynamics_VCU_Vx_Fbk - 5.0) * 0.2;
}
if (rtb_Dynamics_Subtract2 >= 1.0) {
rtb_Dynamics_Subtract2 = 1.0;
}
/* End of MATLAB Function: '<Root>/DOB_Gain' */
/* Product: '<Root>/Product1' incorporates:
* Constant: '<Root>/DOBFlag'
* Product: '<Root>/Product'
*/
Dynamics_u0 = -(rtb_Dynamics_Product4_d * 0.9);
/* Saturate: '<Root>/DOB_Saturation' */
if (Dynamics_u0 > 30.0) {
Dynamics_u0 = 30.0;
} else if (Dynamics_u0 < -30.0) {
Dynamics_u0 = -30.0;
} else {
/* no actions */
}
/* Sum: '<Root>/Subtract2' incorporates:
* DeadZone: '<S4>/Dead Zone'
* MultiPortSwitch: '<S15>/Multiport Switch1'
* Product: '<Root>/Multiply1'
* Product: '<S17>/Product'
* Saturate: '<Root>/DOB_Saturation'
* Sum: '<S4>/Add'
*/
rtb_Dynamics_MultiportSwitch1 = ((rtb_Dynamics_MultiportSwitch1 *
0.044648264844923756) + rtb_Dynamics_Product1_hh) + (Dynamics_u0 *
rtb_Dynamics_Subtract2);
/* Saturate: '<Root>/Torq_Saturation' */
if (rtb_Dynamics_MultiportSwitch1 > 80.0) {
rtb_Dynamics_MultiportSwitch1 = 80.0;
} else if (rtb_Dynamics_MultiportSwitch1 < -80.0) {
rtb_Dynamics_MultiportSwitch1 = -80.0;
} else {
/* no actions */
}
/* End of Saturate: '<Root>/Torq_Saturation' */
/* MATLAB Function: '<Root>/Gear_pos_out' incorporates:
* Inport: '<Root>/<RC_GearPosition>'
*/
if (Dynamics_rtU.Dynamics_RC_GearPosition == 0.0) {
Dynamics_tmp = 0;
} else if (Dynamics_rtU.Dynamics_RC_GearPosition == 2.0) {
Dynamics_tmp = 0;
} else if (Dynamics_rtU.Dynamics_RC_GearPosition == 1.0) {
Dynamics_tmp = -1;
} else {
Dynamics_tmp = (Dynamics_rtU.Dynamics_RC_GearPosition == 3.0) ? ((int32_T)1)
: ((int32_T)0);
}
/* Outport: '<Root>/Torq_cmd_out1' incorporates:
* MATLAB Function: '<Root>/Gear_pos_out'
* Product: '<Root>/Multiply'
*/
Dynamics_rtY.Dynamics_Torq_cmd_out1 = ((real_T)Dynamics_tmp) *
rtb_Dynamics_MultiportSwitch1;
/* Update for UnitDelay: '<S7>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE = rtb_Dynamics_Vx_Output;
/* Update for UnitDelay: '<S7>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE = rtb_Dynamics_Product1;
/* Update for UnitDelay: '<S18>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_c = rtb_Dynamics_Product1;
/* Update for UnitDelay: '<S18>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_e = rtb_Dynamics_Sum1_jm;
/* Update for UnitDelay: '<S19>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_h = rtb_Dynamics_Sum1_jm;
/* Update for UnitDelay: '<S19>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_p = rtb_Dynamics_Error;
/* Update for UnitDelay: '<S20>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_g = rtb_Dynamics_Error;
/* Update for UnitDelay: '<S20>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_a = rtb_Dynamics_Sum1_n;
/* Update for Delay: '<S22>/Delay1' */
Dynamics_rtDW.Dynamics_Delay1_DSTATE = rtb_Dynamics_Gain;
/* Update for Delay: '<S22>/Delay' */
Dynamics_rtDW.Dynamics_Delay_DSTATE[0] = Dynamics_rtDW.Dynamics_Delay_DSTATE[1];
Dynamics_rtDW.Dynamics_Delay_DSTATE[1] = rtb_Dynamics_Gain;
/* Update for Delay: '<S22>/Delay2' */
Dynamics_rtDW.Dynamics_Delay2_DSTATE = rtb_Dynamics_Product1_g;
/* Update for Delay: '<S22>/Delay3' */
Dynamics_rtDW.Dynamics_Delay3_DSTATE[0] =
Dynamics_rtDW.Dynamics_Delay3_DSTATE[1];
Dynamics_rtDW.Dynamics_Delay3_DSTATE[1] = rtb_Dynamics_Product1_g;
/* Update for UnitDelay: '<S21>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_b = rtb_Dynamics_Product1_g;
/* Update for UnitDelay: '<S21>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_b = rtb_Dynamics_Product1_hh;
/* Update for Memory: '<Root>/Memory' */
Dynamics_rtDW.Dynamics_Memory_PreviousInput = rtb_Dynamics_MultiportSwitch1;
/* Update for UnitDelay: '<S10>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_hu = rtb_Dynamics_Product1;
/* Update for UnitDelay: '<S10>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_ad = rtb_Dynamics_Sum1_ig;
/* Update for UnitDelay: '<S11>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_c4 = rtb_Dynamics_Sum1_ig;
/* Update for UnitDelay: '<S11>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_i = rtb_Dynamics_Sum1_l;
/* Update for UnitDelay: '<S12>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_d = rtb_Dynamics_Sum1_l;
/* Update for UnitDelay: '<S12>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_e0 = rtb_Dynamics_Sum1_ap;
/* Update for UnitDelay: '<S13>/d1' */
Dynamics_rtDW.Dynamics_d1_DSTATE_h = rtb_Dynamics_Add3;
/* Update for UnitDelay: '<S13>/d' */
Dynamics_rtDW.Dynamics_d_DSTATE_l = rtb_Dynamics_Product1_d;
/* Update for Delay: '<S14>/Delay1' */
Dynamics_rtDW.Dynamics_Delay1_DSTATE_a = rtb_Dynamics_Product1_d;
/* Update for Delay: '<S14>/Delay' */
Dynamics_rtDW.Dynamics_Delay_DSTATE_f[0] =
Dynamics_rtDW.Dynamics_Delay_DSTATE_f[1];
Dynamics_rtDW.Dynamics_Delay_DSTATE_f[1] = rtb_Dynamics_Product1_d;
/* Update for Delay: '<S14>/Delay2' */
Dynamics_rtDW.Dynamics_Delay2_DSTATE_b = rtb_Dynamics_Product4_d;
/* Update for Delay: '<S14>/Delay3' */
Dynamics_rtDW.Dynamics_Delay3_DSTATE_d[0] =
Dynamics_rtDW.Dynamics_Delay3_DSTATE_d[1];
Dynamics_rtDW.Dynamics_Delay3_DSTATE_d[1] = rtb_Dynamics_Product4_d;
}
/* Model initialize function */
void wheelSpd2_initialize(void)
{
/* (no initialization code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/

View File

@ -0,0 +1,185 @@
/*
* 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: wheelSpd2.h
*
* Code generated for Simulink model 'wheelSpd2'.
*
* Model version : 1.9
* Simulink Coder version : 9.9 (R2023a) 19-Nov-2022
* C/C++ source code generated on : Wed Sep 25 21:15:56 2024
*
* Target selection: ert.tlc
* Embedded hardware selection: NXP->Cortex-M4
* Code generation objectives:
* 1. Execution efficiency
* 2. Debugging
* Validation result: Not run
*/
#ifndef RTW_HEADER_wheelSpd2_h_
#define RTW_HEADER_wheelSpd2_h_
#ifndef wheelSpd2_COMMON_INCLUDES_
#define wheelSpd2_COMMON_INCLUDES_
#include "rtwtypes.h"
#endif /* wheelSpd2_COMMON_INCLUDES_ */
/* Macros for accessing real-time model data structure */
#ifndef rtmGetErrorStatus
#define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
#endif
#ifndef rtmSetErrorStatus
#define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
#endif
/* Forward declaration for rtModel */
typedef struct Dynamics_tag_RTM Dynamics_RT_MODEL;
/* Block signals and states (default storage) for system '<Root>' */
typedef struct {
real_T Dynamics_Delay_DSTATE[2]; /* '<S22>/Delay' */
real_T Dynamics_Delay3_DSTATE[2]; /* '<S22>/Delay3' */
real_T Dynamics_Delay_DSTATE_f[2]; /* '<S14>/Delay' */
real_T Dynamics_Delay3_DSTATE_d[2]; /* '<S14>/Delay3' */
real_T Dynamics_d1_DSTATE; /* '<S7>/d1' */
real_T Dynamics_d_DSTATE; /* '<S7>/d' */
real_T Dynamics_d_DSTATE_c; /* '<S18>/d' */
real_T Dynamics_d1_DSTATE_e; /* '<S18>/d1' */
real_T Dynamics_d_DSTATE_h; /* '<S19>/d' */
real_T Dynamics_d1_DSTATE_p; /* '<S19>/d1' */
real_T Dynamics_d_DSTATE_g; /* '<S20>/d' */
real_T Dynamics_d1_DSTATE_a; /* '<S20>/d1' */
real_T Dynamics_Delay1_DSTATE; /* '<S22>/Delay1' */
real_T Dynamics_Delay2_DSTATE; /* '<S22>/Delay2' */
real_T Dynamics_d1_DSTATE_b; /* '<S21>/d1' */
real_T Dynamics_d_DSTATE_b; /* '<S21>/d' */
real_T Dynamics_d_DSTATE_hu; /* '<S10>/d' */
real_T Dynamics_d1_DSTATE_ad; /* '<S10>/d1' */
real_T Dynamics_d_DSTATE_c4; /* '<S11>/d' */
real_T Dynamics_d1_DSTATE_i; /* '<S11>/d1' */
real_T Dynamics_d_DSTATE_d; /* '<S12>/d' */
real_T Dynamics_d1_DSTATE_e0; /* '<S12>/d1' */
real_T Dynamics_d1_DSTATE_h; /* '<S13>/d1' */
real_T Dynamics_d_DSTATE_l; /* '<S13>/d' */
real_T Dynamics_Delay1_DSTATE_a; /* '<S14>/Delay1' */
real_T Dynamics_Delay2_DSTATE_b; /* '<S14>/Delay2' */
real_T Dynamics_PrevY; /* '<Root>/Input_Vx_RateLimiter' */
real_T Dynamics_PrevY_e; /* '<Root>/TargetSpd_RateLimiter' */
real_T Dynamics_PrevY_f; /* '<Root>/Brake_Out_RateLimiter' */
real_T Dynamics_Memory_PreviousInput;/* '<Root>/Memory' */
} Dynamics_DW;
/* External inputs (root inport signals with default storage) */
typedef struct {
real_T Dynamics_RPM; /* '<Root>/<RPM>' */
real_T Dynamics_TQ; /* '<Root>/<TQ>' */
real_T Dynamics_Brake_input; /* '<Root>/<Brake_input>' */
real_T Dynamics_Vx_Cmd; /* '<Root>/<Vx_Cmd>' */
real_T Dynamics_Vx_Limit; /* '<Root>/<Vx_Limit>' */
real_T Dynamics_VCU_Vx_Fbk; /* '<Root>/<VCU_Vx_Fbk>' */
real_T Dynamics_RC_GearPosition; /* '<Root>/<RC_GearPosition>' */
} Dynamics_ExtU;
/* External outputs (root outports fed by signals with default storage) */
typedef struct {
real_T Dynamics_Brake_cmd_out; /* '<Root>/Brake_cmd_out' */
real_T Dynamics_Torq_cmd_out1; /* '<Root>/Torq_cmd_out1' */
} Dynamics_ExtY;
/* Real-time Model Data Structure */
struct Dynamics_tag_RTM {
const char_T * volatile errorStatus;
};
/* Block signals and states (default storage) */
extern Dynamics_DW Dynamics_rtDW;
/* External inputs (root inport signals with default storage) */
extern Dynamics_ExtU Dynamics_rtU;
/* External outputs (root outports fed by signals with default storage) */
extern Dynamics_ExtY Dynamics_rtY;
/* Model entry point functions */
extern void wheelSpd2_initialize(void);
extern void wheelSpd2_step(void);
/* Real-time Model object */
extern Dynamics_RT_MODEL *const Dynamics_rtM;
/*-
* These blocks were eliminated from the model due to optimizations:
*
* Block '<S4>/BW_PI' : Unused code path elimination
* Block '<S4>/Constant1' : Unused code path elimination
* Block '<S4>/Constant16' : Unused code path elimination
* Block '<S4>/Constant17' : Unused code path elimination
* Block '<S4>/Constant2' : Unused code path elimination
* Block '<Root>/Vx_Cmd' : Unused code path elimination
* Block '<Root>/ControlFlag' : Eliminated nontunable gain of 1
* Block '<S4>/FBGain' : Eliminated nontunable gain of 1
* Block '<S16>/FFGain' : Eliminated nontunable gain of 1
* Block '<S23>/Constant1' : Unused code path elimination
* Block '<S23>/Constant2' : Unused code path elimination
* Block '<S23>/Switch' : Unused code path elimination
* Block '<S23>/Switch1' : Unused code path elimination
* Block '<S23>/Switch2' : Unused code path elimination
* Block '<S23>/Switch3' : Unused code path elimination
* Block '<S9>/Creeping_Flag' : Unused code path elimination
*/
/*-
* The generated code includes comments that allow you to trace directly
* back to the appropriate location in the model. The basic format
* is <system>/block_name, where system is the system number (uniquely
* assigned by Simulink) and block_name is the name of the block.
*
* Use the MATLAB hilite_system command to trace the generated code back
* to the model. For example,
*
* hilite_system('<S3>') - opens system 3
* hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
*
* Here is the system hierarchy for this model
*
* '<Root>' : 'wheelSpd2'
* '<S1>' : 'wheelSpd2/DOB'
* '<S2>' : 'wheelSpd2/DOB_Gain'
* '<S3>' : 'wheelSpd2/Error_Initalize_Brake'
* '<S4>' : 'wheelSpd2/FF_PID_Controller'
* '<S5>' : 'wheelSpd2/GearCondition_Brake'
* '<S6>' : 'wheelSpd2/Gear_pos_out'
* '<S7>' : 'wheelSpd2/LPFM'
* '<S8>' : 'wheelSpd2/Target_RPM'
* '<S9>' : 'wheelSpd2/Vx_Logic'
* '<S10>' : 'wheelSpd2/DOB/Dot3'
* '<S11>' : 'wheelSpd2/DOB/Dot4'
* '<S12>' : 'wheelSpd2/DOB/Dot5'
* '<S13>' : 'wheelSpd2/DOB/LPFM'
* '<S14>' : 'wheelSpd2/DOB/Second order LPF'
* '<S15>' : 'wheelSpd2/FF_PID_Controller/FB'
* '<S16>' : 'wheelSpd2/FF_PID_Controller/FF'
* '<S17>' : 'wheelSpd2/FF_PID_Controller/FB/P'
* '<S18>' : 'wheelSpd2/FF_PID_Controller/FF/Dot'
* '<S19>' : 'wheelSpd2/FF_PID_Controller/FF/Dot2'
* '<S20>' : 'wheelSpd2/FF_PID_Controller/FF/Dot3'
* '<S21>' : 'wheelSpd2/FF_PID_Controller/FF/LPFM'
* '<S22>' : 'wheelSpd2/FF_PID_Controller/FF/Second order LPF'
* '<S23>' : 'wheelSpd2/Vx_Logic/Creeping Control'
* '<S24>' : 'wheelSpd2/Vx_Logic/Vx_OutPut_Function'
*/
/*-
* Requirements for '<Root>': wheelSpd2
*/
#endif /* RTW_HEADER_wheelSpd2_h_ */
/*
* File trailer for generated code.
*
* [EOF]
*/