Version 3 is with update to the test rig with a linear actuator

Dependencies:   SPTE_10Bar_5V mbed AS5048 SDFileSystem MODSERIAL PinDetect LCM101 LinearActuator

Revision:
5:63063a9fa51c
Parent:
4:1cdce6c6c94e
Child:
6:02507d7a6f51
--- a/bench.h	Fri Oct 12 12:12:55 2018 +0000
+++ b/bench.h	Mon Dec 09 10:51:46 2019 +0000
@@ -1,19 +1,28 @@
 #ifndef _BENCH02_H_
 #define _BENCH02_H_
+#include "MODSERIAL.h"
 
 #include "mbed.h"
+#include <string>
+
+#include "SDFileSystem.h"
+#include "constants.h"
+
 #include "as5048.h"
 #include "lcm101.h"
 #include "SPTEPressureSensor.h"
-#include "constants.h"
+#include "Valve.h"
+
+#include "PinDetect.h"
 
 /**
  * Class to read out sensory information from the second test bench;
- * the upper and lower leg, foot en toe setup with 1-dof hinges,
+ * the knee joint setup with 1-dof hinge,
  * each of which is equipped with an AMS AS5048 absolute rotary sensor.
  * The sensors are daisy chained and communicate via SPI
  * also includes a load cell measuring the vertical force applied externally to 
  * the hip and pressure sensors connected to the setup
+ * An on /off valve can pressurise the actuator on the leg
  */
 class Bench {
 public:
@@ -27,21 +36,39 @@
         KNEE,
         HIP
     };
+    
+    // constructor
+    Bench(PinName mosi = AS5048_MOSI, PinName miso = AS5048_MISO, PinName sck = AS5048_SCLK, PinName cs = AS5048_CS, 
+        bool use5kN = sensors::use5kN,PinName p_lcm101 = LCM101, 
+        PinName p_spte0 = SPTE_0, PinName p_spte1 = SPTE_1,PinName p_valve = VALVE_PIN,
+        PinName sd_mosi = SD_MOSI, PinName sd_miso = SD_MISO, PinName sd_sck = SD_SCK, PinName sd_cs = SD_CS,
+        PinName tx = USBTX, PinName rx = USBRX, PinName but0 = SW2, PinName but1 = SW3);  
 
-    Bench(PinName mosi, PinName miso, PinName sck, PinName cs, PinName p_lcm101, PinName p_spte0, PinName p_spte1);
+    
+    //setup
+    void initialise();
     
-    void Update();
+    void setLoggingFrequency(float logHertz);
+    void setExtraColumns(string extraColumnNames[], int numCols);
+    void setExtraData(float data[]);
+    void update(); 
 
+    bool isLogging();//indicates if we are now datalogging
+    void stopLogging();//halts the data logging if we are now datalogging
+    
+    //reading angle sensors
+    As5048* get_as5048();
+    
     float getDegrees(int i_joint);
     float getDegrees(Joint joint);
 
     float getRadians(int i_joint);
     float getRadians(Joint joint);
 
-
     const char* getJointName(int i_joint);
     const char* getJointName(Joint joint);
 
+    //reading and calibrating force and pressure sensors
     float getForce();
     void nullForce();
     
@@ -50,14 +77,72 @@
     float getPressure1();
     void nullPressure1();
     
-    As5048* get_as5048();
+    //controlling valve
+    bool getValve();
+    void setValve(bool pressurise); 
+    
+    //printing data
+    MODSERIAL pc;
+    
+    void pausePrint();
+    void resumePrint();
+    
+private:
+    //timing
+    int loggingUS; //microseconds between recording data logging
+    float loggingHz;// Hz of data logging
+    
+    Ticker tick_update, tick_serial, tick_logging; //for the updating of sensor values, printing of serial data and logging of data
+    Timer timer;
+    int firstReadMS; //first timer value read
+    bool startedLogging; //in the middle of a logging cycle
+    
+    bool is_logging;
+    bool is_printing;
+    bool was_printing; //if printing is paused true if is_printing was true
+        
+    //buttons
+    PinDetect lowerBut;
+    PinDetect upperBut;
+    
+    //joint angle 
+    As5048 as5048_;
+    
+    //load cells
+    Lcm101 loadCell5kN;
+    Lcm101 loadCell1kN;
+    bool use5kN;//determine which load cell is used
+    
+    //pressure sensors
+    SPTEPressureSensor spte0;
+    SPTEPressureSensor spte1;
+    
+    //valve
+    ValveDigital valveFesto;
+    
+    //SD card
+    SDFileSystem sd;
+    FILE * fp_data;
+    int fname_prepend;//file number
+    bool sd_card_present;//card detected    
+       
+    static const int maxCols = 5;
+    int usedExtraCols; //number of extra columns useds
+    string extraColNames[maxCols];//names of extra columns (up to maxCols allowed with 15 characters)  
+    float extraColValues[maxCols];//value held in extra columns for current time step
+       
+    void InitSdCard();      
+    void StartLogging(const char * fname_append = "data");
+    void StopLogging();
+    void LogData();
+    void ToggleLogging();
+    
+    // serial printing
+    void TogglePrinting();
+    void PrintStatus();
+    void PrintMenu();  
+};
 
 
-private:
-    As5048 as5048_;
-    Lcm101 lcm101_;
-    SPTEPressureSensor spte0;
-    SPTEPressureSensor spte1;
-};
 
 #endif
\ No newline at end of file