ediff iitb / Mbed 2 deprecated HIL_FMEA_oursteering

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ediff_iitbracing
Date:
Wed Mar 06 19:20:02 2013 +0000
Parent:
1:fec1d091fa34
Commit message:
Test publish

Changed in this revision

algo.cpp Show annotated file Show diff for this revision Revisions of this file
define_variables.h Show annotated file Show diff for this revision Revisions of this file
fmea.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/algo.cpp	Wed Mar 06 13:58:03 2013 +0000
+++ b/algo.cpp	Wed Mar 06 19:20:02 2013 +0000
@@ -6,6 +6,8 @@
 //Output array is stored in array
 //Output is linearly interpolated
 
+float pid_output = 0;
+
 float turnradiusfunction(float steering)
 {
     float steering_high,steering_range;
@@ -46,13 +48,13 @@
 //Further evalutes desired throttle left and right values from PID output and throttle input
 void pid()
 {   
-      // if any rpm values is zero, make it 10
-      if (rpm_Left <= 0)
+      // if any rpm values leas than 10, make it 10
+      if (rpm_Left <= dead_rpm)
       {
           rpm_Left = dead_rpm;
       }
     
-      if (rpm_Right <= 0)
+      if (rpm_Right <= dead_rpm)
       {
           rpm_Right = dead_rpm;
       }    
@@ -82,21 +84,28 @@
       }    
     
       //pid calculations
-    
-      wratio_actual = rpm_Right/rpm_Left;
       
-      error_new = wratio_desired - wratio_actual;                                  //error
-      derivative = (error_new-error_prev)/timeint;                                 //derivative of error            
-      if(integral < integral_saturation)                                           //saturate the integral part 
+      if (!openloop)
       {
-          integral += error_new*timeint;                                           //integral of error
-      }   
-      
-      float pid_output =  kp*error_new + ki*integral + kd*derivative + c;               //PID output
- 
-      error_prev = error_new;
+          wratio_actual = rpm_Right/rpm_Left;
+          
+          error_new = wratio_desired - wratio_actual;                                  //error
+          derivative = (error_new-error_prev)/timeint;                                 //derivative of error            
+          if(integral < integral_saturation)                                           //saturate the integral part 
+          {
+              integral += error_new*timeint;                                           //integral of error
+          }   
+          
+          pid_output =  kp*error_new + ki*integral + kd*derivative + c;               //PID output
+     
+          error_prev = error_new;
+      }
+      else
+      {
+          pid_output = 0;
+      }
       w_ratio = pid_output + wratio_desired;                                        //w ratio desired after feedback
-   
+        
       throttle_Right = 2*throttle/(1+1/w_ratio);                                    // V1, V2 from throttle input and w ratio desired after feedback
       throttle_Left = 2*throttle/(1+w_ratio);
  
--- a/define_variables.h	Wed Mar 06 13:58:03 2013 +0000
+++ b/define_variables.h	Wed Mar 06 19:20:02 2013 +0000
@@ -51,6 +51,10 @@
 extern float rpm_Left;
 extern float rpm_Right;
 
+//Openloop Flag
+extern volatile bool openloop;
+extern const float rpm_openloop_limit;
+
 //PID constants
 extern float kp;
 extern float kd;
--- a/fmea.cpp	Wed Mar 06 13:58:03 2013 +0000
+++ b/fmea.cpp	Wed Mar 06 19:20:02 2013 +0000
@@ -3,7 +3,7 @@
 //FMEA - Failure Mode Error Analysis codes.
 //Checks involve the following sensors:
 //LEFT THROTTLE, RIGHT THROTTLE, 
-//STEERING 1 (CAN Steering Sensor), STEERING 2 (Rotary Potentiometer),
+//STEERING 1 (CAN Steering Sensor), STEERING 2 (Linear Potentiometer),
 //LEFT WHEEL RPM and RIGHT WHEEL RPM.
 
 //FMEA parameters
@@ -24,7 +24,6 @@
 //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;
--- a/main.cpp	Wed Mar 06 13:58:03 2013 +0000
+++ b/main.cpp	Wed Mar 06 19:20:02 2013 +0000
@@ -45,6 +45,10 @@
 float turnradius;
 float wratio_desired;                                                   //Right/Left
 
+//Opeloop Flag
+volatile bool openloop_lowrpm = true;
+const float rpm_openloop_limit = 100;
+
 //PID constants
 float kp=0;
 float kd=0;
@@ -205,10 +209,18 @@
         Prev_time_Left = Current_time_Left;                             // Set Current Reading as previous reading for next iteration
         cnt_Left = 0;                                                   //Reset Count
         rpm_Left = 1 / ( time_elapsed_Left  / (1000000*60) );           //Evaluate RPM from time for 1 revolution
+        if (rpm_Left < rpm_openloop_limit)
+        {
+            openloop_lowrpm = true;
+        }
+        else
+        {
+            openloop_lowrpm = false;
+        }
         displayLeftrpm = true;                                          //Display RPM - for testing purposes only
     }
     
-    if (MissingTeethCheckLeft)                                          //Called every 10 sec
+    if (MissingTeethCheckLeft && !openloop_lowrpm)                                          //Called every 10 sec
     {
          countLeftMissingTeeth++;        
          if (countLeftMissingTeeth == 1)                                //No comparisons for first tooth ( 12th is compared with first)
@@ -258,10 +270,14 @@
         Prev_time_Right = Current_time_Right;                             // Set Current Reading as previous reading for next iteration
         cnt_Right = 0;                                                    //Reset Count
         rpm_Right = 1 / ( time_elapsed_Right  / (1000000*60) );           //Evaluate RPM from time for 1 revolution
+         if (rpm_Right < rpm_openloop_limit)
+        {
+            openloop_lowrpm = true;
+        }
         displayRightrpm = true;                                           //Evaluate RPM from time for 1 revolution
      }
     
-    if (MissingTeethCheckRight)                                           //Called every 10 sec
+    if (MissingTeethCheckRight && !openloop_lowrpm)                                           //Called every 10 sec
     {
          countRightMissingTeeth++;        
          if (countRightMissingTeeth == 1)                                 //No comparisons for first tooth ( 12th is compared with first)