Program that execute AEB system

Dependencies:   AEB Ultrasonic Controller_Master mbed

Dependents:   AEB

Revision:
1:8cb509a319e5
Parent:
0:64a08651b7c0
Child:
2:fb694fb2ef9b
--- a/main.cpp	Thu Jun 02 21:23:36 2016 +0000
+++ b/main.cpp	Fri Jun 03 07:50:12 2016 +0000
@@ -3,27 +3,73 @@
 */
 #include "mbed.h"
 #include "Ultrasonic.h"
-#include "Controller_Master.h"
+
+extern "C" {
+#include "Controller.h"
 #include "rtwtypes.h"
+}
 
+static RT_MODEL_Controller_T Controller_M_;
+static RT_MODEL_Controller_T *const Controller_M = &Controller_M_;/* Real-time model */
+static B_Controller_T Controller_B;    /* Observable signals */
+static DW_Controller_T Controller_DW;  /* Observable states */
+
+/* '<Root>/V' */
+static real_T Controller_U_V;
+
+/* '<Root>/D_M' */
+static real_T Controller_U_D_M;
+
+/* '<Root>/SLAVE' */
+static uint8_T Controller_U_SLAVE;
+
+/* '<Root>/BRAKE' */
+static uint8_T Controller_Y_BRAKE;
+
+/* '<Root>/LED_BLUE' */
+static uint8_T Controller_Y_LED_BLUE;
+
+/* '<Root>/LED_RED' */
+static uint8_T Controller_Y_LED_RED;
+
+/* '<Root>/MASTER' */
+static uint8_T Controller_Y_MASTER;
+
+/*
+ * Associating rt_OneStep with a real-time clock or interrupt service routine
+ * is what makes the generated code "real-time".  The function rt_OneStep is
+ * always associated with the base rate of the model.  Subrates are managed
+ * by the base rate from inside the generated code.  Enabling/disabling
+ * interrupts and floating point context switches are target specific.  This
+ * example code indicates where these should take place relative to executing
+ * the generated code step function.  Overrun behavior should be tailored to
+ * 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_T *const Controller_M);
+
+Serial  pc(USBTX, USBRX); // tx, rx
 DigitalOut led_R(LED_RED);
 DigitalOut led_B(LED_BLUE);
 DigitalIn  slave(D6);
 Ticker t;
 float V = 50;
 
-Serial  pc(USBTX, USBRX); // tx, rx
 
 void step();
 
 int main()
 {
-    
+    /* Pack model data into RTM */
+    Controller_M->ModelData.blockIO = &Controller_B;
+    Controller_M->ModelData.dwork = &Controller_DW;
+
+    /* Initialize model */
+    Controller_initialize(Controller_M, &Controller_U_V, &Controller_U_D_M,
+                          &Controller_U_SLAVE, &Controller_Y_BRAKE,
+                          &Controller_Y_LED_BLUE, &Controller_Y_LED_RED,
+                          &Controller_Y_MASTER);
     Ultrasonic_init();  // Just call this funtion to initialize the ultrasonic sensor
-    Controller_Master_U.V = V;
-    Controller_Master_U.D_M = read_cm();
-    Controller_Master_U.Slave = slave.read();
-    Controller_Master_initialize();
     t.attach(&step,0.2);
     while (true) {
         wait(0.2);
@@ -33,10 +79,44 @@
 
 void step()
 {
-    Controller_Master_U.D_M = read_cm();
-    Controller_Master_U.Slave = slave.read();
-    pc.printf("Distance: %f \n", Controller_Master_U.D_M);    // Call read_cm() to get the distance in cm
-    Controller_Master_step();
-    led_B = Controller_Master_Y.LED_BLUE;
-    led_R = Controller_Master_Y.LED_RED;
+    Controller_U_D_M = read_cm();
+    Controller_U_SLAVE = slave.read();
+    rt_OneStep(Controller_M); 
+    pc.printf("Distance: %f \n", Controller_U_D_M);    // Call read_cm() to get the distance in cm
+    led_B = Controller_Y_LED_BLUE;
+    led_R = Controller_Y_LED_RED;
+}
+
+void rt_OneStep(RT_MODEL_Controller_T *const Controller_M)
+{
+    static boolean_T OverrunFlag = false;
+
+    /* Disable interrupts here */
+
+    /* Check for overrun */
+    if (OverrunFlag) {
+        rtmSetErrorStatus(Controller_M, "Overrun");
+        return;
+    }
+
+    OverrunFlag = true;
+
+    /* Save FPU context here (if necessary) */
+    /* Re-enable timer or interrupt here */
+    /* Set model inputs here */
+
+    /* Step the model */
+    Controller_step(Controller_M, Controller_U_V, Controller_U_D_M,
+                    Controller_U_SLAVE, &Controller_Y_BRAKE,
+                    &Controller_Y_LED_BLUE, &Controller_Y_LED_RED,
+                    &Controller_Y_MASTER);
+
+    /* Get model outputs here */
+
+    /* Indicate task complete */
+    OverrunFlag = false;
+
+    /* Disable interrupts here */
+    /* Restore FPU context here (if necessary) */
+    /* Enable interrupts here */
 }
\ No newline at end of file