diff --git a/GW/src/Dynamics_Motor_logic/rtwtypes.h b/GW/src/Dynamics_Motor_logic/rtwtypes.h new file mode 100644 index 00000000..687f9559 --- /dev/null +++ b/GW/src/Dynamics_Motor_logic/rtwtypes.h @@ -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] + */ diff --git a/GW/src/Dynamics_Motor_logic/wheelSpd2.c b/GW/src/Dynamics_Motor_logic/wheelSpd2.c new file mode 100644 index 00000000..0bebe2bc --- /dev/null +++ b/GW/src/Dynamics_Motor_logic/wheelSpd2.c @@ -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: '/Vx_OutPut_Function' incorporates: + * Inport: '/' + * Inport: '/' + */ + 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: '/Vx_OutPut_Function' */ + + /* RateLimiter: '/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: '/Input_Vx_RateLimiter' */ + + /* MATLAB Function: '/Target_RPM' incorporates: + * Inport: '/' + */ + 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: '/Target_RPM' */ + + /* RateLimiter: '/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: '/TargetSpd_RateLimiter' */ + + /* Product: '/Product1' incorporates: + * Constant: '/Constant' + * Gain: '/gain' + * Product: '/Product11' + * Sum: '/Sum1' + * Sum: '/Sum2' + * Sum: '/Sum3' + * Sum: '/Sum4' + * UnitDelay: '/d' + * UnitDelay: '/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: '/Subtract' incorporates: + * Inport: '/' + */ + rtb_Dynamics_Error = rtb_Dynamics_Product1 - Dynamics_rtU.Dynamics_RPM; + + /* Saturate: '/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: '/Error_Saturation' */ + + /* MATLAB Function: '/GearCondition_Brake' incorporates: + * Inport: '/' + */ + 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: '/Switch1' incorporates: + * Constant: '/Constant4' + */ + if (rtb_Dynamics_Error > 0.0) { + rtb_Dynamics_MultiportSwitch1 = 0.0; + } else { + rtb_Dynamics_MultiportSwitch1 = rtb_Dynamics_Error; + } + + /* Product: '/Multiply2' incorporates: + * Gain: '/Brake_GAIN' + * MATLAB Function: '/GearCondition_Brake' + * Switch: '/Switch1' + */ + rtb_Dynamics_MultiportSwitch1 = (-0.8 * rtb_Dynamics_MultiportSwitch1) * + ((real_T)Dynamics_tmp); + + /* RateLimiter: '/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: '/Brake_Out_RateLimiter' */ + + /* Saturate: '/Brake_Saturation' */ + if (rtb_Dynamics_MultiportSwitch1 > 1000.0) { + /* Outport: '/Brake_cmd_out' */ + Dynamics_rtY.Dynamics_Brake_cmd_out = 1000.0; + } else if (rtb_Dynamics_MultiportSwitch1 < 0.0) { + /* Outport: '/Brake_cmd_out' */ + Dynamics_rtY.Dynamics_Brake_cmd_out = 0.0; + } else { + /* Outport: '/Brake_cmd_out' */ + Dynamics_rtY.Dynamics_Brake_cmd_out = rtb_Dynamics_MultiportSwitch1; + } + + /* End of Saturate: '/Brake_Saturation' */ + + /* DeadZone: '/Dead Zone' incorporates: + * MultiPortSwitch: '/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: '/Sum1' incorporates: + * Gain: '/gain' + * Sum: '/Sum2' + * UnitDelay: '/d' + * UnitDelay: '/d1' + */ + rtb_Dynamics_Sum1_jm = ((rtb_Dynamics_Product1 - + Dynamics_rtDW.Dynamics_d_DSTATE_c) * 1000.0) - + Dynamics_rtDW.Dynamics_d1_DSTATE_e; + + /* Sum: '/Sum1' incorporates: + * Gain: '/gain' + * Sum: '/Sum2' + * UnitDelay: '/d' + * UnitDelay: '/d1' + */ + rtb_Dynamics_Error = ((rtb_Dynamics_Sum1_jm - + Dynamics_rtDW.Dynamics_d_DSTATE_h) * 1000.0) - + Dynamics_rtDW.Dynamics_d1_DSTATE_p; + + /* Sum: '/Sum1' incorporates: + * Gain: '/gain' + * Sum: '/Sum2' + * UnitDelay: '/d' + * UnitDelay: '/d1' + */ + rtb_Dynamics_Sum1_n = ((rtb_Dynamics_Error - Dynamics_rtDW.Dynamics_d_DSTATE_g) + * 1000.0) - Dynamics_rtDW.Dynamics_d1_DSTATE_a; + + /* Gain: '/Gain' incorporates: + * Constant: '/Constant3' + * Constant: '/Constant4' + * Constant: '/Constant5' + * Product: '/Product' + * Product: '/Product1' + * Product: '/Product2' + * Sum: '/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: '/Product1' incorporates: + * Constant: '/Constant1' + * Constant: '/Constant2' + * Delay: '/Delay' + * Delay: '/Delay1' + * Delay: '/Delay2' + * Delay: '/Delay3' + * Gain: '/gain1' + * Gain: '/gain3' + * Product: '/x(n), x(n-1), x(n-2)' + * Product: '/y(n-1)' + * Product: '/y(n-2)' + * Sum: '/Sum1' + * Sum: '/Sum2' + * Sum: '/Sum3' + * Sum: '/Sum4' + * Sum: '/Sum5' + * Sum: '/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: '/Product1' incorporates: + * Constant: '/Constant' + * Gain: '/gain' + * Product: '/Product11' + * Sum: '/Sum1' + * Sum: '/Sum2' + * Sum: '/Sum3' + * Sum: '/Sum4' + * UnitDelay: '/d' + * UnitDelay: '/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: '/Sum1' incorporates: + * Gain: '/gain' + * Sum: '/Sum2' + * UnitDelay: '/d' + * UnitDelay: '/d1' + */ + rtb_Dynamics_Sum1_ig = ((rtb_Dynamics_Product1 - + Dynamics_rtDW.Dynamics_d_DSTATE_hu) * 1000.0) - + Dynamics_rtDW.Dynamics_d1_DSTATE_ad; + + /* Sum: '/Sum1' incorporates: + * Gain: '/gain' + * Sum: '/Sum2' + * UnitDelay: '/d' + * UnitDelay: '/d1' + */ + rtb_Dynamics_Sum1_l = ((rtb_Dynamics_Sum1_ig - + Dynamics_rtDW.Dynamics_d_DSTATE_c4) * 1000.0) - + Dynamics_rtDW.Dynamics_d1_DSTATE_i; + + /* Sum: '/Sum1' incorporates: + * Gain: '/gain' + * Sum: '/Sum2' + * UnitDelay: '/d' + * UnitDelay: '/d1' + */ + rtb_Dynamics_Sum1_ap = ((rtb_Dynamics_Sum1_l - + Dynamics_rtDW.Dynamics_d_DSTATE_d) * 1000.0) - + Dynamics_rtDW.Dynamics_d1_DSTATE_e0; + + /* Sum: '/Add3' incorporates: + * Constant: '/Constant3' + * Constant: '/Constant4' + * Constant: '/Constant5' + * Gain: '/Gain' + * Memory: '/Memory' + * Product: '/Product2' + * Product: '/Product3' + * Product: '/Product4' + * Sum: '/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: '/Product1' incorporates: + * Constant: '/Constant' + * Gain: '/gain' + * Product: '/Product11' + * Sum: '/Sum1' + * Sum: '/Sum2' + * Sum: '/Sum3' + * Sum: '/Sum4' + * UnitDelay: '/d' + * UnitDelay: '/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: '/Product1' incorporates: + * Constant: '/Constant1' + * Constant: '/Constant2' + * Delay: '/Delay' + * Delay: '/Delay1' + * Delay: '/Delay2' + * Delay: '/Delay3' + * Gain: '/gain1' + * Gain: '/gain3' + * Product: '/x(n), x(n-1), x(n-2)' + * Product: '/y(n-1)' + * Product: '/y(n-2)' + * Sum: '/Sum1' + * Sum: '/Sum2' + * Sum: '/Sum3' + * Sum: '/Sum4' + * Sum: '/Sum5' + * Sum: '/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: '/DOB_Gain' incorporates: + * Inport: '/' + */ + 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: '/DOB_Gain' */ + + /* Product: '/Product1' incorporates: + * Constant: '/DOBFlag' + * Product: '/Product' + */ + Dynamics_u0 = -(rtb_Dynamics_Product4_d * 0.9); + + /* Saturate: '/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: '/Subtract2' incorporates: + * DeadZone: '/Dead Zone' + * MultiPortSwitch: '/Multiport Switch1' + * Product: '/Multiply1' + * Product: '/Product' + * Saturate: '/DOB_Saturation' + * Sum: '/Add' + */ + rtb_Dynamics_MultiportSwitch1 = ((rtb_Dynamics_MultiportSwitch1 * + 0.044648264844923756) + rtb_Dynamics_Product1_hh) + (Dynamics_u0 * + rtb_Dynamics_Subtract2); + + /* Saturate: '/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: '/Torq_Saturation' */ + + /* MATLAB Function: '/Gear_pos_out' incorporates: + * Inport: '/' + */ + 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: '/Torq_cmd_out1' incorporates: + * MATLAB Function: '/Gear_pos_out' + * Product: '/Multiply' + */ + Dynamics_rtY.Dynamics_Torq_cmd_out1 = ((real_T)Dynamics_tmp) * + rtb_Dynamics_MultiportSwitch1; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE = rtb_Dynamics_Vx_Output; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE = rtb_Dynamics_Product1; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_c = rtb_Dynamics_Product1; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_e = rtb_Dynamics_Sum1_jm; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_h = rtb_Dynamics_Sum1_jm; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_p = rtb_Dynamics_Error; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_g = rtb_Dynamics_Error; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_a = rtb_Dynamics_Sum1_n; + + /* Update for Delay: '/Delay1' */ + Dynamics_rtDW.Dynamics_Delay1_DSTATE = rtb_Dynamics_Gain; + + /* Update for Delay: '/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: '/Delay2' */ + Dynamics_rtDW.Dynamics_Delay2_DSTATE = rtb_Dynamics_Product1_g; + + /* Update for Delay: '/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: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_b = rtb_Dynamics_Product1_g; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_b = rtb_Dynamics_Product1_hh; + + /* Update for Memory: '/Memory' */ + Dynamics_rtDW.Dynamics_Memory_PreviousInput = rtb_Dynamics_MultiportSwitch1; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_hu = rtb_Dynamics_Product1; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_ad = rtb_Dynamics_Sum1_ig; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_c4 = rtb_Dynamics_Sum1_ig; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_i = rtb_Dynamics_Sum1_l; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_d = rtb_Dynamics_Sum1_l; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_e0 = rtb_Dynamics_Sum1_ap; + + /* Update for UnitDelay: '/d1' */ + Dynamics_rtDW.Dynamics_d1_DSTATE_h = rtb_Dynamics_Add3; + + /* Update for UnitDelay: '/d' */ + Dynamics_rtDW.Dynamics_d_DSTATE_l = rtb_Dynamics_Product1_d; + + /* Update for Delay: '/Delay1' */ + Dynamics_rtDW.Dynamics_Delay1_DSTATE_a = rtb_Dynamics_Product1_d; + + /* Update for Delay: '/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: '/Delay2' */ + Dynamics_rtDW.Dynamics_Delay2_DSTATE_b = rtb_Dynamics_Product4_d; + + /* Update for Delay: '/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] + */ diff --git a/GW/src/Dynamics_Motor_logic/wheelSpd2.h b/GW/src/Dynamics_Motor_logic/wheelSpd2.h new file mode 100644 index 00000000..5ca396f2 --- /dev/null +++ b/GW/src/Dynamics_Motor_logic/wheelSpd2.h @@ -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 '' */ +typedef struct { + real_T Dynamics_Delay_DSTATE[2]; /* '/Delay' */ + real_T Dynamics_Delay3_DSTATE[2]; /* '/Delay3' */ + real_T Dynamics_Delay_DSTATE_f[2]; /* '/Delay' */ + real_T Dynamics_Delay3_DSTATE_d[2]; /* '/Delay3' */ + real_T Dynamics_d1_DSTATE; /* '/d1' */ + real_T Dynamics_d_DSTATE; /* '/d' */ + real_T Dynamics_d_DSTATE_c; /* '/d' */ + real_T Dynamics_d1_DSTATE_e; /* '/d1' */ + real_T Dynamics_d_DSTATE_h; /* '/d' */ + real_T Dynamics_d1_DSTATE_p; /* '/d1' */ + real_T Dynamics_d_DSTATE_g; /* '/d' */ + real_T Dynamics_d1_DSTATE_a; /* '/d1' */ + real_T Dynamics_Delay1_DSTATE; /* '/Delay1' */ + real_T Dynamics_Delay2_DSTATE; /* '/Delay2' */ + real_T Dynamics_d1_DSTATE_b; /* '/d1' */ + real_T Dynamics_d_DSTATE_b; /* '/d' */ + real_T Dynamics_d_DSTATE_hu; /* '/d' */ + real_T Dynamics_d1_DSTATE_ad; /* '/d1' */ + real_T Dynamics_d_DSTATE_c4; /* '/d' */ + real_T Dynamics_d1_DSTATE_i; /* '/d1' */ + real_T Dynamics_d_DSTATE_d; /* '/d' */ + real_T Dynamics_d1_DSTATE_e0; /* '/d1' */ + real_T Dynamics_d1_DSTATE_h; /* '/d1' */ + real_T Dynamics_d_DSTATE_l; /* '/d' */ + real_T Dynamics_Delay1_DSTATE_a; /* '/Delay1' */ + real_T Dynamics_Delay2_DSTATE_b; /* '/Delay2' */ + real_T Dynamics_PrevY; /* '/Input_Vx_RateLimiter' */ + real_T Dynamics_PrevY_e; /* '/TargetSpd_RateLimiter' */ + real_T Dynamics_PrevY_f; /* '/Brake_Out_RateLimiter' */ + real_T Dynamics_Memory_PreviousInput;/* '/Memory' */ +} Dynamics_DW; + +/* External inputs (root inport signals with default storage) */ +typedef struct { + real_T Dynamics_RPM; /* '/' */ + real_T Dynamics_TQ; /* '/' */ + real_T Dynamics_Brake_input; /* '/' */ + real_T Dynamics_Vx_Cmd; /* '/' */ + real_T Dynamics_Vx_Limit; /* '/' */ + real_T Dynamics_VCU_Vx_Fbk; /* '/' */ + real_T Dynamics_RC_GearPosition; /* '/' */ +} Dynamics_ExtU; + +/* External outputs (root outports fed by signals with default storage) */ +typedef struct { + real_T Dynamics_Brake_cmd_out; /* '/Brake_cmd_out' */ + real_T Dynamics_Torq_cmd_out1; /* '/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 '/BW_PI' : Unused code path elimination + * Block '/Constant1' : Unused code path elimination + * Block '/Constant16' : Unused code path elimination + * Block '/Constant17' : Unused code path elimination + * Block '/Constant2' : Unused code path elimination + * Block '/Vx_Cmd' : Unused code path elimination + * Block '/ControlFlag' : Eliminated nontunable gain of 1 + * Block '/FBGain' : Eliminated nontunable gain of 1 + * Block '/FFGain' : Eliminated nontunable gain of 1 + * Block '/Constant1' : Unused code path elimination + * Block '/Constant2' : Unused code path elimination + * Block '/Switch' : Unused code path elimination + * Block '/Switch1' : Unused code path elimination + * Block '/Switch2' : Unused code path elimination + * Block '/Switch3' : Unused code path elimination + * Block '/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 /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('') - opens system 3 + * hilite_system('/Kp') - opens and selects block Kp which resides in S3 + * + * Here is the system hierarchy for this model + * + * '' : 'wheelSpd2' + * '' : 'wheelSpd2/DOB' + * '' : 'wheelSpd2/DOB_Gain' + * '' : 'wheelSpd2/Error_Initalize_Brake' + * '' : 'wheelSpd2/FF_PID_Controller' + * '' : 'wheelSpd2/GearCondition_Brake' + * '' : 'wheelSpd2/Gear_pos_out' + * '' : 'wheelSpd2/LPFM' + * '' : 'wheelSpd2/Target_RPM' + * '' : 'wheelSpd2/Vx_Logic' + * '' : 'wheelSpd2/DOB/Dot3' + * '' : 'wheelSpd2/DOB/Dot4' + * '' : 'wheelSpd2/DOB/Dot5' + * '' : 'wheelSpd2/DOB/LPFM' + * '' : 'wheelSpd2/DOB/Second order LPF' + * '' : 'wheelSpd2/FF_PID_Controller/FB' + * '' : 'wheelSpd2/FF_PID_Controller/FF' + * '' : 'wheelSpd2/FF_PID_Controller/FB/P' + * '' : 'wheelSpd2/FF_PID_Controller/FF/Dot' + * '' : 'wheelSpd2/FF_PID_Controller/FF/Dot2' + * '' : 'wheelSpd2/FF_PID_Controller/FF/Dot3' + * '' : 'wheelSpd2/FF_PID_Controller/FF/LPFM' + * '' : 'wheelSpd2/FF_PID_Controller/FF/Second order LPF' + * '' : 'wheelSpd2/Vx_Logic/Creeping Control' + * '' : 'wheelSpd2/Vx_Logic/Vx_OutPut_Function' + */ + +/*- + * Requirements for '': wheelSpd2 + + */ +#endif /* RTW_HEADER_wheelSpd2_h_ */ + +/* + * File trailer for generated code. + * + * [EOF] + */