Program that execute AEB system

Dependencies:   AEB Ultrasonic Controller_Master mbed

Dependents:   AEB

Revision:
3:06075cbd49bd
Parent:
2:fb694fb2ef9b
Child:
4:0df8a61cbee9
diff -r fb694fb2ef9b -r 06075cbd49bd main.cpp
--- a/main.cpp	Wed Jul 06 09:17:23 2016 +0000
+++ b/main.cpp	Wed Jul 06 10:57:35 2016 +0000
@@ -2,45 +2,45 @@
 #include "Ultrasonic.h"
 
 extern "C" {
-#include "Controller_Master.h"         /* Model's header file */
+#include "Controller_Slave.h"       /* Model's header file */
 #include "rtwtypes.h"
 }
 
-static RT_MODEL_Controller_Master_T Controller_Master_M_;
-static RT_MODEL_Controller_Master_T *const Controller_Master_M =
-    &Controller_Master_M_;               /* Real-time model */
-static B_Controller_Master_T Controller_Master_B;/* Observable signals */
-static DW_Controller_Master_T Controller_Master_DW;/* Observable states */
+static RT_MODEL_Controller_Slave_T Controller_Slave_M_;
+static RT_MODEL_Controller_Slave_T *const Controller_Slave_M =
+    &Controller_Slave_M_;                /* Real-time model */
+static B_Controller_Slave_T Controller_Slave_B;/* Observable signals */
+static DW_Controller_Slave_T Controller_Slave_DW;/* Observable states */
 
 /* '<Root>/V' */
-static real_T Controller_Master_U_V;
+static real_T Controller_Slave_U_V;
 
-/* '<Root>/D_M' */
-static real_T Controller_Master_U_D_M;
+/* '<Root>/D_S' */
+static real_T Controller_Slave_U_D_S;
 
-/* '<Root>/SLAVE' */
-static uint8_T Controller_Master_U_Slave;
+/* '<Root>/MASTER' */
+static uint8_T Controller_Slave_U_Master;
 
 /* '<Root>/QA_EN' */
-static boolean_T Controller_Master_U_QA_EN;
+static boolean_T Controller_Slave_U_QA_EN;
 
 /* '<Root>/BRAKE' */
-static uint8_T Controller_Master_Y_BRAKE;
+static uint8_T Controller_Slave_Y_BRAKE;
 
 /* '<Root>/ACC' */
-static uint8_T Controller_Master_Y_ACC;
+static uint8_T Controller_Slave_Y_ACC;
 
 /* '<Root>/LED_RED' */
-static uint8_T Controller_Master_Y_LED_RED;
+static uint8_T Controller_Slave_Y_LED_RED;
 
 /* '<Root>/LED_GREEN' */
-static uint8_T Controller_Master_Y_LED_GREEN;
+static uint8_T Controller_Slave_Y_LED_GREEN;
 
 /* '<Root>/LED_BLUE' */
-static uint8_T Controller_Master_Y_LED_BLUE;
+static uint8_T Controller_Slave_Y_LED_BLUE;
 
-/* '<Root>/MASTER' */
-static uint8_T Controller_Master_Y_MASTER;
+/* '<Root>/SLAVE' */
+static uint8_T Controller_Slave_Y_SLAVE;
 
 /*
  * Associating rt_OneStep with a real-time clock or interrupt service routine
@@ -53,18 +53,18 @@
  * your application needs.  This example simply sets an error status in the
  * real-time model and returns from rt_OneStep.
  */
-void rt_OneStep(RT_MODEL_Controller_Master_T *const Controller_Master_M);
+void rt_OneStep(RT_MODEL_Controller_Slave_T *const Controller_Slave_M);
 void step();
 
 
 Ultrasonic sonic(D2,D4);  // Just call this funtion to initialize the ultrasonic sensor
 // D2 trigger D4 echo
- 
+
 DigitalOut led_R(LED_RED);
 DigitalOut led_G(LED_GREEN);
 DigitalOut led_B(LED_BLUE);
-DigitalOut master_out(D8);
-DigitalIn  slave(D6);
+DigitalOut slave_out(D8);
+DigitalIn  master(D6);
 float V = 29;   // Set the vehicle speed here
 Ticker t;
 Serial  pc(USBTX, USBRX); // tx, rx
