Library for the master controller

Dependents:   Test_Controller_Master AEB

Revision:
2:d114feef8f3b
Parent:
1:03ec2e1d1008
Child:
3:66d07e7a134a
--- a/Controller_Master.c	Sat Jun 04 18:37:52 2016 +0000
+++ b/Controller_Master.c	Wed Jul 06 08:22:31 2016 +0000
@@ -7,9 +7,9 @@
  *
  * Code generated for Simulink model 'Controller_Master'.
  *
- * Model version                  : 1.2
+ * Model version                  : 1.6
  * Simulink Coder version         : 8.10 (R2016a) 10-Feb-2016
- * C/C++ source code generated on : Sat Jun 04 20:35:28 2016
+ * C/C++ source code generated on : Wed Jul 06 10:20:25 2016
  *
  * Target selection: ert.tlc
  * Embedded hardware selection: NXP->Cortex-M4
@@ -19,14 +19,18 @@
 
 #include "Controller_Master.h"
 
-/* Named constants for Chart: '<S1>/AEB' */
+/* Named constants for Chart: '<S1>/AEB_QA' */
 #define Controller_M_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
-#define Controller_Master_IN_ACTIVE    ((uint8_T)1U)
+#define Controller_Master_IN_ACCELERATE ((uint8_T)1U)
+#define Controller_Master_IN_AEB_ACTIVE ((uint8_T)1U)
 #define Controller_Master_IN_BRAKE     ((uint8_T)1U)
+#define Controller_Master_IN_BRAKE_d   ((uint8_T)2U)
 #define Controller_Master_IN_ERR       ((uint8_T)1U)
 #define Controller_Master_IN_IDLE      ((uint8_T)2U)
+#define Controller_Master_IN_IDLE_k    ((uint8_T)3U)
 #define Controller_Master_IN_OK        ((uint8_T)2U)
-#define Controller_Master_IN_READY     ((uint8_T)2U)
+#define Controller_Master_IN_QA_ACTIVE ((uint8_T)2U)
+#define Controller_Master_IN_READY     ((uint8_T)3U)
 #define Controller_Master_IN_WARNING   ((uint8_T)3U)
 
 /* Named constants for Chart: '<S1>/select_command' */
@@ -36,6 +40,14 @@
 #define Controller_Master_IN_OFF1      ((uint8_T)2U)
 #define Controller_Master_IN_ON        ((uint8_T)3U)
 
+/* Forward declaration for local functions */
+static void Controller_Master_AEB_QA(real_T Controller_Master_U_V, real_T
+  Controller_Master_U_D_M, boolean_T Controller_Master_U_QA_EN, uint8_T
+  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_ACC, uint8_T
+  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_LED_GREEN, uint8_T *
+  Controller_Master_Y_MASTER, B_Controller_Master_T *Controller_Master_B,
+  DW_Controller_Master_T *Controller_Master_DW);
+
 /*===========*
  * Constants *
  *===========*/
@@ -66,33 +78,397 @@
 # endif
 #endif
 
