/*
 * 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: ADM_Integrated_Logic.c
 *
 * Code generated for Simulink model 'ADM_Integrated_Logic'.
 *
 * Model version                  : 14.11
 * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
 * C/C++ source code generated on : Wed Oct  1 13:12:45 2025
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: NXP->Cortex-M4
 * Code generation objectives:
 *    1. Execution efficiency
 *    2. RAM efficiency
 *    3. Debugging
 * Validation result: Not run
 */

#include "ADM_Integrated_Logic.h"
#include <stdint.h>
#include <math.h>
#include <stdbool.h>

/* Named constants for Chart: '<S8>/Chart' */
#define IN_HAC_OFF                     ((uint8_t)1U)
#define IN_HAC_ON                      ((uint8_t)2U)

/* Block signals and states (default storage) */
DW_ADM_Integrated_Logic_T ADM_Integrated_Logic_DW;

/* External inputs (root inport signals with default storage) */
ExtU_ADM_Integrated_Logic_T ADM_Integrated_Logic_U;

/* External outputs (root outports fed by signals with default storage) */
ExtY_ADM_Integrated_Logic_T ADM_Integrated_Logic_Y;

/* Real-time model */
static RT_MODEL_ADM_Integrated_Logic_T ADM_Integrated_Logic_M_;
RT_MODEL_ADM_Integrated_Logic_T *const ADM_Integrated_Logic_M =
  &ADM_Integrated_Logic_M_;
static void ADM_Integrated_Lo_Calculate_F_c(double rtu_W, double rtu_theta,
  double *rty_F_c);
static void ADM_Integrated__MATLABFunction1(double rtu_u, double *rty_y);
static void ADM_Integrated__MATLABFunction2(double rtu_u, double *rty_y);

/*
 * Output and update for atomic system:
 *    '<S43>/Calculate_F_c'
 *    '<S43>/Calculate_F_c1'
 */
static void ADM_Integrated_Lo_Calculate_F_c(double rtu_W, double rtu_theta,
  double *rty_F_c)
{
  *rty_F_c = rtu_W * sin(rtu_theta);
}

/*
 * Output and update for atomic system:
 *    '<S1>/MATLAB Function1'
 *    '<S1>/MATLAB Function5'
 */
static void ADM_Integrated__MATLABFunction1(double rtu_u, double *rty_y)
{
  *rty_y = rtu_u;
  if (rtu_u < 140.0) {
    *rty_y = 140.0;
  }
}

/*
 * Output and update for atomic system:
 *    '<S1>/MATLAB Function2'
 *    '<S1>/MATLAB Function6'
 */
static void ADM_Integrated__MATLABFunction2(double rtu_u, double *rty_y)
{
  *rty_y = rtu_u;
  if (rtu_u > -140.0) {
    *rty_y = -140.0;
  }
}

