HeRoS: read out and log joint angles and force sensor data from the leg test bench. Now with additional features to read pressure sensors and set the null values of the pressure and force sensors

Dependencies:   SPTE_10Bar_5V mbed AS5048 SDFileSystem MODSERIAL PinDetect Valve LCM101

Fork of heros_leg_readout_torque_addition by K K

Revision:
11:b0a6faaa5e9f
Parent:
9:60760807834f
--- a/bench.cpp	Mon Feb 17 15:15:24 2020 +0000
+++ b/bench.cpp	Tue Feb 25 15:04:21 2020 +0000
@@ -344,13 +344,12 @@
 }
 
 /**
- * Start logging data
- * param fname_append: a string describing the name appended to each logged file
+ * Start logging data (opens data logging file)
+ * @param fname_append: a string describing the name appended to each logged file
  * (along with its unique loggging number).
  */
 void Bench::StartLogging(const char * fname_append)
 {    
-    pc.printf("\r\nDATA LOGGING");
     if (sd_card_present) {
 
         // create unique file name
@@ -373,13 +372,43 @@
                     fHeader = fHeader + "," + extraColNames[i];
                 }
             }
-            //pc.printf("%s", fHeader.c_str());
             fprintf(fp_data, "%s", fHeader.c_str());
-            tick_logging.attach_us(this,&Bench::LogData,loggingUS);
+            //tick_logging.attach_us(this,&Bench::LogData,loggingUS);
+            timer.start();
+            startedLogging = true;
+            is_logging = true;
+        }
+    } else {
+        pc.printf("\t> No SD Card; no data will be logged.\r\n");
+        startedLogging = false;
+    }
+}
+
+/**
+ * Restart logging data (opens data logging file)
+ * @param fname_append: a string describing the name appended to each logged file
+ * (along with its unique loggging number).
+ */
+void Bench::RestartLogging(const char * fname_append)
+{    
+    if (sd_card_present) {
+
+        // file name carries on from what we last had
+        char fname[50];
+        sprintf(fname, "/sd/%d_%s.csv",fname_prepend,fname_append);
+
+        pc.printf("\t> Opening data log file '%s'...\r\n",fname);
+
+        // open file for writing and start logging after success
+        fp_data = fopen(fname,"w");
+        if (fp_data==NULL) {
+            pc.printf("\t> ERROR: failed to open log file (t=%d ms)\r\n",
+                      timer.read_ms());
+        } else {            
             timer.start();
             startedLogging = true;
             
-            pc.printf("\t> Logging started.\r\n");
+            pc.printf("\t> Logging file opened.\r\n");
             
             is_logging = true;
         }
@@ -389,7 +418,6 @@
     }
 }
 
-
 /**
  * Stop logging data.
  */
@@ -405,8 +433,7 @@
         Bench::pc.printf("\r> Stopped.");
     } else {
         Bench::pc.printf("\t> No data was logged.");
-    }
-    
+    }    
     is_logging = false;
 }
 
@@ -533,10 +560,9 @@
 void Bench::ToggleLogging()
 {
     if (not is_logging) {
-        StartLogging();
+        is_logging = true;
     } else {
         is_logging = false;
-        StopLogging();
     }        
     PrintMenu();
 }