+/* Function for Chart: '<S1>/AEB_QA' */
+static void Controller_Master_AEB_QA(real_T Controller_Master_U_V, real_T
+  Controller_Master_U_D_M, boolean_T Controller_Master_U_QA_EN, uint8_T
+  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_ACC, uint8_T
+  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_LED_GREEN, uint8_T *
+  Controller_Master_Y_MASTER, B_Controller_Master_T *Controller_Master_B,
+  DW_Controller_Master_T *Controller_Master_DW)
+{
+  real_T K;
+
+  /* During 'AEB_QA': '<S2>:35' */
+  /* During 'ERRORS_CHECK_THREAD': '<S2>:33' */
+  if (Controller_Master_DW->is_ERRORS_CHECK_THREAD != Controller_Master_IN_ERR)
+  {
+    /* Inport: '<Root>/V' incorporates:
+     *  Inport: '<Root>/D_M'
+     */
+    /* During 'OK': '<S2>:37' */
+    /* '<S2>:46:1' sf_internal_predicateOutput = ... */
+    /* '<S2>:46:1' V > 180 || D > 200 || D < 0; */
+    if ((Controller_Master_U_V > 180.0) || (Controller_Master_U_D_M > 200.0) ||
+        (Controller_Master_U_D_M < 0.0)) {
+      /* Transition: '<S2>:46' */
+      Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_ERR;
+
+      /* Entry 'ERR': '<S2>:42' */
+      /* '<S2>:42:1' Led_Red = uint8(1); */
+      *Controller_Master_Y_LED_RED = 1U;
+
+      /* '<S2>:42:1' Master = uint8(0) ; */
+      *Controller_Master_Y_MASTER = 0U;
+
+      /* '<S2>:42:3' En = false; */
+      Controller_Master_DW->En = false;
+
+      /* '<S2>:42:3' Brake = uint8(0); */
+      *Controller_Master_Y_BRAKE = 0U;
+
+      /* '<S2>:42:4' Led_Blue = 0; */
+      Controller_Master_B->Led_Blue = 0.0;
+
+      /* '<S2>:42:5' Acc = uint8(0); */
+      *Controller_Master_Y_ACC = 0U;
+
+      /* '<S2>:42:6' Led_Green = uint8(0); */
+      *Controller_Master_Y_LED_GREEN = 0U;
+    } else {
+      /* '<S2>:43:1' sf_internal_predicateOutput = ... */
+      /* '<S2>:43:1' D == 0; */
+      if (Controller_Master_U_D_M == 0.0) {
+        /* Transition: '<S2>:43' */
+        Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_ERR;
+
+        /* Entry 'ERR': '<S2>:42' */
+        /* '<S2>:42:1' Led_Red = uint8(1); */
+        *Controller_Master_Y_LED_RED = 1U;
+
+        /* '<S2>:42:1' Master = uint8(0) ; */
+        *Controller_Master_Y_MASTER = 0U;
+
+        /* '<S2>:42:3' En = false; */
+        Controller_Master_DW->En = false;
+
+        /* '<S2>:42:3' Brake = uint8(0); */
+        *Controller_Master_Y_BRAKE = 0U;
+
+        /* '<S2>:42:4' Led_Blue = 0; */
+        Controller_Master_B->Led_Blue = 0.0;
+
+        /* '<S2>:42:5' Acc = uint8(0); */
+        *Controller_Master_Y_ACC = 0U;
+
+        /* '<S2>:42:6' Led_Green = uint8(0); */
+        *Controller_Master_Y_LED_GREEN = 0U;
+      }
+    }
+  } else {
+    /* During 'ERR': '<S2>:42' */
+  }
+
+  /* During 'APPLICATION_THREAD': '<S2>:32' */
+  switch (Controller_Master_DW->is_APPLICATION_THREAD) {
+   case Controller_Master_IN_AEB_ACTIVE:
+    /* During 'AEB_ACTIVE': '<S2>:1' */
+    /* '<S2>:26:1' sf_internal_predicateOutput = ... */
+    /* '<S2>:26:1' En == false; */
+    if (!Controller_Master_DW->En) {
+      /* Transition: '<S2>:26' */
+      /* Exit Internal 'AEB_ACTIVE': '<S2>:1' */
+      Controller_Master_DW->is_AEB_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
+      Controller_Master_DW->is_APPLICATION_THREAD = Controller_Master_IN_READY;
+
+      /* Entry 'READY': '<S2>:21' */
+      /* '<S2>:21:1' Brake = uint8(0); */
+      *Controller_Master_Y_BRAKE = 0U;
+
+      /* '<S2>:21:1' Led_Blue = 0; */
+      Controller_Master_B->Led_Blue = 0.0;
+
+      /* '<S2>:21:1' Led_Green = uint8(0); */
+      *Controller_Master_Y_LED_GREEN = 0U;
+
+      /* '<S2>:21:4' Acc = uint8(0); */
+      *Controller_Master_Y_ACC = 0U;
+    } else {
+      /* Inport: '<Root>/QA_EN' incorporates:
+       *  Inport: '<Root>/V'
+       */
+      /* '<S2>:70:1' sf_internal_predicateOutput = ... */
+      /* '<S2>:70:1' QA_En == true && V<30; */
+      if (Controller_Master_U_QA_EN && (Controller_Master_U_V < 30.0)) {
+        /* Transition: '<S2>:70' */
+        /* Exit Internal 'AEB_ACTIVE': '<S2>:1' */
+        Controller_Master_DW->is_AEB_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
+        Controller_Master_DW->is_APPLICATION_THREAD =
+          Controller_Master_IN_QA_ACTIVE;
+
+        /* Entry 'QA_ACTIVE': '<S2>:69' */
+        /* '<S2>:69:1' K = (V^2)/D; */
+        /* Entry Internal 'QA_ACTIVE': '<S2>:69' */
+        /* Transition: '<S2>:64' */
+        Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_IDLE_k;
+
+        /* Entry 'IDLE': '<S2>:67' */
+        /* '<S2>:67:1' Brake = uint8(0); */
+        *Controller_Master_Y_BRAKE = 0U;
+
+        /* '<S2>:67:1' Led_Blue = 0; */
+        Controller_Master_B->Led_Blue = 0.0;
+
+        /* '<S2>:67:1' Led_Green = uint8(0); */
+        *Controller_Master_Y_LED_GREEN = 0U;
+
+        /* '<S2>:67:4' Acc = uint8(0); */
+        *Controller_Master_Y_ACC = 0U;
+      } else {
+        /* Inport: '<Root>/D_M' */
+        /* '<S2>:1:1' K = (V^2)/D; */
+        K = Controller_Master_U_V * Controller_Master_U_V /
+          Controller_Master_U_D_M;
+        switch (Controller_Master_DW->is_AEB_ACTIVE) {
+         case Controller_Master_IN_BRAKE:
+          /* During 'BRAKE': '<S2>:3' */
+          /* '<S2>:10:1' sf_internal_predicateOutput = ... */
+          /* '<S2>:10:1' K < 100; */
+          if (K < 100.0) {
+            /* Transition: '<S2>:10' */
+            Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_WARNING;
+
+            /* Entry 'WARNING': '<S2>:5' */
+            /* '<S2>:5:1' Brake = uint8(0); */
+            *Controller_Master_Y_BRAKE = 0U;
+          }
+          break;
+
+         case Controller_Master_IN_IDLE:
+          /* During 'IDLE': '<S2>:6' */
+          /* '<S2>:12:1' sf_internal_predicateOutput = ... */
+          /* '<S2>:12:1' K >= 70; */
+          if (K >= 70.0) {
+            /* Transition: '<S2>:12' */
+            Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_WARNING;
+
+            /* Entry 'WARNING': '<S2>:5' */
+            /* '<S2>:5:1' Brake = uint8(0); */
+            *Controller_Master_Y_BRAKE = 0U;
+          }
+          break;
+
+         default:
+          /* During 'WARNING': '<S2>:5' */
+          /* '<S2>:9:1' sf_internal_predicateOutput = ... */
+          /* '<S2>:9:1' K  >= 100; */
+          if (K >= 100.0) {
+            /* Transition: '<S2>:9' */
+            Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_BRAKE;
+
+            /* Entry 'BRAKE': '<S2>:3' */
+            /* '<S2>:3:1' Brake = uint8(1); */
+            *Controller_Master_Y_BRAKE = 1U;
+
+            /* '<S2>:3:1' Led_Blue = 1; */
+            Controller_Master_B->Led_Blue = 1.0;
+          } else {
+            /* '<S2>:11:1' sf_internal_predicateOutput = ... */
+            /* '<S2>:11:1' K < 70; */
+            if (K < 70.0) {
+              /* Transition: '<S2>:11' */
+              Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_IDLE;
+
+              /* Entry 'IDLE': '<S2>:6' */
+              /* '<S2>:6:1' Brake = uint8(0); */
+              *Controller_Master_Y_BRAKE = 0U;
+
+              /* '<S2>:6:1' Led_Blue = 0; */
+              Controller_Master_B->Led_Blue = 0.0;
+            } else {
+              /* '<S2>:5:1' Led_Blue = (K-70)/30; */
+              Controller_Master_B->Led_Blue = (K - 70.0) / 30.0;
+            }
+          }
+          break;
+        }
+      }
+    }
+    break;
+
+   case Controller_Master_IN_QA_ACTIVE:
+    /* Inport: '<Root>/QA_EN' incorporates:
+     *  Inport: '<Root>/V'
+     */
+    /* During 'QA_ACTIVE': '<S2>:69' */
+    /* '<S2>:71:1' sf_internal_predicateOutput = ... */
+    /* '<S2>:71:1' QA_En ~= true || V>=30; */
+    if ((!Controller_Master_U_QA_EN) || (Controller_Master_U_V >= 30.0)) {
+      /* Transition: '<S2>:71' */
+      /* Exit Internal 'QA_ACTIVE': '<S2>:69' */
+      Controller_Master_DW->is_QA_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
+      Controller_Master_DW->is_APPLICATION_THREAD =
+        Controller_Master_IN_AEB_ACTIVE;
+
+      /* Entry 'AEB_ACTIVE': '<S2>:1' */
+      /* '<S2>:1:1' K = (V^2)/D; */
+      /* Entry Internal 'AEB_ACTIVE': '<S2>:1' */
+      /* Transition: '<S2>:51' */
+      Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_IDLE;
+
+      /* Entry 'IDLE': '<S2>:6' */
+      /* '<S2>:6:1' Brake = uint8(0); */
+      *Controller_Master_Y_BRAKE = 0U;
+
+      /* '<S2>:6:1' Led_Blue = 0; */
+      Controller_Master_B->Led_Blue = 0.0;
+    } else {
+      /* '<S2>:79:1' sf_internal_predicateOutput = ... */
+      /* '<S2>:79:1' En == false; */
+      if (!Controller_Master_DW->En) {
+        /* Transition: '<S2>:79' */
+        /* Exit Internal 'QA_ACTIVE': '<S2>:69' */
+        Controller_Master_DW->is_QA_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
+        Controller_Master_DW->is_APPLICATION_THREAD = Controller_Master_IN_READY;
+
+        /* Entry 'READY': '<S2>:21' */
+        /* '<S2>:21:1' Brake = uint8(0); */
+        *Controller_Master_Y_BRAKE = 0U;
+
+        /* '<S2>:21:1' Led_Blue = 0; */
+        Controller_Master_B->Led_Blue = 0.0;
+
+        /* '<S2>:21:1' Led_Green = uint8(0); */
+        *Controller_Master_Y_LED_GREEN = 0U;
+
+        /* '<S2>:21:4' Acc = uint8(0); */
+        *Controller_Master_Y_ACC = 0U;
+      } else {
+        /* Inport: '<Root>/D_M' */
+        /* '<S2>:69:1' K = (V^2)/D; */
+        K = Controller_Master_U_V * Controller_Master_U_V /
+          Controller_Master_U_D_M;
+        switch (Controller_Master_DW->is_QA_ACTIVE) {
+         case Controller_Master_IN_ACCELERATE:
+          /* During 'ACCELERATE': '<S2>:68' */
+          /* '<S2>:75:1' sf_internal_predicateOutput = ... */
+          /* '<S2>:75:1' K  >= 100; */
+          if (K >= 100.0) {
+            /* Transition: '<S2>:75' */
+            Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_IDLE_k;
+
+            /* Entry 'IDLE': '<S2>:67' */
+            /* '<S2>:67:1' Brake = uint8(0); */
+            *Controller_Master_Y_BRAKE = 0U;
+
+            /* '<S2>:67:1' Led_Blue = 0; */
+            Controller_Master_B->Led_Blue = 0.0;
+
+            /* '<S2>:67:1' Led_Green = uint8(0); */
+            *Controller_Master_Y_LED_GREEN = 0U;
+
+            /* '<S2>:67:4' Acc = uint8(0); */
+            *Controller_Master_Y_ACC = 0U;
+          }
+          break;
+
+         case Controller_Master_IN_BRAKE_d:
+          /* During 'BRAKE': '<S2>:65' */
+          /* '<S2>:73:1' sf_internal_predicateOutput = ... */
+          /* '<S2>:73:1' K <= 100; */
+          if (K <= 100.0) {
+            /* Transition: '<S2>:73' */
+            Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_IDLE_k;
+
+            /* Entry 'IDLE': '<S2>:67' */
+            /* '<S2>:67:1' Brake = uint8(0); */
+            *Controller_Master_Y_BRAKE = 0U;
+
+            /* '<S2>:67:1' Led_Blue = 0; */
+            Controller_Master_B->Led_Blue = 0.0;
+
+            /* '<S2>:67:1' Led_Green = uint8(0); */
+            *Controller_Master_Y_LED_GREEN = 0U;
+
+            /* '<S2>:67:4' Acc = uint8(0); */
+            *Controller_Master_Y_ACC = 0U;
+          }
+          break;
+
+         default:
+          /* During 'IDLE': '<S2>:67' */
+          /* '<S2>:72:1' sf_internal_predicateOutput = ... */
+          /* '<S2>:72:1' K  > 100; */
+          if (K > 100.0) {
+            /* Transition: '<S2>:72' */
+            Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_BRAKE_d;
+
+            /* Entry 'BRAKE': '<S2>:65' */
+            /* '<S2>:65:1' Brake = uint8(1); */
+            *Controller_Master_Y_BRAKE = 1U;
+
+            /* '<S2>:65:1' Led_Blue = 1; */
+            Controller_Master_B->Led_Blue = 1.0;
+          } else {
+            /* '<S2>:74:1' sf_internal_predicateOutput = ... */
+            /* '<S2>:74:1' K < 100; */
+            if (K < 100.0) {
+              /* Transition: '<S2>:74' */
+              Controller_Master_DW->is_QA_ACTIVE =
+                Controller_Master_IN_ACCELERATE;
+
+              /* Entry 'ACCELERATE': '<S2>:68' */
+              /* '<S2>:68:1' Led_Green = uint8(1); */
+              *Controller_Master_Y_LED_GREEN = 1U;
+
+              /* '<S2>:68:1' Acc = uint8(1); */
+              *Controller_Master_Y_ACC = 1U;
+            }
+          }
+          break;
+        }
+      }
+    }
+    break;
+
+   default:
+    /* During 'READY': '<S2>:21' */
+    /* '<S2>:23:1' sf_internal_predicateOutput = ... */
+    /* '<S2>:23:1' En == true; */
+    if (Controller_Master_DW->En) {
+      /* Transition: '<S2>:23' */
+      Controller_Master_DW->is_APPLICATION_THREAD =
+        Controller_Master_IN_AEB_ACTIVE;
+
+      /* Entry 'AEB_ACTIVE': '<S2>:1' */
+      /* '<S2>:1:1' K = (V^2)/D; */
+      /* Entry Internal 'AEB_ACTIVE': '<S2>:1' */
+      /* Transition: '<S2>:51' */
+      Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_IDLE;
+
+      /* Entry 'IDLE': '<S2>:6' */
+      /* '<S2>:6:1' Brake = uint8(0); */
+      *Controller_Master_Y_BRAKE = 0U;
+
+      /* '<S2>:6:1' Led_Blue = 0; */
+      Controller_Master_B->Led_Blue = 0.0;
+    }
+    break;
+  }
+}
+
 /* Model step function */
 void Controller_Master_step(RT_MODEL_Controller_Master_T *const
   Controller_Master_M, real_T Controller_Master_U_V, real_T
-  Controller_Master_U_D_M, uint8_T Controller_Master_U_Slave, uint8_T
-  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_LED_BLUE, uint8_T
-  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_MASTER)
+  Controller_Master_U_D_M, boolean_T Controller_Master_U_QA_EN, uint8_T
+  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_ACC, uint8_T
+  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_LED_GREEN, uint8_T *
+  Controller_Master_Y_LED_BLUE, uint8_T *Controller_Master_Y_MASTER)
 {
   B_Controller_Master_T *Controller_Master_B = ((B_Controller_Master_T *)
     Controller_Master_M->ModelData.blockIO);
   DW_Controller_Master_T *Controller_Master_DW = ((DW_Controller_Master_T *)
     Controller_Master_M->ModelData.dwork);
-  real_T K;
 
   /* Outputs for Atomic SubSystem: '<Root>/Controller_Master' */
-  /* Chart: '<S1>/AEB' incorporates:
-   *  Inport: '<Root>/D_M'
-   *  Inport: '<Root>/V'
-   *  Memory: '<S1>/Memory'
-   */
-  /* Gateway: Controller_Master/AEB */
-  /* During: Controller_Master/AEB */
+  /* Chart: '<S1>/AEB_QA' */
+  /* Gateway: Controller_Master/AEB_QA */
+  /* During: Controller_Master/AEB_QA */
   if (Controller_Master_DW->is_active_c3_Controller_Master == 0U) {
-    /* Entry: Controller_Master/AEB */
+    /* Entry: Controller_Master/AEB_QA */
     Controller_Master_DW->is_active_c3_Controller_Master = 1U;
 
-    /* Entry Internal: Controller_Master/AEB */
-    /* Entry Internal 'AEB': '<S2>:35' */
+    /* Entry Internal: Controller_Master/AEB_QA */
+    /* Entry Internal 'AEB_QA': '<S2>:35' */
     /* Entry Internal 'ERRORS_CHECK_THREAD': '<S2>:33' */
     /* Transition: '<S2>:38' */
     Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_OK;
@@ -117,202 +493,23 @@
 
     /* '<S2>:21:1' Led_Blue = 0; */
     Controller_Master_B->Led_Blue = 0.0;
-  } else {
-    /* During 'AEB': '<S2>:35' */
-    /* During 'ERRORS_CHECK_THREAD': '<S2>:33' */
-    if (Controller_Master_DW->is_ERRORS_CHECK_THREAD != Controller_Master_IN_ERR)
-    {
-      /* During 'OK': '<S2>:37' */
-      /* '<S2>:46:1' sf_internal_predicateOutput = ... */
-      /* '<S2>:46:1' V > 180 || D > 200 || D < 0; */
-      if ((Controller_Master_U_V > 180.0) || (Controller_Master_U_D_M > 200.0) ||
-          (Controller_Master_U_D_M < 0.0)) {
-        /* Transition: '<S2>:46' */
-        Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_ERR;
 
-        /* Outport: '<Root>/LED_RED' */
-        /* Entry 'ERR': '<S2>:42' */
-        /* '<S2>:42:1' Led_Red = uint8(1); */
-        *Controller_Master_Y_LED_RED = 1U;
-
-        /* Outport: '<Root>/MASTER' */
-        /* Entry 'MCU_ERR': '<S2>:40' */
-        /* '<S2>:40:1' Master = uint8(0) ; */
-        *Controller_Master_Y_MASTER = 0U;
-
-        /* '<S2>:40:1' En = false; */
-        Controller_Master_DW->En = false;
-
-        /* Outport: '<Root>/BRAKE' */
-        /* '<S2>:40:1' Brake = uint8(0); */
-        *Controller_Master_Y_BRAKE = 0U;
-
-        /* '<S2>:40:3' Led_Blue = 0; */
-        Controller_Master_B->Led_Blue = 0.0;
-      } else {
-        /* '<S2>:43:1' sf_internal_predicateOutput = ... */
-        /* '<S2>:43:1' D == 0; */
-        if (Controller_Master_U_D_M == 0.0) {
-          /* Transition: '<S2>:43' */
-          Controller_Master_DW->is_ERRORS_CHECK_THREAD =
-            Controller_Master_IN_ERR;
-
-          /* Outport: '<Root>/LED_RED' */
-          /* Entry 'ERR': '<S2>:42' */
-          /* '<S2>:42:1' Led_Red = uint8(1); */
-          *Controller_Master_Y_LED_RED = 1U;
-
-          /* Outport: '<Root>/MASTER' */
-          /* Entry 'SENSOR_ERR': '<S2>:39' */
-          /* '<S2>:39:1' Master = uint8(0) ; */
-          *Controller_Master_Y_MASTER = 0U;
-
-          /* '<S2>:39:1' En = false; */
-          Controller_Master_DW->En = false;
-
-          /* Outport: '<Root>/BRAKE' */
-          /* '<S2>:39:1' Brake = uint8(0); */
-          *Controller_Master_Y_BRAKE = 0U;
-
-          /* '<S2>:39:3' Led_Blue = 0; */
-          Controller_Master_B->Led_Blue = 0.0;
-        } else {
-          /* '<S2>:45:1' sf_internal_predicateOutput = ... */
-          /* '<S2>:45:1' Slave ~= 1; */
-          if (Controller_Master_DW->Memory_PreviousInput != 1) {
-            /* Transition: '<S2>:45' */
-            Controller_Master_DW->is_ERRORS_CHECK_THREAD =
-              Controller_Master_IN_ERR;
-
-            /* Outport: '<Root>/LED_RED' */
-            /* Entry 'ERR': '<S2>:42' */
-            /* '<S2>:42:1' Led_Red = uint8(1); */
-            *Controller_Master_Y_LED_RED = 1U;
-          }
-        }
-      }
-    } else {
-      /* During 'ERR': '<S2>:42' */
-    }
-
-    /* During 'APPLICATION_THREAD': '<S2>:32' */
-    if (Controller_Master_DW->is_APPLICATION_THREAD ==
-        Controller_Master_IN_ACTIVE) {
-      /* During 'ACTIVE': '<S2>:1' */
-      /* '<S2>:26:1' sf_internal_predicateOutput = ... */
-      /* '<S2>:26:1' En == false; */
-      if (!Controller_Master_DW->En) {
-        /* Transition: '<S2>:26' */
-        /* Exit Internal 'ACTIVE': '<S2>:1' */
-        Controller_Master_DW->is_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
-        Controller_Master_DW->is_APPLICATION_THREAD = Controller_Master_IN_READY;
-
-        /* Outport: '<Root>/BRAKE' */
-        /* Entry 'READY': '<S2>:21' */
-        /* '<S2>:21:1' Brake = uint8(0); */
-        *Controller_Master_Y_BRAKE = 0U;
+    /* Outport: '<Root>/LED_GREEN' */
+    /* '<S2>:21:1' Led_Green = uint8(0); */
+    *Controller_Master_Y_LED_GREEN = 0U;
 
-        /* '<S2>:21:1' Led_Blue = 0; */
-        Controller_Master_B->Led_Blue = 0.0;
-      } else {
-        /* '<S2>:1:1' K = (V^2)/D; */
-        K = Controller_Master_U_V * Controller_Master_U_V /
-          Controller_Master_U_D_M;
-        switch (Controller_Master_DW->is_ACTIVE) {
-         case Controller_Master_IN_BRAKE:
-          /* During 'BRAKE': '<S2>:3' */
-          /* '<S2>:10:1' sf_internal_predicateOutput = ... */
-          /* '<S2>:10:1' K < 100; */
-          if (K < 100.0) {
-            /* Transition: '<S2>:10' */
-            Controller_Master_DW->is_ACTIVE = Controller_Master_IN_WARNING;
-
-            /* Outport: '<Root>/BRAKE' */
-            /* Entry 'WARNING': '<S2>:5' */
-            /* '<S2>:5:1' Brake = uint8(0); */
-            *Controller_Master_Y_BRAKE = 0U;
-          }
-          break;
-
-         case Controller_Master_IN_IDLE:
-          /* During 'IDLE': '<S2>:6' */
-          /* '<S2>:12:1' sf_internal_predicateOutput = ... */
-          /* '<S2>:12:1' K >= 70; */
-          if (K >= 70.0) {
-            /* Transition: '<S2>:12' */
-            Controller_Master_DW->is_ACTIVE = Controller_Master_IN_WARNING;
-
-            /* Outport: '<Root>/BRAKE' */
-            /* Entry 'WARNING': '<S2>:5' */
-            /* '<S2>:5:1' Brake = uint8(0); */
-            *Controller_Master_Y_BRAKE = 0U;
-          }
-          break;
-
-         default:
-          /* During 'WARNING': '<S2>:5' */
-          /* '<S2>:9:1' sf_internal_predicateOutput = ... */
-          /* '<S2>:9:1' K  >= 100; */
-          if (K >= 100.0) {
-            /* Transition: '<S2>:9' */
-            Controller_Master_DW->is_ACTIVE = Controller_Master_IN_BRAKE;
-
-            /* Outport: '<Root>/BRAKE' */
-            /* Entry 'BRAKE': '<S2>:3' */
-            /* '<S2>:3:1' Brake = uint8(1); */
-            *Controller_Master_Y_BRAKE = 1U;
-
-            /* '<S2>:3:1' Led_Blue = 1; */
-            Controller_Master_B->Led_Blue = 1.0;
-          } else {
-            /* '<S2>:11:1' sf_internal_predicateOutput = ... */
-            /* '<S2>:11:1' K < 70; */
-            if (K < 70.0) {
-              /* Transition: '<S2>:11' */
-              Controller_Master_DW->is_ACTIVE = Controller_Master_IN_IDLE;
-
-              /* Outport: '<Root>/BRAKE' */
-              /* Entry 'IDLE': '<S2>:6' */
-              /* '<S2>:6:1' Brake = uint8(0); */
-              *Controller_Master_Y_BRAKE = 0U;
-
-              /* '<S2>:6:1' Led_Blue = 0; */
-              Controller_Master_B->Led_Blue = 0.0;
-            } else {
-              /* '<S2>:5:1' Led_Blue = (K-70)/30; */
-              Controller_Master_B->Led_Blue = (K - 70.0) / 30.0;
-            }
-          }
-          break;
-        }
-      }
-    } else {
-      /* During 'READY': '<S2>:21' */
-      /* '<S2>:23:1' sf_internal_predicateOutput = ... */
-      /* '<S2>:23:1' En == true; */
-      if (Controller_Master_DW->En) {
-        /* Transition: '<S2>:23' */
-        Controller_Master_DW->is_APPLICATION_THREAD =
-          Controller_Master_IN_ACTIVE;
-
-        /* Entry 'ACTIVE': '<S2>:1' */
-        /* '<S2>:1:1' K = (V^2)/D; */
-        /* Entry Internal 'ACTIVE': '<S2>:1' */
-        /* Transition: '<S2>:51' */
-        Controller_Master_DW->is_ACTIVE = Controller_Master_IN_IDLE;
-
-        /* Outport: '<Root>/BRAKE' */
-        /* Entry 'IDLE': '<S2>:6' */
-        /* '<S2>:6:1' Brake = uint8(0); */
-        *Controller_Master_Y_BRAKE = 0U;
-
-        /* '<S2>:6:1' Led_Blue = 0; */
-        Controller_Master_B->Led_Blue = 0.0;
-      }
-    }
+    /* Outport: '<Root>/ACC' */
+    /* '<S2>:21:4' Acc = uint8(0); */
+    *Controller_Master_Y_ACC = 0U;
+  } else {
+    Controller_Master_AEB_QA(Controller_Master_U_V, Controller_Master_U_D_M,
+      Controller_Master_U_QA_EN, Controller_Master_Y_BRAKE,
+      Controller_Master_Y_ACC, Controller_Master_Y_LED_RED,
+      Controller_Master_Y_LED_GREEN, Controller_Master_Y_MASTER,
+      Controller_Master_B, Controller_Master_DW);
   }
 
-  /* End of Chart: '<S1>/AEB' */
+  /* End of Chart: '<S1>/AEB_QA' */
 
   /* Chart: '<S1>/select_command' */
   if (Controller_Master_DW->temporalCounter_i1 < MAX_uint32_T) {
@@ -368,8 +565,8 @@
           /* During 'BLINK_OFF': '<S3>:11' */
           /* '<S3>:14:1' sf_internal_predicateOutput = ... */
           /* '<S3>:14:1' after(1-enable,sec); */
-          if (Controller_Master_DW->temporalCounter_i1 >= (uint32_T)ceil((1.0 -
-                Controller_Master_B->Led_Blue) / 0.2 - 2.0E-9)) {
+          if ((Controller_Master_DW->temporalCounter_i1 << 1) >= 1.0 -
+              Controller_Master_B->Led_Blue) {
             /* Transition: '<S3>:14' */
             Controller_Master_DW->is_BLINK = Controller_Master_IN_BLINK_ON;
             Controller_Master_DW->temporalCounter_i1 = 0U;
@@ -469,21 +666,17 @@
   }
 
   /* End of Chart: '<S1>/select_command' */
-
-  /* Update for Memory: '<S1>/Memory' incorporates:
-   *  Update for Inport: '<Root>/SLAVE'
-   */
-  Controller_Master_DW->Memory_PreviousInput = Controller_Master_U_Slave;
-
   /* End of Outputs for SubSystem: '<Root>/Controller_Master' */
 }
 
 /* Model initialize function */
 void Controller_Master_initialize(RT_MODEL_Controller_Master_T *const
   Controller_Master_M, real_T *Controller_Master_U_V, real_T
-  *Controller_Master_U_D_M, uint8_T *Controller_Master_U_Slave, uint8_T
-  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_LED_BLUE, uint8_T
-  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_MASTER)
+  *Controller_Master_U_D_M, uint8_T *Controller_Master_U_Slave, boolean_T
+  *Controller_Master_U_QA_EN, uint8_T *Controller_Master_Y_BRAKE, uint8_T
+  *Controller_Master_Y_ACC, uint8_T *Controller_Master_Y_LED_RED, uint8_T
+  *Controller_Master_Y_LED_GREEN, uint8_T *Controller_Master_Y_LED_BLUE, uint8_T
+  *Controller_Master_Y_MASTER)
 {
   DW_Controller_Master_T *Controller_Master_DW = ((DW_Controller_Master_T *)
     Controller_Master_M->ModelData.dwork);
@@ -504,20 +697,21 @@
   (*Controller_Master_U_V) = 0.0;
   (*Controller_Master_U_D_M) = 0.0;
   (*Controller_Master_U_Slave) = 0U;
+  (*Controller_Master_U_QA_EN) = false;
 
   /* external outputs */
   (*Controller_Master_Y_BRAKE) = 0U;
+  (*Controller_Master_Y_ACC) = 0U;
+  (*Controller_Master_Y_LED_RED) = 0U;
+  (*Controller_Master_Y_LED_GREEN) = 0U;
   (*Controller_Master_Y_LED_BLUE) = 0U;
-  (*Controller_Master_Y_LED_RED) = 0U;
   (*Controller_Master_Y_MASTER) = 0U;
 
   /* SystemInitialize for Atomic SubSystem: '<Root>/Controller_Master' */
-  /* InitializeConditions for Memory: '<S1>/Memory' */
-  Controller_Master_DW->Memory_PreviousInput = 1U;
-
-  /* SystemInitialize for Chart: '<S1>/AEB' */
+  /* SystemInitialize for Chart: '<S1>/AEB_QA' */
   Controller_Master_DW->is_APPLICATION_THREAD = Controller_M_IN_NO_ACTIVE_CHILD;
-  Controller_Master_DW->is_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
+  Controller_Master_DW->is_AEB_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
+  Controller_Master_DW->is_QA_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
   Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_M_IN_NO_ACTIVE_CHILD;
   Controller_Master_DW->is_active_c3_Controller_Master = 0U;
   Controller_Master_DW->En = true;