MBSD / Mbed 2 deprecated AEB_TERATERM

Dependencies:   mbed

Fork of AEB by Vincenzo Comito

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AEB0.cpp Source File

AEB0.cpp

00001 /*
00002  * Academic License - for use in teaching, academic research, and meeting
00003  * course requirements at degree granting institutions only.  Not for
00004  * government, commercial, or other organizational use.
00005  *
00006  * File: AEB0.c
00007  *
00008  * Code generated for Simulink model 'AEB0'.
00009  *
00010  * Model version                  : 1.77
00011  * Simulink Coder version         : 8.10 (R2016a) 10-Feb-2016
00012  * C/C++ source code generated on : Thu Jul 28 19:46:51 2016
00013  *
00014  * Target selection: ert.tlc
00015  * Embedded hardware selection: Intel->x86-64 (Windows64)
00016  * Code generation objectives: Unspecified
00017  * Validation result: Not run
00018  */
00019 
00020 #include "AEB0.h"
00021 #include "AEB0_private.h"
00022 
00023 /* Named constants for Chart: '<Root>/AEB ' */
00024 #define AEB0_IN_AEB_misbehaviour       ((uint8_T)1U)
00025 #define AEB0_IN_AEB_ok                 ((uint8_T)2U)
00026 #define AEB0_IN_NO_ACTIVE_CHILD        ((uint8_T)0U)
00027 #define AEB0_IN_brake_fault            ((uint8_T)1U)
00028 #define AEB0_IN_brake_off_             ((uint8_T)1U)
00029 #define AEB0_IN_brake_on_              ((uint8_T)2U)
00030 #define AEB0_IN_ok                     ((uint8_T)1U)
00031 #define AEB0_IN_ok2                    ((uint8_T)3U)
00032 #define AEB0_IN_zero_dist              ((uint8_T)2U)
00033 #define AEB0_IN_zero_dist_fault        ((uint8_T)3U)
00034 #define AEB0_div                       (100.0)
00035 
00036 /* Block states (auto storage) */
00037 DW_AEB0_T AEB0_DW;
00038 
00039 /* External inputs (root inport signals with auto storage) */
00040 ExtU_AEB0_T AEB0_U;
00041 
00042 /* External outputs (root outports fed by signals with auto storage) */
00043 ExtY_AEB0_T AEB0_Y;
00044 
00045 /* Real-time model */
00046 RT_MODEL_AEB0_T AEB0_M_;
00047 RT_MODEL_AEB0_T *const AEB0_M = &AEB0_M_;
00048 
00049 /* Model step function */
00050 void AEB0_step(void)
00051 {
00052   /* Chart: '<Root>/AEB ' incorporates:
00053    *  Inport: '<Root>/distance_m'
00054    *  Inport: '<Root>/speed_km_h'
00055    */
00056   if (AEB0_DW.temporalCounter_i1 < 7U) {
00057     AEB0_DW.temporalCounter_i1++;
00058   }
00059 
00060   if (AEB0_DW.temporalCounter_i2 < 7U) {
00061     AEB0_DW.temporalCounter_i2++;
00062   }
00063 
00064   /* Gateway: AEB
00065    */
00066   /* During: AEB
00067    */
00068   if (AEB0_DW.is_active_c3_AEB0 == 0U) {
00069     /* Entry: AEB
00070      */
00071     AEB0_DW.is_active_c3_AEB0 = 1U;
00072 
00073     /* Entry Internal: AEB
00074      */
00075     /* Transition: '<S1>:37' */
00076     AEB0_DW.is_AEB_distance_sensor_fault_de = AEB0_IN_ok;
00077 
00078     /* Outport: '<Root>/fault' */
00079     /* Entry 'ok': '<S1>:21' */
00080     /* '<S1>:21:1' fault=0 */
00081     AEB0_Y.fault = 0.0;
00082 
00083     /* Entry Internal 'AEB_brake_fault_detection': '<S1>:41' */
00084     /* Transition: '<S1>:44' */
00085     AEB0_DW.is_AEB_brake_fault_detection = AEB0_IN_ok2;
00086 
00087     /* Entry Internal 'AEB_ALGO': '<S1>:40' */
00088     /* Transition: '<S1>:4' */
00089     AEB0_DW.is_AEB_ALGO = AEB0_IN_AEB_ok;
00090     AEB0_DW.is_AEB_ok = AEB0_IN_brake_off_;
00091 
00092     /* Outport: '<Root>/brake' */
00093     /* Entry 'brake_off_': '<S1>:3' */
00094     /* '<S1>:3:1' brake=0 */
00095     AEB0_Y.brake = 0.0;
00096   } else {
00097     /* During 'AEB': '<S1>:39' */
00098     /* During 'AEB_fault_detection': '<S1>:43' */
00099     /* During 'AEB_distance_sensor_fault_detection': '<S1>:42' */
00100     switch (AEB0_DW.is_AEB_distance_sensor_fault_de) {
00101      case AEB0_IN_ok:
00102       /* During 'ok': '<S1>:21' */
00103       /* '<S1>:23:1' sf_internal_predicateOutput = ... */
00104       /* '<S1>:23:1' distance_m == 0; */
00105       if (AEB0_U.distance_m == 0.0) {
00106         /* Transition: '<S1>:23' */
00107         AEB0_DW.is_AEB_distance_sensor_fault_de = AEB0_IN_zero_dist;
00108         AEB0_DW.temporalCounter_i1 = 0U;
00109       }
00110       break;
00111 
00112      case AEB0_IN_zero_dist:
00113       /* During 'zero_dist': '<S1>:28' */
00114       /* '<S1>:24:1' sf_internal_predicateOutput = ... */
00115       /* '<S1>:24:1' distance_m > 0; */
00116       if (AEB0_U.distance_m > 0.0) {
00117         /* Transition: '<S1>:24' */
00118         AEB0_DW.is_AEB_distance_sensor_fault_de = AEB0_IN_ok;
00119 
00120         /* Outport: '<Root>/fault' */
00121         /* Entry 'ok': '<S1>:21' */
00122         /* '<S1>:21:1' fault=0 */
00123         AEB0_Y.fault = 0.0;
00124       } else {
00125         /* '<S1>:26:1' sf_internal_predicateOutput = ... */
00126         /* '<S1>:26:1' after(500, msec); */
00127         if (AEB0_DW.temporalCounter_i1 >= 5U) {
00128           /* Transition: '<S1>:26' */
00129           AEB0_DW.is_AEB_distance_sensor_fault_de = AEB0_IN_zero_dist_fault;
00130 
00131           /* Outport: '<Root>/fault' */
00132           /* Entry 'zero_dist_fault': '<S1>:25' */
00133           /* '<S1>:25:1' fault=1 */
00134           AEB0_Y.fault = 1.0;
00135         }
00136       }
00137       break;
00138 
00139      default:
00140       /* During 'zero_dist_fault': '<S1>:25' */
00141       break;
00142     }
00143 
00144     /* During 'AEB_brake_fault_detection': '<S1>:41' */
00145     switch (AEB0_DW.is_AEB_brake_fault_detection) {
00146      case AEB0_IN_brake_fault:
00147       /* During 'brake_fault': '<S1>:34' */
00148       break;
00149 
00150      case AEB0_IN_brake_on_:
00151       /* During 'brake_on_': '<S1>:32' */
00152       /* '<S1>:35:1' sf_internal_predicateOutput = ... */
00153       /* '<S1>:35:1' (after(500, msec)) && (speed_km_h>=speed_at_brake_start &&  speed_km_h > 0 && brake>0.1); */
00154       if ((AEB0_DW.temporalCounter_i2 >= 5U) && (AEB0_U.speed_km_h >=
00155            AEB0_DW.speed_at_brake_start) && (AEB0_U.speed_km_h > 0.0) &&
00156           (AEB0_Y.brake > 0.1)) {
00157         /* Transition: '<S1>:35' */
00158         AEB0_DW.is_AEB_brake_fault_detection = AEB0_IN_brake_fault;
00159 
00160         /* Outport: '<Root>/fault' */
00161         /* Entry 'brake_fault': '<S1>:34' */
00162         /* '<S1>:34:1' fault=1 */
00163         AEB0_Y.fault = 0.0;
00164       } else {
00165         /* '<S1>:46:1' sf_internal_predicateOutput = ... */
00166         /* '<S1>:46:1' (after(500, msec)) && (speed_km_h<speed_at_brake_start); */
00167         if ((AEB0_DW.temporalCounter_i2 >= 5U) && (AEB0_U.speed_km_h <
00168              AEB0_DW.speed_at_brake_start)) {
00169           /* Transition: '<S1>:46' */
00170           AEB0_DW.is_AEB_brake_fault_detection = AEB0_IN_brake_on_;
00171           AEB0_DW.temporalCounter_i2 = 0U;
00172 
00173           /* Entry 'brake_on_': '<S1>:32' */
00174           /* '<S1>:32:1' speed_at_brake_start = speed_km_h */
00175           AEB0_DW.speed_at_brake_start = AEB0_U.speed_km_h;
00176         } else {
00177           /* '<S1>:47:1' sf_internal_predicateOutput = ... */
00178           /* '<S1>:47:1' brake==0; */
00179           if (AEB0_Y.brake == 0.0) {
00180             /* Transition: '<S1>:47' */
00181             AEB0_DW.is_AEB_brake_fault_detection = AEB0_IN_ok2;
00182           }
00183         }
00184       }
00185       break;
00186 
00187      default:
00188       /* During 'ok2': '<S1>:31' */
00189       /* '<S1>:33:1' sf_internal_predicateOutput = ... */
00190       /* '<S1>:33:1' brake==1; */
00191       if (AEB0_Y.brake == 1.0) {
00192         /* Transition: '<S1>:33' */
00193         AEB0_DW.is_AEB_brake_fault_detection = AEB0_IN_brake_on_;
00194         AEB0_DW.temporalCounter_i2 = 0U;
00195 
00196         /* Entry 'brake_on_': '<S1>:32' */
00197         /* '<S1>:32:1' speed_at_brake_start = speed_km_h */
00198         AEB0_DW.speed_at_brake_start = AEB0_U.speed_km_h;
00199       }
00200       break;
00201     }
00202 
00203     /* During 'AEB_ALGO': '<S1>:40' */
00204     if (AEB0_DW.is_AEB_ALGO != AEB0_IN_AEB_misbehaviour) {
00205       /* During 'AEB_ok': '<S1>:14' */
00206       /* '<S1>:16:1' sf_internal_predicateOutput = ... */
00207       /* '<S1>:16:1' fault==1; */
00208       if (AEB0_Y.fault == 1.0) {
00209         /* Transition: '<S1>:16' */
00210         /* Exit Internal 'AEB_ok': '<S1>:14' */
00211         AEB0_DW.is_AEB_ok = AEB0_IN_NO_ACTIVE_CHILD;
00212         AEB0_DW.is_AEB_ALGO = AEB0_IN_AEB_misbehaviour;
00213 
00214         /* Outport: '<Root>/brake' */
00215         /* Entry 'AEB_misbehaviour': '<S1>:15' */
00216         /* '<S1>:15:1' brake=0 */
00217         AEB0_Y.brake = 0.0;
00218       } else if (AEB0_DW.is_AEB_ok == AEB0_IN_brake_off_) {
00219         /* During 'brake_off_': '<S1>:3' */
00220         /* '<S1>:5:1' sf_internal_predicateOutput = ... */
00221         /* '<S1>:5:1' speed_km_h^2/div>distance_m; */
00222         if (AEB0_U.speed_km_h * AEB0_U.speed_km_h / AEB0_div > AEB0_U.distance_m)
00223         {
00224           /* Transition: '<S1>:5' */
00225           AEB0_DW.is_AEB_ok = AEB0_IN_brake_on_;
00226 
00227           /* Outport: '<Root>/brake' */
00228           /* Entry 'brake_on_': '<S1>:1' */
00229           /*  brake is proportional to the inverse of distance */
00230           /*  and to the speed. This was required */
00231           /*  since it was requested that the led frequency */
00232           /*  must be proportional to the brake request */
00233           /* '<S1>:1:3' brake=1 */
00234           AEB0_Y.brake = 1.0;
00235         }
00236       } else {
00237         /* During 'brake_on_': '<S1>:1' */
00238         /* '<S1>:6:1' sf_internal_predicateOutput = ... */
00239         /* '<S1>:6:1' speed_km_h^2/div<distance_m; */
00240         if (AEB0_U.speed_km_h * AEB0_U.speed_km_h / AEB0_div < AEB0_U.distance_m)
00241         {
00242           /* Transition: '<S1>:6' */
00243           AEB0_DW.is_AEB_ok = AEB0_IN_brake_off_;
00244 
00245           /* Outport: '<Root>/brake' */
00246           /* Entry 'brake_off_': '<S1>:3' */
00247           /* '<S1>:3:1' brake=0 */
00248           AEB0_Y.brake = 0.0;
00249         }
00250       }
00251     } else {
00252       /* During 'AEB_misbehaviour': '<S1>:15' */
00253     }
00254   }
00255 
00256   /* End of Chart: '<Root>/AEB ' */
00257 }
00258 
00259 /* Model initialize function */
00260 void AEB0_initialize(void)
00261 {
00262   /* Registration code */
00263 
00264   /* initialize error status */
00265   rtmSetErrorStatus(AEB0_M, (NULL));
00266 
00267   /* states (dwork) */
00268   (void) memset((void *)&AEB0_DW, 0,
00269                 sizeof(DW_AEB0_T));
00270 
00271   /* external inputs */
00272   (void) memset((void *)&AEB0_U, 0,
00273                 sizeof(ExtU_AEB0_T));
00274 
00275   /* external outputs */
00276   (void) memset((void *)&AEB0_Y, 0,
00277                 sizeof(ExtY_AEB0_T));
00278 
00279   /* SystemInitialize for Chart: '<Root>/AEB ' */
00280   AEB0_DW.is_AEB_ALGO = AEB0_IN_NO_ACTIVE_CHILD;
00281   AEB0_DW.is_AEB_ok = AEB0_IN_NO_ACTIVE_CHILD;
00282   AEB0_DW.is_AEB_brake_fault_detection = AEB0_IN_NO_ACTIVE_CHILD;
00283   AEB0_DW.temporalCounter_i2 = 0U;
00284   AEB0_DW.is_AEB_distance_sensor_fault_de = AEB0_IN_NO_ACTIVE_CHILD;
00285   AEB0_DW.temporalCounter_i1 = 0U;
00286   AEB0_DW.is_active_c3_AEB0 = 0U;
00287 
00288   /* SystemInitialize for Outport: '<Root>/fault' incorporates:
00289    *  SystemInitialize for Chart: '<Root>/AEB '
00290    */
00291   AEB0_Y.fault = 0.0;
00292 }
00293 
00294 /* Model terminate function */
00295 void AEB0_terminate(void)
00296 {
00297   /* (no terminate code required) */
00298 }
00299 
00300 /*
00301  * File trailer for generated code.
00302  *
00303  * [EOF]
00304  */