FSG / Mbed 2 deprecated 7_21_17_FSG

Dependencies:   BCEmotor Battery_Linear_Actuator Controller_ IMU_code_ LTC1298_7_14 MODSERIAL PosVelFilter_7_14 System mbed

Fork of 7_20_17_FSG_ by FSG

Revision:
8:9b9431404db7
Parent:
7:10d7fbac30ea
Child:
9:2dcfd6ce61ea
diff -r 10d7fbac30ea -r 9b9431404db7 main.cpp
--- a/main.cpp	Fri Jul 21 15:25:11 2017 +0000
+++ b/main.cpp	Tue Jul 25 17:41:34 2017 +0000
@@ -17,6 +17,7 @@
 extern "C" void mbed_reset();   //utilized to reset the mbed through the serial terminal
 
 char Key;
+float input_num;
 
 string IMU_STRING = "";
 
@@ -50,11 +51,17 @@
 float la_D_gain = 0.00;
 /* PID LOOP STUFF */
 
+int count_while = 0;
+
 float IMU_pitch_angle;
 double double_actual_position = 0.00;
 
 string MC_readable_string = "";
 
+int IMU_count = 0;
+int Pr_count = 0;
+int BCE_count = 0;
+
 void IMU_ticking()
 {
     //led1 = !led1;   //flash the IMU LED
@@ -65,7 +72,7 @@
 
 void PRESSURE_ticking()
 {
-    PC.printf("pressure: %f psi \r", (0.00122*(adc().ch1_filt)*9.9542)-0.0845);    //read the analog pin
+    PC.printf("pressure: %f psi \n", (0.00122*(adc().ch1_filt)*9.9542)-0.0845);    //read the analog pin
     //this voltage has been checked and scaled properly (6/28/2017)
 }
 
@@ -74,6 +81,7 @@
     PC.printf("BE_pos: %3.0f mm  BE_vel: %2.2f mm/s  Set Point %3.0f  controller output: % 1.3f \n", pvf().getPosition(), pvf().getVelocity(), positionCmd, posCon().getOutput());
 }
 
+
 int main()
 {  
     PC.baud(9600);          //mbed to PC serial connection speed
@@ -104,7 +112,6 @@
     wait(10); //for debugging
                 
 
-    float motor_cmd = 0.0;
     float P = 0.10;
     float I = 0.00;
     float D = 0.00;
@@ -120,16 +127,17 @@
     float bce_auto_step = 0.1;
     float volume_bce = 1.0;
     int bce_man_step = 50;
-    float positionCmd_temp;
+    
+    float ticker_step_size = 1.0;
     
     //set the intial gains for the position controller
-    /*posCon().setPgain(P);
+    posCon().setPgain(P);
     posCon().setIgain(I);
     posCon().setDgain(D);
     posCon().writeSetPoint(positionCmd);
     hBridge().reset();
-    hBridge().run(motor_cmd);
-    */
+    //hBridge().run(motor_cmd);
+    
     /* *************************** LED *************************** */
     led1 = 1;   //initial values
     led2 = 1;
@@ -137,29 +145,7 @@
     led4 = 1;    
     /* *************************** LED *************************** */
     
-    //PC.printf("Program Started 6/5/17\n");
-    int count_while = 0;
-    //hBridge().reset();
-    //PC.printf("\n```````````Linear Actuator in IMU controlled mode````````````\n\n");
-    //PC.printf("Hit shift + \"H\" to home the battery Linear Actuator\n");
-    
-    /* *************************** Potentiometer *************************** */
-    //PRESSURE_ticker.attach(&PRESSURE_ticking, 3.0);
-    /* *************************** Potentiometer *************************** */
-    
-    /* *************************** MOTOR CONTROLLER *************************** */
-    //Battery_Linear_Actuator BLA_object;               //create the IMU object from the imported class
-    /* *************************** MOTOR CONTROLLER *************************** */
-    
-    /* *************************** IMU *************************** */
-    IMU_code IMU_object;               //create the IMU object from the imported class
-    IMU_ticker.attach(&IMU_ticking, 5.0);
-    /* *************************** IMU *************************** */
-    
-    /* *************************** BCE *************************** */
-    //float previous_positionCmd = -1;
-    //BCE_ticker.attach(&BCE_ticking, 10.0);
-    /* *************************** BCE *************************** */
+    IMU_code IMU_object; 
     
     while(1) 
     {
@@ -244,7 +230,73 @@
                 wait(1); //for debugging      
                 // "-999999" means it is not working  
             }
-            
+            else if (Key == '3' or Key == '#')
+            {
+                PC.printf("Ticker Sensor Step Size\n");
+                if (ticker_step_size == 1.0)
+                {
+                    ticker_step_size = 5.0;
+                }
+                else if (ticker_step_size == 5.0)
+                {
+                    ticker_step_size = 10.0;
+                }
+                else if (ticker_step_size == 10.0)
+                {
+                    ticker_step_size = 20.0;
+                }
+                else if (ticker_step_size == 20.0)
+                {
+                    ticker_step_size = 1.0;
+                }
+                PC.printf("Ticker Step Size is %f\n", ticker_step_size);
+            }
+            else if (Key =='4' or Key == '$')
+            {
+                if (IMU_count == 0)
+                {
+                    PC.printf("IMU turned on! Ticker time is %f seconds\n", ticker_step_size);
+                    IMU_ticker.attach(&IMU_ticking, ticker_step_size);
+                    IMU_count = 1;
+                }
+                else if (IMU_count == 1)
+                {
+                    PC.printf("IMU turned off!\n");
+                    IMU_ticker.detach();
+                    IMU_count = 0;
+                }
+                    
+            }
+            else if (Key == '5' or Key == '%')
+            {
+                if (Pr_count == 0)
+                {
+                    PC.printf("Pressure turned on!  Ticker time is %f seconds\n", ticker_step_size);
+                    PRESSURE_ticker.attach(&PRESSURE_ticking, ticker_step_size);
+                    Pr_count = 1;
+                }
+                else if (Pr_count == 1)
+                {
+                    PC.printf("Pressure turned off!\n");
+                    PRESSURE_ticker.detach();
+                    Pr_count = 0;
+                }
+            }
+            else if (Key == '6' or Key == '^')
+            {
+                if (BCE_count == 0)
+                {
+                    PC.printf("BCE turned on!  Ticker time is %f seconds\n", ticker_step_size);
+                    BCE_ticker.attach(&BCE_ticking, ticker_step_size);
+                    BCE_count = 1;
+                }
+                else if (BCE_count == 1)
+                {
+                    PC.printf("BCE turned off!\n");
+                    BCE_ticker.detach();
+                    BCE_count = 0;
+                }
+            }
         //Buoyancy Engine Controls
             else if (Key == ',' or Key == '<')
             {
@@ -408,7 +460,7 @@
                 }
             }
             else if (Key == 'l' or Key == 'L') 
-                PC.printf("DEBUG: String position? %f velocity? %f (BCE active: %f)\n", pvf().getPosition(), pvf().getVelocity(),posCon().getOutput()); //DEBUG TROY
+                PC.printf("DEBUG: String position? %f set position? %f velocity? %f (BCE active: %f)\n", pvf().getPosition(), positionCmd, pvf().getVelocity(),posCon().getOutput()); //DEBUG TROY
             
         //Linear Actuator Controls
             else if(Key == 'c' or Key == 'C')
@@ -653,6 +705,7 @@
             positionCmd= 375;
             posCon().writeSetPoint(positionCmd);
             hBridge().run(posCon().getOutput());
+            wait(2);
         }
     
         //string snaps