ediff iitb / Mbed 2 deprecated HIL_FMEA_oursteering

Dependencies:   mbed

Revision:
0:30ff725706d2
Child:
1:fec1d091fa34
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fmea.cpp	Tue Mar 05 01:19:30 2013 +0000
@@ -0,0 +1,167 @@
+#include "fmea.h"
+
+//FMEA - Failure Mode Error Analysis codes.
+//Checks involve the following sensors:
+//LEFT THROTTLE, RIGHT THROTTLE, 
+//STEERING 1 (CAN Steering Sensor), STEERING 2 (Rotary Potentiometer),
+//LEFT WHEEL RPM and RIGHT WHEEL RPM.
+
+//FMEA parameters
+const float steering_diff_limit = 7;
+const float throttle_diff_limit = 0.5;
+int fmea_recheck_iteration = 3;
+float fmea_recheck_time = 0.3;
+
+//FMEA counters/trackers
+int flag_steering_comparison = 0;
+int flag_throttle_comparison = 0;
+int flag_steering2_pulldown = 0;
+int flag_rpm_Left_pulldown = 0;
+int flag_rpm_Right_pulldown = 0;
+int flag_throttle_Left_pulldown = 0;
+int flag_throttle_Right_pulldown = 0;
+
+
+//FMEA Flags
+bool flag_use_openloop = false;
+bool flag_use_steering = false;
+bool flag_steering_use = false;
+
+//Ticker for each FMEA function.
+Ticker for_rpm_Left_pulldown_fmea;
+Ticker for_rpm_Right_pulldown_fmea;
+Ticker for_throttle_Left_pulldown_fmea;
+Ticker for_throttle_Right_pulldown_fmea;
+Ticker for_steering2_pulldown_fmea;
+
+//Left RPM sensor fails. Sensor output is pulled down to zero.
+void rpm_Left_pulldown_fmea()
+{
+    for_rpm_Left_pulldown_fmea.detach();
+    if (rpm_Left <= dead_rpm)
+    {
+        flag_rpm_Left_pulldown++;
+        if (flag_rpm_Left_pulldown >= fmea_recheck_iteration)
+        {
+            flag_use_openloop = true;
+            return;
+        }
+        for_rpm_Left_pulldown_fmea.attach(&rpm_Left_pulldown_fmea,fmea_recheck_time);              
+    }
+    else
+    {
+        flag_rpm_Left_pulldown = 0;
+    }
+}
+
+//Right RPM sensor fails. Sensor output is pulled down to zero.
+void rpm_Right_pulldown_fmea()
+{
+    for_rpm_Right_pulldown_fmea.detach();
+    if (rpm_Right <= dead_rpm)
+    {
+        flag_rpm_Right_pulldown++;
+        if (flag_rpm_Right_pulldown >= fmea_recheck_iteration)
+        {
+            flag_use_openloop = true;
+            return;
+        }
+        for_rpm_Right_pulldown_fmea.attach(&rpm_Right_pulldown_fmea,fmea_recheck_time);                   
+    }
+    else
+    {
+        flag_rpm_Right_pulldown = 0;
+    }
+}
+
+//Left Throttle sensor fails. Sensor output is pulled down to zero.
+void throttle_Left_pulldown_fmea()
+{
+    for_throttle_Left_pulldown_fmea.detach(); 
+    if (throttle_Left < 0.1)
+    {
+        flag_throttle_Left_pulldown++;
+        if (flag_throttle_Left_pulldown >= fmea_recheck_iteration)
+        {
+            shutdown = true;
+            return;
+        }
+        for_throttle_Left_pulldown_fmea.attach(&rpm_Left_pulldown_fmea,fmea_recheck_time);                   
+    }
+    else
+    {
+        flag_throttle_Left_pulldown = 0;
+    }
+}
+
+//Right Throttle sensor fails. Sensor output is pulled down to zero.
+void throttle_Right_pulldown_fmea()
+{
+    for_throttle_Right_pulldown_fmea.detach();
+    if (throttle_Right < 0.1)
+    {
+        flag_throttle_Right_pulldown++;
+        if (flag_throttle_Right_pulldown >= fmea_recheck_iteration)
+        {
+            shutdown = true;
+            return;
+        }
+        for_throttle_Right_pulldown_fmea.attach(&rpm_Right_pulldown_fmea,fmea_recheck_time);         
+    }
+    else
+    {
+        flag_throttle_Right_pulldown = 0;
+        return;
+    }
+}
+
+//Steering Sensor 2 (Potentiometer) fails. Sensor output is pulled down to zero.
+void steering2_pulldown_fmea()
+{
+    for_steering2_pulldown_fmea.detach();
+    if (steering2 < 0.1)
+    {
+        flag_steering2_pulldown++;
+        if (flag_steering2_pulldown >= fmea_recheck_iteration)
+        {
+            flag_use_steering = true;
+            return;
+        }
+        for_steering2_pulldown_fmea.attach(&steering2_pulldown_fmea,fmea_recheck_time);                  
+    }
+    else
+    {
+        shutdown = true;
+        return;
+    }
+}
+
+//Check for consistency of the two differently obtained steering values.
+void steering_comparison_fmea()
+{
+    if (!flag_use_steering)
+    {
+        if (abs(steering2-steering) > steering_diff_limit)
+        {
+           flag_steering_comparison++;
+           if (flag_steering_comparison >= fmea_recheck_iteration) 
+           {
+               steering2_pulldown_fmea();
+           }
+           steering_comparison_fmea();
+        }
+        else
+        {
+           flag_steering_comparison = 0;        
+        }
+    }
+}
+
+//Check for consistency of the two differently obtained throttle values.
+void throttle_comparison_fmea()
+{
+    if (abs(throttle2-throttle) > throttle_diff_limit)
+    {
+        shutdown = true;
+    }
+}