/* Model step function */
void ADM_Integrated_Logic_step(void)
{
  double rtb_Add3;
  double rtb_Add_e;
  double rtb_Brake_Saturation;
  double rtb_Brake_Torque_Cmd;
  double rtb_Error_m;
  double rtb_Gain_c;
  double rtb_Integrator_1;
  double rtb_Pitch_Angle;
  double rtb_Pitch_Saturation;
  double rtb_Product1_ee;
  double rtb_Product1_h;
  double rtb_Product1_j;
  double rtb_Product1_kq;
  double rtb_Product1_m;
  double rtb_Sum1_aj;
  double rtb_Sum1_i2;
  double rtb_Sum1_lm;
  double rtb_Sum1_o1;
  double rtb_Sum1_p;
  double rtb_Switch2;
  double rtb_TargetSpd_RateLimiter;
  double rtb_Target_RPM;
  double rtb_UkYk1_j;
  double rtb_Vx_Cmd_R;
  double rtb_deltafalllimit_a;
  double rtb_deltafalllimit_m;
  double rtb_y;
  double rtb_y_e_tmp;
  double rtb_y_k;
  int32_t tmp;
  bool rtb_Compare;
  bool rtb_Compare_d;

  /* RelationalOperator: '<S3>/Compare' incorporates:
   *  Constant: '<S3>/Constant'
   *  Inport: '<Root>/GV_Drive_Mode'
   */
  rtb_Compare = (ADM_Integrated_Logic_U.GV_Drive_Mode == 2.0);

  /* MATLAB Function: '<S18>/Vx_OutPut_Function' incorporates:
   *  Constant: '<S58>/Constant'
   *  Inport: '<Root>/GV_BrakeTorqueCommand'
   *  Inport: '<Root>/GV_Vx_Command'
   *  Inport: '<Root>/GV_Vx_Limit'
   *  RelationalOperator: '<S58>/Compare'
   */
  if (!(ADM_Integrated_Logic_U.GV_BrakeTorqueCommand >= 50.0)) {
    if (ADM_Integrated_Logic_U.GV_Vx_Limit <=
        ADM_Integrated_Logic_U.GV_Vx_Command) {
      rtb_Add_e = ADM_Integrated_Logic_U.GV_Vx_Limit;
    } else {
      rtb_Add_e = ADM_Integrated_Logic_U.GV_Vx_Command;
    }
  } else {
    rtb_Add_e = 0.0;
  }

  /* Product: '<S18>/Product' incorporates:
   *  MATLAB Function: '<S18>/Vx_OutPut_Function'
   *  Switch: '<S18>/Switch'
   */
  rtb_Pitch_Angle = rtb_Add_e * (double)!rtb_Compare;

  /* RateLimiter: '<S18>/Input_Vx_RateLimiter' */
  rtb_TargetSpd_RateLimiter = rtb_Pitch_Angle - ADM_Integrated_Logic_DW.PrevY;
  if (rtb_TargetSpd_RateLimiter > 0.004) {
    rtb_Vx_Cmd_R = ADM_Integrated_Logic_DW.PrevY + 0.004;
  } else if (rtb_TargetSpd_RateLimiter < -0.008) {
    rtb_Vx_Cmd_R = ADM_Integrated_Logic_DW.PrevY - 0.008;
  } else {
    rtb_Vx_Cmd_R = rtb_Pitch_Angle;
  }

  ADM_Integrated_Logic_DW.PrevY = rtb_Vx_Cmd_R;

  /* End of RateLimiter: '<S18>/Input_Vx_RateLimiter' */

  /* RelationalOperator: '<S39>/Compare' incorporates:
   *  Constant: '<S39>/Constant'
   *  Inport: '<Root>/GV_BrakeTorqueCommand'
   */
  rtb_Compare_d = (ADM_Integrated_Logic_U.GV_BrakeTorqueCommand >= 100.0);

  /* Delay: '<S7>/Memory' */
  rtb_Pitch_Angle = ADM_Integrated_Logic_DW.Memory_DSTATE;

  /* MATLAB Function: '<S7>/Gear_FUNCTION1' incorporates:
   *  Inport: '<Root>/GV_VCU_GearSelStat'
   *  Inport: '<Root>/GV_Vx_Fbk'
   */
  if (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 0.0) {
    if ((ADM_Integrated_Logic_U.GV_Vx_Fbk <= 0.0) && rtb_Compare_d) {
      rtb_Pitch_Angle = 0.0;
    }
  } else {
    switch ((int32_t)rtb_Pitch_Angle) {
     case 0:
      if ((ADM_Integrated_Logic_U.GV_Vx_Fbk <= 0.0) &&
          ((ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 1.0) ||
           (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 3.0) ||
           (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 2.0))) {
        rtb_Pitch_Angle = 2.0;
      }
      break;

     case 1:
      if (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 2.0) {
        rtb_Pitch_Angle = 2.0;
      }
      break;

     case 2:
      if ((ADM_Integrated_Logic_U.GV_Vx_Fbk <= 0.0) && rtb_Compare_d) {
        if (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 1.0) {
          rtb_Pitch_Angle = 1.0;
        } else if (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 3.0) {
          rtb_Pitch_Angle = 3.0;
        }
      }
      break;

     case 3:
      if (ADM_Integrated_Logic_U.GV_VCU_GearSelStat == 2.0) {
        rtb_Pitch_Angle = 2.0;
      }
      break;
    }
  }

  /* End of MATLAB Function: '<S7>/Gear_FUNCTION1' */

  /* Chart: '<S8>/Chart' incorporates:
   *  Constant: '<S8>/Constant'
   *  Constant: '<S8>/Constant1'
   *  Inport: '<Root>/GV_MCU_RPM'
   */
  if (ADM_Integrated_Logic_DW.is_active_c6_ADM_Integrated_Log == 0) {
    ADM_Integrated_Logic_DW.is_active_c6_ADM_Integrated_Log = 1U;
    ADM_Integrated_Logic_DW.is_c6_ADM_Integrated_Logic = IN_HAC_OFF;
  } else if (ADM_Integrated_Logic_DW.is_c6_ADM_Integrated_Logic == IN_HAC_OFF) {
    if (ADM_Integrated_Logic_U.GV_MCU_RPM < -50.0) {
      ADM_Integrated_Logic_DW.is_c6_ADM_Integrated_Logic = IN_HAC_ON;
    } else {
      /* Outport: '<Root>/Debug_HAC_RPM_Decision' */
      ADM_Integrated_Logic_Y.Debug_HAC_RPM_Decision = 0.0;
    }

    /* case IN_HAC_ON: */
  } else if (ADM_Integrated_Logic_U.GV_MCU_RPM > 150.0) {
    ADM_Integrated_Logic_DW.is_c6_ADM_Integrated_Logic = IN_HAC_OFF;
  } else {
    /* Outport: '<Root>/Debug_HAC_RPM_Decision' */
    ADM_Integrated_Logic_Y.Debug_HAC_RPM_Decision = 1.0;
  }

  /* End of Chart: '<S8>/Chart' */

  /* Saturate: '<S8>/Pitch_Saturation' incorporates:
   *  DiscreteIntegrator: '<S8>/Integrator_2'
   */
  if (ADM_Integrated_Logic_DW.Integrator_2_DSTATE > 8.0) {
    rtb_Pitch_Saturation = 8.0;
  } else if (ADM_Integrated_Logic_DW.Integrator_2_DSTATE < -0.0) {
    rtb_Pitch_Saturation = 0;
  } else {
    rtb_Pitch_Saturation = ADM_Integrated_Logic_DW.Integrator_2_DSTATE;
  }

  /* End of Saturate: '<S8>/Pitch_Saturation' */

  /* Delay: '<S50>/Delay' */
  if (ADM_Integrated_Logic_DW.icLoad) {
    ADM_Integrated_Logic_DW.Delay_DSTATE = rtb_Pitch_Saturation;
  }

  /* Product: '<S50>/delta rise limit' incorporates:
   *  Constant: '<S8>/Angle_Upper'
   *  SampleTimeMath: '<S50>/sample time'
   *
   * About '<S50>/sample time':
   *  y = K where K = ( w * Ts )
   *   */
  rtb_Integrator_1 = 0.002;

  /* Sum: '<S50>/Difference Inputs1' incorporates:
   *  Delay: '<S50>/Delay'
   *
   * Block description for '<S50>/Difference Inputs1':
   *
   *  Add in CPU
   */
  rtb_Pitch_Saturation -= ADM_Integrated_Logic_DW.Delay_DSTATE;

  /* Switch: '<S55>/Switch2' incorporates:
   *  RelationalOperator: '<S55>/LowerRelop1'
   */
  if (!(rtb_Pitch_Saturation > 0.002)) {
    /* Product: '<S50>/delta fall limit' incorporates:
     *  Constant: '<S8>/Angle_Down'
     *  SampleTimeMath: '<S50>/sample time'
     *
     * About '<S50>/sample time':
     *  y = K where K = ( w * Ts )
     *   */
    rtb_deltafalllimit_m = -0.002;

    /* Switch: '<S55>/Switch' incorporates:
     *  RelationalOperator: '<S55>/UpperRelop'
     */
    if (rtb_Pitch_Saturation < -0.002) {
      rtb_Integrator_1 = -0.002;
    } else {
      rtb_Integrator_1 = rtb_Pitch_Saturation;
    }

    /* End of Switch: '<S55>/Switch' */
  }

  /* End of Switch: '<S55>/Switch2' */

  /* Sum: '<S50>/Difference Inputs2' incorporates:
   *  Delay: '<S50>/Delay'
   *
   * Block description for '<S50>/Difference Inputs2':
   *
   *  Add in CPU
   */
  rtb_Pitch_Saturation = rtb_Integrator_1 + ADM_Integrated_Logic_DW.Delay_DSTATE;

  /* MATLAB Function: '<S43>/Calculate_F_c' incorporates:
   *  Gain: '<S43>/Gain'
   */
  ADM_Integrated_Lo_Calculate_F_c(ADM_Integrated_Logic_ConstB.W_value,
    0.017453292519943295 * rtb_Pitch_Saturation, &rtb_deltafalllimit_m);

  /* Gain: '<S43>/Gain2' incorporates:
   *  Constant: '<S43>/Radius'
   *  Gain: '<S43>/Gain1'
   *  Gain: '<S43>/Rolling_Gain'
   *  MATLAB Function: '<S43>/Calculate_F_R'
   *  Product: '<S43>/Multiply3'
   *  Sum: '<S43>/Required_Brake_Cal'
   */
  rtb_deltafalllimit_m = (cos(0.017453292519943295 * rtb_Pitch_Saturation) *
    436.7465753424658 * 0.0 + rtb_deltafalllimit_m) * 0.292 *
    0.083822296730930432;

  /* Saturate: '<S43>/Saturation' */
  if (rtb_deltafalllimit_m > 60.0) {
    rtb_deltafalllimit_m = 60.0;
  } else if (rtb_deltafalllimit_m < 0.0) {
    rtb_deltafalllimit_m = 0.0;
  }

  /* End of Saturate: '<S43>/Saturation' */

  /* Delay: '<S49>/Delay' */
  if (ADM_Integrated_Logic_DW.icLoad_e) {
    ADM_Integrated_Logic_DW.Delay_DSTATE_i = rtb_deltafalllimit_m;
  }

  /* Product: '<S49>/delta rise limit' incorporates:
   *  Constant: '<S8>/Upper_Torq'
   *  SampleTimeMath: '<S49>/sample time'
   *
   * About '<S49>/sample time':
   *  y = K where K = ( w * Ts )
   *   */
  rtb_Integrator_1 = 0.016;

  /* Sum: '<S49>/Difference Inputs1' incorporates:
   *  Delay: '<S49>/Delay'
   *
   * Block description for '<S49>/Difference Inputs1':
   *
   *  Add in CPU
   */
  rtb_deltafalllimit_m -= ADM_Integrated_Logic_DW.Delay_DSTATE_i;

  /* Switch: '<S54>/Switch2' incorporates:
   *  RelationalOperator: '<S54>/LowerRelop1'
   */
  if (!(rtb_deltafalllimit_m > 0.016)) {
    /* Switch: '<S54>/Switch' incorporates:
     *  RelationalOperator: '<S54>/UpperRelop'
     */
    if (rtb_deltafalllimit_m < -0.16) {
      rtb_Integrator_1 = -0.16;
    } else {
      rtb_Integrator_1 = rtb_deltafalllimit_m;
    }

    /* End of Switch: '<S54>/Switch' */
  }

  /* End of Switch: '<S54>/Switch2' */

  /* Sum: '<S49>/Difference Inputs2' incorporates:
   *  Delay: '<S49>/Delay'
   *
   * Block description for '<S49>/Difference Inputs2':
   *
   *  Add in CPU
   */
  rtb_deltafalllimit_m = rtb_Integrator_1 +
    ADM_Integrated_Logic_DW.Delay_DSTATE_i;

  /* Gain: '<S8>/Grade_GAIN' */
  rtb_deltafalllimit_a = 0.8 * rtb_deltafalllimit_m;

  /* MATLAB Function: '<S8>/HAC_OFF_OK_Func' */
  rtb_Brake_Torque_Cmd = 0.0;

  /* Outport: '<Root>/Debug_HAC_FLAG' incorporates:
   *  MATLAB Function: '<S8>/HAC_OFF_OK_Func'
   */
  ADM_Integrated_Logic_Y.Debug_HAC_FLAG = 0.0;

  /* MATLAB Function: '<S8>/HAC_OFF_OK_Func' incorporates:
   *  Constant: '<S8>/Accel_Cmd '
   *  Constant: '<S8>/Brake_Cmd'
   *  Constant: '<S8>/Gear_D'
   *  Inport: '<Root>/GV_BrakeTorqueCommand'
   *  Inport: '<Root>/GV_MCU_EstTrq'
   *  Outport: '<Root>/Debug_HAC_RPM_Decision'
   *  RelationalOperator: '<S8>/Relational Operator'
   *  RelationalOperator: '<S8>/Relational Operator1'
   *  RelationalOperator: '<S8>/Relational Operator2'
   *  Sum: '<S8>/HAC_Flags_Add'
   */
  if ((double)(((ADM_Integrated_Logic_U.GV_BrakeTorqueCommand <= 20.0) +
                (rtb_Vx_Cmd_R <= 2.0)) + (rtb_Pitch_Angle == 3.0)) +
      ADM_Integrated_Logic_Y.Debug_HAC_RPM_Decision >= 4.0) {
    if (ADM_Integrated_Logic_DW.HAC_ON_FLAG == 0.0) {
      ADM_Integrated_Logic_DW.HAC_ON_Timer = 0.0;
    }

    ADM_Integrated_Logic_DW.HAC_ON_FLAG = 1.0;
    rtb_Brake_Torque_Cmd = 1000.0;
    ADM_Integrated_Logic_DW.Smoothed_Torque = 1000.0;
    if (ADM_Integrated_Logic_DW.HAC_ON_Timer < 3.0) {
      ADM_Integrated_Logic_DW.HAC_Desired_Torque = rtb_deltafalllimit_a;
      ADM_Integrated_Logic_DW.HAC_ON_Timer += 0.005;
    }

    /* Outport: '<Root>/Debug_HAC_FLAG' */
    ADM_Integrated_Logic_Y.Debug_HAC_FLAG = 1.0;
  } else if (ADM_Integrated_Logic_DW.HAC_ON_FLAG == 1.0) {
    if (ADM_Integrated_Logic_U.GV_MCU_EstTrq >=
        ADM_Integrated_Logic_DW.HAC_Desired_Torque) {
      ADM_Integrated_Logic_DW.Smoothed_Torque -= 0.05 *
        ADM_Integrated_Logic_DW.Smoothed_Torque;
      if (ADM_Integrated_Logic_DW.Smoothed_Torque < 0.01) {
        ADM_Integrated_Logic_DW.Smoothed_Torque = 0.0;
        ADM_Integrated_Logic_DW.HAC_ON_FLAG = 0.0;
        ADM_Integrated_Logic_DW.HAC_Desired_Torque = 0.0;
        ADM_Integrated_Logic_DW.HAC_ON_Timer = 0.0;
      }

      rtb_Brake_Torque_Cmd = ADM_Integrated_Logic_DW.Smoothed_Torque;
    } else {
      rtb_Brake_Torque_Cmd = 1000.0;
      ADM_Integrated_Logic_DW.Smoothed_Torque = 1000.0;

      /* Outport: '<Root>/Debug_HAC_FLAG' */
      ADM_Integrated_Logic_Y.Debug_HAC_FLAG = 1.0;
    }
  }

  /* Gain: '<S4>/Brake_GAIN' incorporates:
   *  DiscreteTransferFcn: '<S1>/Discrete Transfer Fcn'
   */
  rtb_y_k = 0.0625 * ADM_Integrated_Logic_DW.DiscreteTransferFcn_states * -80.0;

  /* MATLAB Function: '<S4>/GearCondition_Brake' */
  if (rtb_Pitch_Angle == 1.0) {
    tmp = -1;
  } else {
    tmp = (rtb_Pitch_Angle == 3.0);
  }

  /* Saturate: '<S4>/Saturation' */
  if (rtb_y_k > 1000.0) {
    rtb_y_k = 1000.0;
  } else if (rtb_y_k < 0.0) {
    rtb_y_k = 0.0;
  }

  /* Product: '<S4>/Multiply2' incorporates:
   *  MATLAB Function: '<S4>/GearCondition_Brake'
   *  Saturate: '<S4>/Saturation'
   */
  rtb_Integrator_1 = (double)tmp * rtb_y_k;

  /* RateLimiter: '<S4>/Brake_Out_RateLimiter' */
  rtb_TargetSpd_RateLimiter = rtb_Integrator_1 - ADM_Integrated_Logic_DW.PrevY_o;
  if (rtb_TargetSpd_RateLimiter > 3.0) {
    rtb_Integrator_1 = ADM_Integrated_Logic_DW.PrevY_o + 3.0;
  } else if (rtb_TargetSpd_RateLimiter < -3.0) {
    rtb_Integrator_1 = ADM_Integrated_Logic_DW.PrevY_o - 3.0;
  }

  ADM_Integrated_Logic_DW.PrevY_o = rtb_Integrator_1;

  /* End of RateLimiter: '<S4>/Brake_Out_RateLimiter' */

  /* Saturate: '<S4>/Brake_Saturation' */
  if (rtb_Integrator_1 > 1000.0) {
    rtb_Integrator_1 = 1000.0;
  } else if (rtb_Integrator_1 < 0.0) {
    rtb_Integrator_1 = 0.0;
  }

  /* End of Saturate: '<S4>/Brake_Saturation' */

  /* MATLAB Function: '<S1>/Emergency_Brake_Func' incorporates:
   *  Inport: '<Root>/GV_Vx_Fbk'
   *  Sum: '<S1>/Add'
   */
  if (rtb_Compare) {
    rtb_Brake_Saturation = ADM_Integrated_Logic_U.GV_Vx_Fbk * 100.0;
  } else {
    rtb_Brake_Saturation = rtb_Brake_Torque_Cmd + rtb_Integrator_1;
  }

  /* Saturate: '<S1>/Brake_Saturation' incorporates:
   *  MATLAB Function: '<S1>/Emergency_Brake_Func'
   */
  if (rtb_Brake_Saturation > 2500.0) {
    rtb_Brake_Saturation = 2500.0;
  } else if (rtb_Brake_Saturation < 0.0) {
    rtb_Brake_Saturation = 0.0;
  }

  /* End of Saturate: '<S1>/Brake_Saturation' */

  /* Outport: '<Root>/GV_Brake_Command' incorporates:
   *  MATLAB Function: '<S1>/IDB_Fault_Injection'
   */
  ADM_Integrated_Logic_Y.GV_Brake_Command = rtb_Brake_Saturation;

  /* Outport: '<Root>/Target_IDB_Out' incorporates:
   *  MATLAB Function: '<S1>/IDB_Fault_Injection'
   */
  ADM_Integrated_Logic_Y.Target_IDB_Out = rtb_Brake_Saturation;

  /* Outport: '<Root>/Debug_CC_Brake_Output' */
  ADM_Integrated_Logic_Y.Debug_CC_Brake_Output = rtb_Integrator_1;

  /* Outport: '<Root>/Debug_HAC_Brake_Output' */
  ADM_Integrated_Logic_Y.Debug_HAC_Brake_Output = rtb_Brake_Torque_Cmd;

  /* Outport: '<Root>/GV_Hill_Torque_Assist' */
  ADM_Integrated_Logic_Y.GV_Hill_Torque_Assist = rtb_deltafalllimit_a;

  /* Outport: '<Root>/Debug_HAC_Pitch_angle' */
  ADM_Integrated_Logic_Y.Debug_HAC_Pitch_angle = rtb_Pitch_Saturation;

  /* MATLAB Function: '<S43>/Calculate_F_c1' incorporates:
   *  Gain: '<S43>/Gain3'
   */
  ADM_Integrated_Lo_Calculate_F_c(ADM_Integrated_Logic_ConstB.W_Value_for_Brake,
    0.017453292519943295 * rtb_Pitch_Saturation, &rtb_deltafalllimit_a);

  /* Product: '<S44>/Product1' incorporates:
   *  Constant: '<S44>/Constant'
   *  Gain: '<S44>/gain'
   *  Inport: '<Root>/GV_IMU_AX_Val'
   *  Product: '<S44>/Product11'
   *  Sum: '<S44>/Sum1'
   *  Sum: '<S44>/Sum2'
   *  Sum: '<S44>/Sum3'
   *  Sum: '<S44>/Sum4'
   *  UnitDelay: '<S44>/d'
   *  UnitDelay: '<S44>/d1'
   */
  rtb_deltafalllimit_a = ((ADM_Integrated_Logic_U.GV_IMU_AX_Val +
    ADM_Integrated_Logic_DW.d1_DSTATE) * 0.002 + 0.061661977236758134 *
    ADM_Integrated_Logic_DW.d_DSTATE) / 0.065661977236758137;

  /* Product: '<S45>/Product1' incorporates:
   *  Constant: '<S45>/Constant'
   *  Gain: '<S45>/gain'
   *  Inport: '<Root>/GV_IMU_AY_Val'
   *  Product: '<S45>/Product11'
   *  Sum: '<S45>/Sum1'
   *  Sum: '<S45>/Sum2'
   *  Sum: '<S45>/Sum3'
   *  Sum: '<S45>/Sum4'
   *  UnitDelay: '<S45>/d'
   *  UnitDelay: '<S45>/d1'
   */
  rtb_Brake_Torque_Cmd = ((ADM_Integrated_Logic_U.GV_IMU_AY_Val +
    ADM_Integrated_Logic_DW.d1_DSTATE_i) * 0.002 + 0.061661977236758134 *
    ADM_Integrated_Logic_DW.d_DSTATE_p) / 0.065661977236758137;

  /* Product: '<S46>/Product1' incorporates:
   *  Constant: '<S46>/Constant'
   *  Gain: '<S46>/gain'
   *  Inport: '<Root>/GV_IMU_AZ_Val'
   *  Product: '<S46>/Product11'
   *  Sum: '<S46>/Sum1'
   *  Sum: '<S46>/Sum2'
   *  Sum: '<S46>/Sum3'
   *  Sum: '<S46>/Sum4'
   *  UnitDelay: '<S46>/d'
   *  UnitDelay: '<S46>/d1'
   */
  rtb_Integrator_1 = ((ADM_Integrated_Logic_U.GV_IMU_AZ_Val +
                       ADM_Integrated_Logic_DW.d1_DSTATE_o) * 0.002 +
                      0.061661977236758134 * ADM_Integrated_Logic_DW.d_DSTATE_n)
    / 0.065661977236758137;

  /* MATLAB Function: '<S8>/Pitch_calculate' */
  rtb_Brake_Saturation = sqrt(rtb_Brake_Torque_Cmd * rtb_Brake_Torque_Cmd +
    rtb_Integrator_1 * rtb_Integrator_1);
  if (!(rtb_Brake_Saturation == 0.0)) {
    rtb_Brake_Saturation = atan(rtb_deltafalllimit_a / rtb_Brake_Saturation);
  }

  /* Sum: '<S8>/Sum' incorporates:
   *  DiscreteIntegrator: '<S8>/Integrator_2'
   *  MATLAB Function: '<S8>/Pitch_calculate'
   */
  rtb_Brake_Saturation = ADM_Integrated_Logic_DW.Integrator_2_DSTATE -
    rtb_Brake_Saturation * 57.295779513082323;

  /* Product: '<S47>/Product1' incorporates:
   *  Constant: '<S47>/Constant'
   *  Gain: '<S47>/gain'
   *  Inport: '<Root>/GV_IMU_PitchRtVal'
   *  Product: '<S47>/Product11'
   *  Sum: '<S47>/Sum1'
   *  Sum: '<S47>/Sum2'
   *  Sum: '<S47>/Sum3'
   *  Sum: '<S47>/Sum4'
   *  UnitDelay: '<S47>/d'
   *  UnitDelay: '<S47>/d1'
   */
  rtb_Product1_m = ((ADM_Integrated_Logic_U.GV_IMU_PitchRtVal +
                     ADM_Integrated_Logic_DW.d1_DSTATE_a) * 0.002 +
                    0.061661977236758134 * ADM_Integrated_Logic_DW.d_DSTATE_d) /
    0.065661977236758137;

  /* MATLAB Function: '<S4>/Target_RPM' */
  if (rtb_Pitch_Angle == 0.0) {
    tmp = 0;
  } else if (rtb_Pitch_Angle == 2.0) {
    tmp = 0;
  } else if (rtb_Pitch_Angle == 1.0) {
    tmp = -1;
  } else {
    tmp = (rtb_Pitch_Angle == 3.0);
  }

  rtb_Target_RPM = rtb_Vx_Cmd_R * 1000.0 / 3600.0 * 11.93 * 60.0 /
    1.7013672006633955 * (double)tmp;

  /* End of MATLAB Function: '<S4>/Target_RPM' */

  /* RateLimiter: '<S4>/TargetSpd_RateLimiter' */
  rtb_TargetSpd_RateLimiter = rtb_Target_RPM - ADM_Integrated_Logic_DW.PrevY_a;
  if (rtb_TargetSpd_RateLimiter > 0.4) {
    rtb_TargetSpd_RateLimiter = ADM_Integrated_Logic_DW.PrevY_a + 0.4;
  } else if (rtb_TargetSpd_RateLimiter < -0.8) {
    rtb_TargetSpd_RateLimiter = ADM_Integrated_Logic_DW.PrevY_a - 0.8;
  } else {
    rtb_TargetSpd_RateLimiter = rtb_Target_RPM;
  }

  ADM_Integrated_Logic_DW.PrevY_a = rtb_TargetSpd_RateLimiter;

  /* End of RateLimiter: '<S4>/TargetSpd_RateLimiter' */

  /* Product: '<S24>/Product1' incorporates:
   *  Constant: '<S24>/Constant'
   *  Gain: '<S24>/gain'
   *  Product: '<S24>/Product11'
   *  Sum: '<S24>/Sum1'
   *  Sum: '<S24>/Sum2'
   *  Sum: '<S24>/Sum3'
   *  Sum: '<S24>/Sum4'
   *  UnitDelay: '<S24>/d'
   *  UnitDelay: '<S24>/d1'
   */
  rtb_Target_RPM = ((rtb_TargetSpd_RateLimiter +
                     ADM_Integrated_Logic_DW.d1_DSTATE_c) * 0.002 +
                    0.1041032953945969 * ADM_Integrated_Logic_DW.d_DSTATE_l) /
    0.1081032953945969;

  /* Sum: '<S34>/Sum1' incorporates:
   *  Gain: '<S34>/gain'
   *  Sum: '<S34>/Sum2'
   *  UnitDelay: '<S34>/d'
   *  UnitDelay: '<S34>/d1'
   */
  rtb_Sum1_i2 = (rtb_Target_RPM - ADM_Integrated_Logic_DW.d_DSTATE_i) * 1000.0 -
    ADM_Integrated_Logic_DW.d1_DSTATE_p;

  /* Sum: '<S35>/Sum1' incorporates:
   *  Gain: '<S35>/gain'
   *  Sum: '<S35>/Sum2'
   *  UnitDelay: '<S35>/d'
   *  UnitDelay: '<S35>/d1'
   */
  rtb_Sum1_o1 = (rtb_Sum1_i2 - ADM_Integrated_Logic_DW.d_DSTATE_c) * 1000.0 -
    ADM_Integrated_Logic_DW.d1_DSTATE_h;

  /* Sum: '<S36>/Sum1' incorporates:
   *  Gain: '<S36>/gain'
   *  Sum: '<S36>/Sum2'
   *  UnitDelay: '<S36>/d'
   *  UnitDelay: '<S36>/d1'
   */
  rtb_Sum1_lm = (rtb_Sum1_o1 - ADM_Integrated_Logic_DW.d_DSTATE_db) * 1000.0 -
    ADM_Integrated_Logic_DW.d1_DSTATE_l;

  /* Gain: '<S32>/Gain' incorporates:
   *  Constant: '<S32>/Constant3'
   *  Constant: '<S32>/Constant4'
   *  Constant: '<S32>/Constant5'
   *  Product: '<S32>/Product'
   *  Product: '<S32>/Product1'
   *  Product: '<S32>/Product2'
   *  Sum: '<S32>/Add5'
   */
  rtb_Gain_c = (((156.8 * rtb_Target_RPM + 212.8 * rtb_Sum1_i2) + 21.8 *
                 rtb_Sum1_o1) + rtb_Sum1_lm) * 9.44822373393802E-6;

  /* Product: '<S38>/Product1' incorporates:
   *  Constant: '<S38>/Constant1'
   *  Constant: '<S38>/Constant2'
   *  Delay: '<S38>/Delay'
   *  Delay: '<S38>/Delay1'
   *  Delay: '<S38>/Delay2'
   *  Delay: '<S38>/Delay3'
   *  Gain: '<S38>/gain1'
   *  Gain: '<S38>/gain3'
   *  Product: '<S38>/x(n), x(n-1), x(n-2)'
   *  Product: '<S38>/y(n-1)'
   *  Product: '<S38>/y(n-2)'
   *  Sum: '<S38>/Sum1'
   *  Sum: '<S38>/Sum2'
   *  Sum: '<S38>/Sum3'
   *  Sum: '<S38>/Sum4'
   *  Sum: '<S38>/Sum5'
   *  Sum: '<S38>/Sum6'
   */
  rtb_Product1_j = ((((2.0 * ADM_Integrated_Logic_DW.Delay1_DSTATE + rtb_Gain_c)
                      + ADM_Integrated_Logic_DW.Delay_DSTATE_c[0]) *
                     0.39478417604357435 - -7.2104316479128512 *
                     ADM_Integrated_Logic_DW.Delay2_DSTATE) - 2.6178993711731877
                    * ADM_Integrated_Logic_DW.Delay3_DSTATE[0]) /
    6.1716689809139611;

  /* Product: '<S37>/Product1' incorporates:
   *  Constant: '<S37>/Constant'
   *  Gain: '<S37>/gain'
   *  Product: '<S37>/Product11'
   *  Sum: '<S37>/Sum1'
   *  Sum: '<S37>/Sum2'
   *  Sum: '<S37>/Sum3'
   *  Sum: '<S37>/Sum4'
   *  UnitDelay: '<S37>/d'
   *  UnitDelay: '<S37>/d1'
   */
  rtb_Product1_ee = ((rtb_Product1_j + ADM_Integrated_Logic_DW.d1_DSTATE_e) *
                     0.002 + 0.00861032953945969 *
                     ADM_Integrated_Logic_DW.d_DSTATE_ij) / 0.01261032953945969;

  /* Sum: '<S4>/Subtract' incorporates:
   *  Inport: '<Root>/GV_MCU_RPM'
   *  MultiPortSwitch: '<S31>/Multiport Switch1'
   */
  rtb_Error_m = rtb_Target_RPM - ADM_Integrated_Logic_U.GV_MCU_RPM;

  /* Saturate: '<S4>/Error_Saturation' incorporates:
   *  MultiPortSwitch: '<S31>/Multiport Switch1'
   */
  if (rtb_Error_m > 2000.0) {
    rtb_Error_m = 2000.0;
  } else if (rtb_Error_m < -2000.0) {
    rtb_Error_m = -2000.0;
  }

  /* End of Saturate: '<S4>/Error_Saturation' */

  /* DeadZone: '<S21>/Dead Zone' incorporates:
   *  MultiPortSwitch: '<S31>/Multiport Switch1'
   */
  if (rtb_Error_m > 50.0) {
    rtb_Add_e = rtb_Error_m - 50.0;
  } else if (rtb_Error_m >= -50.0) {
    rtb_Add_e = 0.0;
  } else {
    rtb_Add_e = rtb_Error_m - -50.0;
  }

  /* Sum: '<S26>/Sum1' incorporates:
   *  Gain: '<S26>/gain'
   *  Sum: '<S26>/Sum2'
   *  UnitDelay: '<S26>/d'
   *  UnitDelay: '<S26>/d1'
   */
  rtb_Error_m = (rtb_Target_RPM - ADM_Integrated_Logic_DW.d_DSTATE_ir) * 1000.0
    - ADM_Integrated_Logic_DW.d1_DSTATE_of;

  /* Sum: '<S27>/Sum1' incorporates:
   *  Gain: '<S27>/gain'
   *  Sum: '<S27>/Sum2'
   *  UnitDelay: '<S27>/d'
   *  UnitDelay: '<S27>/d1'
   */
  rtb_Sum1_aj = (rtb_Error_m - ADM_Integrated_Logic_DW.d_DSTATE_m) * 1000.0 -
    ADM_Integrated_Logic_DW.d1_DSTATE_hm;

  /* Sum: '<S28>/Sum1' incorporates:
   *  Gain: '<S28>/gain'
   *  Sum: '<S28>/Sum2'
   *  UnitDelay: '<S28>/d'
   *  UnitDelay: '<S28>/d1'
   */
  rtb_Sum1_p = (rtb_Sum1_aj - ADM_Integrated_Logic_DW.d_DSTATE_mw) * 1000.0 -
    ADM_Integrated_Logic_DW.d1_DSTATE_g;

  /* Sum: '<S19>/Add3' incorporates:
   *  Constant: '<S19>/Constant3'
   *  Constant: '<S19>/Constant4'
   *  Constant: '<S19>/Constant5'
   *  Gain: '<S19>/Gain'
   *  Memory: '<S4>/Memory'
   *  Product: '<S19>/Product2'
   *  Product: '<S19>/Product3'
   *  Product: '<S19>/Product4'
   *  Sum: '<S19>/Add2'
   */
  rtb_Add3 = (((156.8 * rtb_Target_RPM + 212.8 * rtb_Error_m) + 21.8 *
               rtb_Sum1_aj) + rtb_Sum1_p) * 9.44822373393802E-6 -
    ADM_Integrated_Logic_DW.Memory_PreviousInput;

  /* Product: '<S29>/Product1' incorporates:
   *  Constant: '<S29>/Constant'
   *  Gain: '<S29>/gain'
   *  Product: '<S29>/Product11'
   *  Sum: '<S29>/Sum1'
   *  Sum: '<S29>/Sum2'
   *  Sum: '<S29>/Sum3'
   *  Sum: '<S29>/Sum4'
   *  UnitDelay: '<S29>/d'
   *  UnitDelay: '<S29>/d1'
   */
  rtb_Product1_h = ((rtb_Add3 + ADM_Integrated_Logic_DW.d1_DSTATE_ej) * 0.002 +
                    0.029830988618379066 * ADM_Integrated_Logic_DW.d_DSTATE_j) /
    0.03383098861837907;

  /* Product: '<S30>/Product1' incorporates:
   *  Constant: '<S30>/Constant1'
   *  Constant: '<S30>/Constant2'
   *  Delay: '<S30>/Delay'
   *  Delay: '<S30>/Delay1'
   *  Delay: '<S30>/Delay2'
   *  Delay: '<S30>/Delay3'
   *  Gain: '<S30>/gain1'
   *  Gain: '<S30>/gain3'
   *  Product: '<S30>/x(n), x(n-1), x(n-2)'
   *  Product: '<S30>/y(n-1)'
   *  Product: '<S30>/y(n-2)'
   *  Sum: '<S30>/Sum1'
   *  Sum: '<S30>/Sum2'
   *  Sum: '<S30>/Sum3'
   *  Sum: '<S30>/Sum4'
   *  Sum: '<S30>/Sum5'
   *  Sum: '<S30>/Sum6'
   */
  rtb_Product1_kq = ((((2.0 * ADM_Integrated_Logic_DW.Delay1_DSTATE_c +
                        rtb_Product1_h) +
                       ADM_Integrated_Logic_DW.Delay_DSTATE_p[0]) *
                      0.00035530575843921691 - -7.9992893884831213 *
                      ADM_Integrated_Logic_DW.Delay2_DSTATE_n) -
                     3.9470487616123275 *
                     ADM_Integrated_Logic_DW.Delay3_DSTATE_h[0]) /
    4.0536618499045511;

  /* MATLAB Function: '<S4>/DOB_Gain' incorporates:
   *  Inport: '<Root>/GV_Vx_Fbk'
   */
  if (ADM_Integrated_Logic_U.GV_Vx_Fbk < 5.0) {
    rtb_Switch2 = 0.0;
  } else {
    rtb_Switch2 = (ADM_Integrated_Logic_U.GV_Vx_Fbk - 5.0) * 0.2;
  }

  if (rtb_Switch2 >= 1.0) {
    rtb_Switch2 = 1.0;
  }

  /* End of MATLAB Function: '<S4>/DOB_Gain' */

  /* Product: '<S4>/Product1' incorporates:
   *  Constant: '<S4>/DOBFlag'
   *  Product: '<S4>/Product'
   */
  rtb_y_k = -(rtb_Product1_kq * 0.9);

  /* Saturate: '<S4>/DOB_Saturation' */
  if (rtb_y_k > 30.0) {
    rtb_y_k = 30.0;
  } else if (rtb_y_k < -30.0) {
    rtb_y_k = -30.0;
  }

  /* Sum: '<S4>/Subtract2' incorporates:
   *  DeadZone: '<S21>/Dead Zone'
   *  MultiPortSwitch: '<S31>/Multiport Switch1'
   *  Product: '<S33>/Product'
   *  Product: '<S4>/Multiply1'
   *  Saturate: '<S4>/DOB_Saturation'
   *  Sum: '<S21>/Add'
   */
  rtb_Add_e = (rtb_Add_e * 0.044648264844923756 + rtb_Product1_ee) + rtb_y_k *
    rtb_Switch2;

  /* Saturate: '<S4>/Torq_Saturation' */
  if (rtb_Add_e > 80.0) {
    rtb_Add_e = 80.0;
  } else if (rtb_Add_e < -80.0) {
    rtb_Add_e = -80.0;
  }

  /* End of Saturate: '<S4>/Torq_Saturation' */

  /* MATLAB Function: '<S1>/Emergency_Motor_Func' incorporates:
   *  Inport: '<Root>/GV_IDB_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_RCU_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_Vx_Fbk'
   *  MATLAB Function: '<S4>/Gear_pos_out'
   *  Product: '<S4>/Multiply'
   */
  if (rtb_Compare) {
    if ((ADM_Integrated_Logic_U.GV_IDB_ECU_Fault_Flag == 1.0) &&
        (ADM_Integrated_Logic_U.GV_RCU_ECU_Fault_Flag == 1.0)) {
      if (ADM_Integrated_Logic_U.GV_Vx_Fbk / 3.6 > 0.5) {
        rtb_Switch2 = -80.0;
      } else {
        rtb_Switch2 = 0.0;
      }
    } else {
      rtb_Switch2 = 0.0;
    }
  } else {
    if (rtb_Pitch_Angle == 0.0) {
      /* MATLAB Function: '<S4>/Gear_pos_out' */
      tmp = 0;
    } else if (rtb_Pitch_Angle == 2.0) {
      /* MATLAB Function: '<S4>/Gear_pos_out' */
      tmp = 0;
    } else if (rtb_Pitch_Angle == 1.0) {
      /* MATLAB Function: '<S4>/Gear_pos_out' */
      tmp = -1;
    } else {
      /* MATLAB Function: '<S4>/Gear_pos_out' */
      tmp = (rtb_Pitch_Angle == 3.0);
    }

    rtb_Switch2 = (double)tmp * rtb_Add_e;
  }

  /* End of MATLAB Function: '<S1>/Emergency_Motor_Func' */

  /* MATLAB Function: '<S1>/MCU_Fault_Injection' incorporates:
   *  Inport: '<Root>/GV_MCU_Actuator_Fault_Flag'
   */
  if (ADM_Integrated_Logic_U.GV_MCU_Actuator_Fault_Flag == 1.0) {
    /* Outport: '<Root>/GV_Motor_Torque_Cmd' */
    ADM_Integrated_Logic_Y.GV_Motor_Torque_Cmd = 0.0;
  } else {
    /* Outport: '<Root>/GV_Motor_Torque_Cmd' */
    ADM_Integrated_Logic_Y.GV_Motor_Torque_Cmd = rtb_Switch2;
  }

  /* Outport: '<Root>/Target_MCU_Out' incorporates:
   *  MATLAB Function: '<S1>/MCU_Fault_Injection'
   */
  ADM_Integrated_Logic_Y.Target_MCU_Out = rtb_Switch2;

  /* Outport: '<Root>/GV_Gear_Postion_Out' */
  ADM_Integrated_Logic_Y.GV_Gear_Postion_Out = rtb_Pitch_Angle;

  /* Sum: '<S1>/Add2' incorporates:
   *  Inport: '<Root>/GV_Vx_Fbk'
   */
  rtb_Vx_Cmd_R -= ADM_Integrated_Logic_U.GV_Vx_Fbk;

  /* Sum: '<S1>/Add1' incorporates:
   *  Constant: '<S1>/Constant'
   *  Gain: '<S1>/Gain1'
   *  Inport: '<Root>/GV_Vx_Fbk'
   *  Sum: '<S1>/Add3'
   */
  rtb_y_e_tmp = 400.0 - 6.5 * ADM_Integrated_Logic_U.GV_Vx_Fbk;
  rtb_y_k = rtb_y_e_tmp;

  /* MATLAB Function: '<S1>/MATLAB Function1' incorporates:
   *  Sum: '<S1>/Add1'
   */
  ADM_Integrated__MATLABFunction1(rtb_y_e_tmp, &rtb_y);

  /* Product: '<S16>/delta rise limit' incorporates:
   *  SampleTimeMath: '<S16>/sample time'
   *
   * About '<S16>/sample time':
   *  y = K where K = ( w * Ts )
   *   */
  rtb_Switch2 = rtb_y * 0.002;

  /* Delay: '<S16>/Delay' incorporates:
   *  Inport: '<Root>/GV_RWA_RackAngleCommand'
   */
  if (ADM_Integrated_Logic_DW.icLoad_l) {
    ADM_Integrated_Logic_DW.Delay_DSTATE_c4 =
      ADM_Integrated_Logic_U.GV_RWA_RackAngleCommand;
  }

  /* Sum: '<S16>/Difference Inputs1' incorporates:
   *  Delay: '<S16>/Delay'
   *  Inport: '<Root>/GV_RWA_RackAngleCommand'
   *
   * Block description for '<S16>/Difference Inputs1':
   *
   *  Add in CPU
   */
  rtb_UkYk1_j = ADM_Integrated_Logic_U.GV_RWA_RackAngleCommand -
    ADM_Integrated_Logic_DW.Delay_DSTATE_c4;

  /* MATLAB Function: '<S1>/MATLAB Function2' incorporates:
   *  Gain: '<S1>/Gain3'
   *  Sum: '<S1>/Add1'
   */
  ADM_Integrated__MATLABFunction2(-rtb_y_e_tmp, &rtb_y);

  /* Switch: '<S56>/Switch2' incorporates:
   *  RelationalOperator: '<S56>/LowerRelop1'
   */
  if (!(rtb_UkYk1_j > rtb_Switch2)) {
    /* Product: '<S16>/delta fall limit' incorporates:
     *  SampleTimeMath: '<S16>/sample time'
     *
     * About '<S16>/sample time':
     *  y = K where K = ( w * Ts )
     *   */
    rtb_Switch2 = 0.002 * rtb_y;

    /* Switch: '<S56>/Switch' incorporates:
     *  RelationalOperator: '<S56>/UpperRelop'
     */
    if (!(rtb_UkYk1_j < rtb_Switch2)) {
      rtb_Switch2 = rtb_UkYk1_j;
    }

    /* End of Switch: '<S56>/Switch' */
  }

  /* End of Switch: '<S56>/Switch2' */

  /* Sum: '<S16>/Difference Inputs2' incorporates:
   *  Delay: '<S16>/Delay'
   *
   * Block description for '<S16>/Difference Inputs2':
   *
   *  Add in CPU
   */
  rtb_UkYk1_j = rtb_Switch2 + ADM_Integrated_Logic_DW.Delay_DSTATE_c4;

  /* Outport: '<Root>/GV_Master_Rack_Angle_Cmd' incorporates:
   *  MATLAB Function: '<S1>/RWA_Actuator_Fault_Injection'
   */
  ADM_Integrated_Logic_Y.GV_Master_Rack_Angle_Cmd = rtb_UkYk1_j;

  /* Outport: '<Root>/Target_RWA_Out' incorporates:
   *  MATLAB Function: '<S1>/RWA_Actuator_Fault_Injection'
   */
  ADM_Integrated_Logic_Y.Target_RWA_Out = rtb_UkYk1_j;

  /* MATLAB Function: '<S1>/MATLAB Function5' */
  ADM_Integrated__MATLABFunction1(rtb_y_e_tmp, &rtb_Switch2);

  /* Product: '<S17>/delta rise limit' incorporates:
   *  SampleTimeMath: '<S17>/sample time'
   *
   * About '<S17>/sample time':
   *  y = K where K = ( w * Ts )
   *   */
  rtb_Switch2 *= 0.002;

  /* Delay: '<S17>/Delay' incorporates:
   *  Inport: '<Root>/GV_RWS_RackAngleCommand'
   */
  if (ADM_Integrated_Logic_DW.icLoad_d) {
    ADM_Integrated_Logic_DW.Delay_DSTATE_i1 =
      ADM_Integrated_Logic_U.GV_RWS_RackAngleCommand;
  }

  /* Sum: '<S17>/Difference Inputs1' incorporates:
   *  Delay: '<S17>/Delay'
   *  Inport: '<Root>/GV_RWS_RackAngleCommand'
   *
   * Block description for '<S17>/Difference Inputs1':
   *
   *  Add in CPU
   */
  rtb_y = ADM_Integrated_Logic_U.GV_RWS_RackAngleCommand -
    ADM_Integrated_Logic_DW.Delay_DSTATE_i1;

  /* MATLAB Function: '<S1>/MATLAB Function6' incorporates:
   *  Gain: '<S1>/Gain5'
   */
  ADM_Integrated__MATLABFunction2(-rtb_y_e_tmp, &rtb_y_k);

  /* Switch: '<S57>/Switch2' incorporates:
   *  RelationalOperator: '<S57>/LowerRelop1'
   */
  if (!(rtb_y > rtb_Switch2)) {
    /* Product: '<S17>/delta fall limit' incorporates:
     *  SampleTimeMath: '<S17>/sample time'
     *
     * About '<S17>/sample time':
     *  y = K where K = ( w * Ts )
     *   */
    rtb_Switch2 = 0.002 * rtb_y_k;

    /* Switch: '<S57>/Switch' incorporates:
     *  RelationalOperator: '<S57>/UpperRelop'
     */
    if (!(rtb_y < rtb_Switch2)) {
      rtb_Switch2 = rtb_y;
    }

    /* End of Switch: '<S57>/Switch' */
  }

  /* End of Switch: '<S57>/Switch2' */

  /* Sum: '<S17>/Difference Inputs2' incorporates:
   *  Delay: '<S17>/Delay'
   *
   * Block description for '<S17>/Difference Inputs2':
   *
   *  Add in CPU
   */
  rtb_Switch2 += ADM_Integrated_Logic_DW.Delay_DSTATE_i1;

  /* Outport: '<Root>/GV_RWS_RackAngleCmd1' */
  ADM_Integrated_Logic_Y.GV_RWS_RackAngleCmd1 = rtb_Switch2;

  /* Outport: '<Root>/Act_Fault_Exist' incorporates:
   *  MATLAB Function: '<S1>/Actuator_Fault_Decision'
   */
  ADM_Integrated_Logic_Y.Act_Fault_Exist = 0.0;

  /* MATLAB Function: '<S1>/Actuator_Fault_Decision' incorporates:
   *  Inport: '<Root>/GV_ACU_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_ACU_ECU_Fault_Flag1'
   *  Inport: '<Root>/GV_ACU_ECU_Fault_Flag2'
   *  Inport: '<Root>/GV_ACU_ECU_Fault_Flag3'
   *  Inport: '<Root>/GV_ACU_Fault_Flag'
   *  Inport: '<Root>/GV_Drive_Mode'
   *  Inport: '<Root>/GV_IDB_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_MCU_Actuator_Fault_Flag'
   *  Inport: '<Root>/GV_RCU_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_RWA1_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_RWA2_ECU_Fault_Flag'
   *  Inport: '<Root>/GV_RWA_Actuator_Fault'
   */
  if ((ADM_Integrated_Logic_U.GV_ACU_Fault_Flag == 1.0) ||
      (ADM_Integrated_Logic_U.GV_MCU_Actuator_Fault_Flag == 1.0) ||
      (ADM_Integrated_Logic_U.GV_RWA_Actuator_Fault == 1.0)) {
    /* Outport: '<Root>/Act_Fault_Exist' */
    ADM_Integrated_Logic_Y.Act_Fault_Exist = 1.0;
  }

  if (((ADM_Integrated_Logic_U.GV_ACU_ECU_Fault_Flag == 1.0) ||
       (ADM_Integrated_Logic_U.GV_ACU_ECU_Fault_Flag1 == 1.0) ||
       (ADM_Integrated_Logic_U.GV_ACU_ECU_Fault_Flag2 == 1.0) ||
       (ADM_Integrated_Logic_U.GV_ACU_ECU_Fault_Flag3 == 1.0)) &&
      ((ADM_Integrated_Logic_U.GV_Drive_Mode == 0.0) ||
       (ADM_Integrated_Logic_U.GV_Drive_Mode == 2.0))) {
    /* Outport: '<Root>/Act_Fault_Exist' */
    ADM_Integrated_Logic_Y.Act_Fault_Exist = 1.0;
  }

  if ((ADM_Integrated_Logic_U.GV_IDB_ECU_Fault_Flag == 1.0) ||
      (ADM_Integrated_Logic_U.GV_RCU_ECU_Fault_Flag == 1.0)) {
    /* Outport: '<Root>/Act_Fault_Exist' */
    ADM_Integrated_Logic_Y.Act_Fault_Exist = 1.0;
  } else if ((ADM_Integrated_Logic_U.GV_RWA1_ECU_Fault_Flag == 1.0) &&
             (ADM_Integrated_Logic_U.GV_RWA2_ECU_Fault_Flag == 1.0)) {
    /* Outport: '<Root>/Act_Fault_Exist' */
    ADM_Integrated_Logic_Y.Act_Fault_Exist = 1.0;
  }

  /* Update for Delay: '<S7>/Memory' */
  ADM_Integrated_Logic_DW.Memory_DSTATE = rtb_Pitch_Angle;

  /* Update for DiscreteIntegrator: '<S8>/Integrator_2' incorporates:
   *  Constant: '<S8>/I_gain'
   *  Constant: '<S8>/P_gain'
   *  DiscreteIntegrator: '<S8>/Integrator_1'
   *  Product: '<S8>/Product'
   *  Product: '<S8>/Product1'
   *  Sum: '<S8>/Sum1'
   *  Sum: '<S8>/Sum2'
   */
  ADM_Integrated_Logic_DW.Integrator_2_DSTATE += (rtb_Product1_m -
    (ADM_Integrated_Logic_DW.Integrator_1_DSTATE * 5.0 + rtb_Brake_Saturation *
     100.0)) * 0.002;

  /* Update for Delay: '<S50>/Delay' */
  ADM_Integrated_Logic_DW.icLoad = false;
  ADM_Integrated_Logic_DW.Delay_DSTATE = rtb_Pitch_Saturation;

  /* Update for Delay: '<S49>/Delay' */
  ADM_Integrated_Logic_DW.icLoad_e = false;
  ADM_Integrated_Logic_DW.Delay_DSTATE_i = rtb_deltafalllimit_m;

  /* Update for DiscreteTransferFcn: '<S1>/Discrete Transfer Fcn' */
  ADM_Integrated_Logic_DW.DiscreteTransferFcn_states = rtb_Vx_Cmd_R - -0.9375 *
    ADM_Integrated_Logic_DW.DiscreteTransferFcn_states;

  /* Update for UnitDelay: '<S44>/d1' incorporates:
   *  Inport: '<Root>/GV_IMU_AX_Val'
   */
  ADM_Integrated_Logic_DW.d1_DSTATE = ADM_Integrated_Logic_U.GV_IMU_AX_Val;

  /* Update for UnitDelay: '<S44>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE = rtb_deltafalllimit_a;

  /* Update for UnitDelay: '<S45>/d1' incorporates:
   *  Inport: '<Root>/GV_IMU_AY_Val'
   */
  ADM_Integrated_Logic_DW.d1_DSTATE_i = ADM_Integrated_Logic_U.GV_IMU_AY_Val;

  /* Update for UnitDelay: '<S45>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_p = rtb_Brake_Torque_Cmd;

  /* Update for UnitDelay: '<S46>/d1' incorporates:
   *  Inport: '<Root>/GV_IMU_AZ_Val'
   */
  ADM_Integrated_Logic_DW.d1_DSTATE_o = ADM_Integrated_Logic_U.GV_IMU_AZ_Val;

  /* Update for UnitDelay: '<S46>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_n = rtb_Integrator_1;

  /* Update for DiscreteIntegrator: '<S8>/Integrator_1' */
  ADM_Integrated_Logic_DW.Integrator_1_DSTATE += 0.002 * rtb_Brake_Saturation;

  /* Update for UnitDelay: '<S47>/d1' incorporates:
   *  Inport: '<Root>/GV_IMU_PitchRtVal'
   */
  ADM_Integrated_Logic_DW.d1_DSTATE_a = ADM_Integrated_Logic_U.GV_IMU_PitchRtVal;

  /* Update for UnitDelay: '<S47>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_d = rtb_Product1_m;

  /* Update for UnitDelay: '<S24>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_c = rtb_TargetSpd_RateLimiter;

  /* Update for UnitDelay: '<S24>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_l = rtb_Target_RPM;

  /* Update for UnitDelay: '<S34>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_i = rtb_Target_RPM;

  /* Update for UnitDelay: '<S34>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_p = rtb_Sum1_i2;

  /* Update for UnitDelay: '<S35>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_c = rtb_Sum1_i2;

  /* Update for UnitDelay: '<S35>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_h = rtb_Sum1_o1;

  /* Update for UnitDelay: '<S36>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_db = rtb_Sum1_o1;

  /* Update for UnitDelay: '<S36>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_l = rtb_Sum1_lm;

  /* Update for Delay: '<S38>/Delay1' */
  ADM_Integrated_Logic_DW.Delay1_DSTATE = rtb_Gain_c;

  /* Update for Delay: '<S38>/Delay' */
  ADM_Integrated_Logic_DW.Delay_DSTATE_c[0] =
    ADM_Integrated_Logic_DW.Delay_DSTATE_c[1];
  ADM_Integrated_Logic_DW.Delay_DSTATE_c[1] = rtb_Gain_c;

  /* Update for Delay: '<S38>/Delay2' */
  ADM_Integrated_Logic_DW.Delay2_DSTATE = rtb_Product1_j;

  /* Update for Delay: '<S38>/Delay3' */
  ADM_Integrated_Logic_DW.Delay3_DSTATE[0] =
    ADM_Integrated_Logic_DW.Delay3_DSTATE[1];
  ADM_Integrated_Logic_DW.Delay3_DSTATE[1] = rtb_Product1_j;

  /* Update for UnitDelay: '<S37>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_e = rtb_Product1_j;

  /* Update for UnitDelay: '<S37>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_ij = rtb_Product1_ee;

  /* Update for Memory: '<S4>/Memory' */
  ADM_Integrated_Logic_DW.Memory_PreviousInput = rtb_Add_e;

  /* Update for UnitDelay: '<S26>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_ir = rtb_Target_RPM;

  /* Update for UnitDelay: '<S26>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_of = rtb_Error_m;

  /* Update for UnitDelay: '<S27>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_m = rtb_Error_m;

  /* Update for UnitDelay: '<S27>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_hm = rtb_Sum1_aj;

  /* Update for UnitDelay: '<S28>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_mw = rtb_Sum1_aj;

  /* Update for UnitDelay: '<S28>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_g = rtb_Sum1_p;

  /* Update for UnitDelay: '<S29>/d1' */
  ADM_Integrated_Logic_DW.d1_DSTATE_ej = rtb_Add3;

  /* Update for UnitDelay: '<S29>/d' */
  ADM_Integrated_Logic_DW.d_DSTATE_j = rtb_Product1_h;

  /* Update for Delay: '<S30>/Delay1' */
  ADM_Integrated_Logic_DW.Delay1_DSTATE_c = rtb_Product1_h;

  /* Update for Delay: '<S30>/Delay' */
  ADM_Integrated_Logic_DW.Delay_DSTATE_p[0] =
    ADM_Integrated_Logic_DW.Delay_DSTATE_p[1];
  ADM_Integrated_Logic_DW.Delay_DSTATE_p[1] = rtb_Product1_h;

  /* Update for Delay: '<S30>/Delay2' */
  ADM_Integrated_Logic_DW.Delay2_DSTATE_n = rtb_Product1_kq;

  /* Update for Delay: '<S30>/Delay3' */
  ADM_Integrated_Logic_DW.Delay3_DSTATE_h[0] =
    ADM_Integrated_Logic_DW.Delay3_DSTATE_h[1];
  ADM_Integrated_Logic_DW.Delay3_DSTATE_h[1] = rtb_Product1_kq;

  /* Update for Delay: '<S16>/Delay' */
  ADM_Integrated_Logic_DW.icLoad_l = false;
  ADM_Integrated_Logic_DW.Delay_DSTATE_c4 = rtb_UkYk1_j;

  /* Update for Delay: '<S17>/Delay' */
  ADM_Integrated_Logic_DW.icLoad_d = false;
  ADM_Integrated_Logic_DW.Delay_DSTATE_i1 = rtb_Switch2;
}

/* Model initialize function */
void ADM_Integrated_Logic_initialize(void)
{
  /* InitializeConditions for Delay: '<S50>/Delay' */
  ADM_Integrated_Logic_DW.icLoad = true;

  /* InitializeConditions for Delay: '<S49>/Delay' */
  ADM_Integrated_Logic_DW.icLoad_e = true;

  /* InitializeConditions for Delay: '<S16>/Delay' */
  ADM_Integrated_Logic_DW.icLoad_l = true;

  /* InitializeConditions for Delay: '<S17>/Delay' */
  ADM_Integrated_Logic_DW.icLoad_d = true;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
