Code for the COVR project DROPSAW project test rig (previously used for the Heros testing).

Dependencies:   SPTE_10Bar_5V mbed AS5048 SDFileSystem MODSERIAL LCM101_DROPSAW LinearActuator

Revision:
15:a84d54e25775
Parent:
14:dd4193213be9
--- a/main.cpp	Mon Oct 26 08:33:02 2020 +0000
+++ b/main.cpp	Mon Oct 26 11:55:27 2020 +0000
@@ -28,9 +28,9 @@
 #include "bench.h"
  
 //Methods describing the tests
-void runFatigueExperiment0(int cycles, float targetkPa, float inflateTimeOut,float deflateTimeOut);
-void runFailureExperiment0(float targetkPa);
-void runBenchmarkExperiment0();
+void runFatigueExperiment0(int cycles, float targetkPa, float inflateTimeOut,float deflateTimeOut,int logHz);
+void runFailureExperiment0(float targetkPa,int logHz);
+void runBenchmarkExperiment0(int logHz);
 void runBenchmarkExperiment1(int minForce, float maxAngle, float inflationT, int pwm, int cycles, int logHz);
 
 // Create bench object - this is used to control the test rig
@@ -40,17 +40,27 @@
  * Main loop
  */
 int main()
-{   
-    leg.setLoggingFrequency(10); //Set datalogging frequency (Hz)
-    
+{       
     /* Two extra columns of data will be recorded in this experiment.
     One for the target pressure, and the other for the number of inflation-deflation
     cycles currently completed in the experiment */ 
-    string colNames[] = {"Target pressure (kPa)","Cycle",}; //add data headings
+    string colNames[] = {"Target pressure (kPa)","Cycle"}; //add data headings
     leg.setExtraColumns(colNames,2);
     
-    float targetP = 300; //Pressure at which inflation is stopped and deflation begins (kPa)                                                                                                                                                                                       
-    int expCycles = 40; //Number of inflation cycles 
+    int logHz = 10; //(Hz) datalogging frequency
+    float targetP = 300; //Pressure at which inflation is stopped and deflation begins (kPa)  
+                                                                                                                                                                                         
+    int fatCycles = 40; //Number of inflation cycles for the fatigue test    
+    float infTimeAllow = 10;// (s) time allowed for inflation in a fatigue cycle
+    float defTimeAllow = 10;// (s) time allowed for deflation in a fatigue cycle
+    
+    //for benchmark experiment
+    float minForce = 5;//(N) force threshold at which leg extension changes to flexion
+    float maxAngle = 70;//(deg) angle threshold at which leg flexion changes to extension
+    float inflationTime = 3;//(s) time actuator given to inflate before starting experiment
+    int pwm = 75; //(%) linear actuator motor pwm
+    int benchCycles = 1;//(-) number of flexion/extension cycles
+    
     float vals[] = {targetP,0}; //set of initial values of data that will be logged
     leg.setExtraData(vals);
     
@@ -62,14 +72,16 @@
     stop it if the button is pressed again to stop datalogging 
     (or when experiment stops - then datalogging stops by itself) */
     while (true) {
-        if (leg.isLogging()) {
-            leg.pc.printf("Logging started");
-            runFatigueExperiment0(expCycles,targetP,10,10);
-            //runBenchmarkExperiment0();
-            runBenchmarkExperiment1(5, 70, 3, 75, 1, 10);
-            //runFailureExperiment0(targetP);        
+        if (leg.isLogging()) {//check if logging has started, if so, run an experiment procedure
+            leg.pc.printf("Logging started");//user feedback
+            
+            //uncomment the type of experiment you want to try
+            runFatigueExperiment0(fatCycles,targetP,infTimeAllow,defTimeAllow,logHz);
+            //runBenchmarkExperiment0(logHz);
+            //runBenchmarkExperiment1(minForce, maxAngle, inflationTime, pwm, benchCycles, logHz);
+            //runFailureExperiment0(targetP,logHz);        
         }
-        wait(0.5);
+        wait(0.5);//wait a bit before checking again
     }
 }
 
@@ -81,13 +93,19 @@
  * @param targetkPa: the pressure at which the valve is opened to let the leg go down (kPa)
  * @param inflateTimeOut: (s) if inflation takes longer than this, experiment is assumed to fail and stops, saving data
  * @param deflateTimeOut: (s) if deflation takes longer than this, experiment is assumed to fail and stops, saving data
+ * @param logHz: datalogging frequency
  */
-void runFatigueExperiment0(int cycles, float targetkPa, float inflateTimeOut, float deflateTimeOut) 
+void runFatigueExperiment0(int cycles, float targetkPa, float inflateTimeOut, float deflateTimeOut,int logHz) 
 {
     //method constants
     Timer flowT;//timer used to time flow into and out of actuator
-    float loopTime = 0.1; //(s) time between checking pressure
-    int num_file = 1; //number of data files to save 
+        
+    float loopTime = 1/logHz; //(s) time between checking pressure
+    
+    //number of data files to save (so we can create a safety barrier 
+    //when lots of cycles are done e.g. you may want 100 cycles in each file 
+    //so if something goes wrong, you will have most of the data, to within a 100 cycles)    
+    int num_file = 1; 
     
     for (int i=0; i<num_file; i++) {
         //record data
@@ -165,6 +183,7 @@
 
         /* Logging stopped as experiment is fully completed (desired number of cycles
         reached)*/
+        leg.pc.printf("\r\nExit Fatigue Test");
         leg.setValve(false); //Depressurise
         leg.StopLogging(); //Stop logging data
         leg.resumePrint(); //Let the Bench class print
@@ -177,11 +196,13 @@
  * increasing the actuator pressure by manually opening up the pressure regulator
  * connected to the actuator. It is also assumed that the user will stop inflation 
  * if they deem the actuator to have failed.
- * Data is recorded at ~10Hz.
  * @param targetkPa: the pressure at which the valve is opened to deflate the actuator (kPa)
+ * @param logHz: datalogging frequency
  */
-void runFailureExperiment0(float targetkPa) 
+void runFailureExperiment0(float targetkPa,int logHz) 
 {    
+    double logTime = 1/logHz;//s interval between logging data
+
     //Pressurise the actuator under test
     leg.StartLogging();
     leg.setValve(true);
@@ -191,12 +212,12 @@
     while(leg.isLogging() && (leg.getPressure0()*100 < targetkPa)) {        
         leg.pc.printf("\r\nPressure (kPa): \t%7.2f",leg.getPressure0()*100);//print the pressure
         leg.LogData();//record a datapoint
-        wait(0.1);//wait
+        wait(logTime);//wait
     }
     
     //Depressurise when the user is done with benchmarking or the target pressure is
     //reached    
-    leg.pc.printf("\r\nExit Benchmarking Test");
+    leg.pc.printf("\r\nExit Failure Test");
     leg.setValve(false);
     leg.StopLogging(); //Stop logging data
     leg.resumePrint(); //Let the Bench class print    
@@ -205,17 +226,19 @@
 /**
  * A method used to benchmark the actuator under test before the linear actuator
  * was fitted to the test rig. It simply pressurises the actuator and records data
- * at ~10 Hz
+ * @param logHz: datalogging frequency
  */
-void runBenchmarkExperiment0()
+void runBenchmarkExperiment0(int logHz)
 {
+    double logTime = 1/logHz;//s interval between logging data
+    
     //Pressurise the actuator under test
     leg.StartLogging();
     leg.setValve(true);//inflation
     while(leg.isLogging()) {//until the user presses the key to stop datalogging        
         leg.pc.printf("\r\nPressure (kPa): \t%7.2f",leg.getPressure0()*100); //print the pressure
         leg.LogData();//record a datapoint
-        wait(0.1);//wait
+        wait(logTime);//wait
     }
     
     //Depressurise when the user is done with benchmarking   
@@ -226,8 +249,8 @@
 }
 
 /**
- * A benchmark test with the linear actuator. The actuator is cycled from its flexed position
- * to the point at which it no longer produces force. This is considered its range of motion.
+ * A benchmark test with the linear actuator. The actuator is cycled from its flexed position,
+ * to the point at which it no longer produces force, and back again. This is considered its range of motion.
  * NOTE - not extensively tested
  * @param minForce: (N) force at which cycle goes from extension to flexion
  * @param maxAngle: (deg) angle at which cycle goes from flexion to extension
@@ -270,7 +293,8 @@
             wait(logTime);//wait
         }
         
-        if (!leg.isLogging()) {//If the user stopped
+        //If the user stopped
+        if (!leg.isLogging()) {
             leg.pc.printf("\r\nUser stopped during extension Exit");
             leg.setPWM(0); //turn off linear actuator
             leg.setValve(false);//Depressurise
@@ -292,7 +316,8 @@
             wait(logTime);//wait
         }
         
-        if (!leg.isLogging()) {//If the user stopped
+        //If the user stopped
+        if (!leg.isLogging()) {
             leg.pc.printf("\r\nUser stopped during flexion Exit");
             leg.setPWM(0); 
             leg.setValve(false);//Depressurise