@@ -72,35 +72,34 @@
 int main()
 {
     /* Pack model data into RTM */
-    Controller_Master_M->ModelData.blockIO = &Controller_Master_B;
-    Controller_Master_M->ModelData.dwork = &Controller_Master_DW;
-
+    Controller_Slave_M->ModelData.blockIO = &Controller_Slave_B;
+    Controller_Slave_M->ModelData.dwork = &Controller_Slave_DW;
 
-    Controller_Master_U_V = V;
-    Controller_Master_U_D_M = 50;
-    Controller_Master_U_Slave = 1;
-    Controller_Master_U_QA_EN = true;
+    Controller_Slave_U_V = V;
+    Controller_Slave_U_D_S = 50;
+    Controller_Slave_U_Master = 1;
+    Controller_Slave_U_QA_EN = true;
 
     /* Initialize model */
-    Controller_Master_initialize(Controller_Master_M, &Controller_Master_U_V,
-                                 &Controller_Master_U_D_M, &Controller_Master_U_Slave,
-                                 &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_LED_BLUE,
-                                 &Controller_Master_Y_MASTER);
+    Controller_Slave_initialize(Controller_Slave_M, &Controller_Slave_U_V,
+                                &Controller_Slave_U_D_S, &Controller_Slave_U_Master,
+                                &Controller_Slave_U_QA_EN, &Controller_Slave_Y_BRAKE,
+                                &Controller_Slave_Y_ACC, &Controller_Slave_Y_LED_RED,
+                                &Controller_Slave_Y_LED_GREEN, &Controller_Slave_Y_LED_BLUE,
+                                &Controller_Slave_Y_SLAVE);
 
-  /* Attach rt_OneStep to a timer or interrupt service routine with
-   * period 0.1 seconds (the model's base sample time) here.  The
-   * call syntax for rt_OneStep is
-   *
-   *  rt_OneStep(Controller_Master_M);
-   */
+    /* Attach rt_OneStep to a timer or interrupt service routine with
+     * period 0.1 seconds (the model's base sample time) here.  The
+     * call syntax for rt_OneStep is
+     *
+     *  rt_OneStep(Controller_Master_M);
+     */
     t.attach(&step,0.1);
     led_B.write(1);
     led_G.write(1);
     led_R.write(1);
-    slave.mode(PullDown);
-    master_out.write(1);
+    master.mode(PullDown);
+    slave_out.write(1);
     while (true) {
         wait(0.2);
         //led_R= !led_R;
@@ -110,29 +109,30 @@
     /* Disable rt_OneStep() here */
 
     /* Terminate model */
-    Controller_Master_terminate(Controller_Master_M);
+    Controller_Slave_terminate(Controller_Slave_M);
 }
 
 void step()
 {
-    Controller_Master_U_V = V;
-    Controller_Master_U_D_M = sonic.read_cm();
-    Controller_Master_U_Slave = slave.read();
-    Controller_Master_U_QA_EN = true;
-    rt_OneStep(Controller_Master_M);
-    master_out.write(Controller_Master_Y_MASTER);
-    pc.printf("blue: %d \n", Controller_Master_Y_LED_BLUE);    // Call read_cm() to get the distance in cm
-    pc.printf("red: %d \n", Controller_Master_Y_LED_RED);
-    pc.printf("master: %d \n", Controller_Master_Y_MASTER);
-    pc.printf("brake: %d \n", Controller_Master_Y_BRAKE);
-    pc.printf("green: %d \n", Controller_Master_Y_LED_GREEN);
-    pc.printf("acc: %d \n", Controller_Master_Y_ACC);
-    led_B = !Controller_Master_Y_LED_BLUE;         // negate because 1 -> led off
-    led_R = !Controller_Master_Y_LED_RED;
-    led_G = !Controller_Master_Y_LED_GREEN;
+    Controller_Slave_U_V = V;
+    Controller_Slave_U_D_S = sonic.read_cm();
+    Controller_Slave_U_Master = master.read();
+    Controller_Slave_U_QA_EN = true;
+    rt_OneStep(Controller_Slave_M);
+    slave_out.write(Controller_Slave_Y_SLAVE);
+    pc.printf("blue: %d \n", Controller_Slave_Y_LED_BLUE);    // Call read_cm() to get the distance in cm
+    pc.printf("red: %d \n", Controller_Slave_Y_LED_RED);
+    pc.printf("slave out: %d \n", Controller_Slave_Y_SLAVE);
+    pc.printf("master in: %d \n", Controller_Slave_U_Master);
+    pc.printf("brake: %d \n", Controller_Slave_Y_BRAKE);
+    pc.printf("green: %d \n", Controller_Slave_Y_LED_GREEN);
+    pc.printf("acc: %d \n", Controller_Slave_Y_ACC);
+    led_B = !Controller_Slave_Y_LED_BLUE;         // negate because 1 -> led off
+    led_R = !Controller_Slave_Y_LED_RED;
+    led_G = !Controller_Slave_Y_LED_GREEN;
 }
 
-void rt_OneStep(RT_MODEL_Controller_Master_T *const Controller_Master_M)
+void rt_OneStep(RT_MODEL_Controller_Slave_T *const Controller_Slave_M)
 {
     static boolean_T OverrunFlag = false;
 
@@ -140,7 +140,7 @@
 
     /* Check for overrun */
     if (OverrunFlag) {
-        rtmSetErrorStatus(Controller_Master_M, "Overrun");
+        rtmSetErrorStatus(Controller_Slave_M, "Overrun");
         return;
     }
 
@@ -151,11 +151,12 @@
     /* Set model inputs here */
 
     /* Step the model */
-    Controller_Master_step(Controller_Master_M, 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_LED_BLUE, &Controller_Master_Y_MASTER);
+    Controller_Slave_step(Controller_Slave_M, Controller_Slave_U_V,
+                          Controller_Slave_U_D_S, Controller_Slave_U_Master,
+                          Controller_Slave_U_QA_EN, &Controller_Slave_Y_BRAKE,
+                          &Controller_Slave_Y_ACC, &Controller_Slave_Y_LED_RED,
+                          &Controller_Slave_Y_LED_GREEN,
+                          &Controller_Slave_Y_LED_BLUE, &Controller_Slave_Y_SLAVE);
 
     /* Get model outputs here */