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

Dependencies:   SPTE_10Bar_5V mbed AS5048 SDFileSystem MODSERIAL PinDetect LCM101 LinearActuator

Committer:
cnckiwi31
Date:
Mon Dec 09 13:08:36 2019 +0000
Revision:
8:bc467f5fe7c3
Parent:
6:02507d7a6f51
Child:
10:77fcbad99a31
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
megrootens 0:3855d4588f76 1 #ifndef _BENCH02_H_
megrootens 0:3855d4588f76 2 #define _BENCH02_H_
cnckiwi31 5:63063a9fa51c 3 #include "MODSERIAL.h"
megrootens 0:3855d4588f76 4
megrootens 0:3855d4588f76 5 #include "mbed.h"
cnckiwi31 5:63063a9fa51c 6 #include <string>
cnckiwi31 5:63063a9fa51c 7
cnckiwi31 5:63063a9fa51c 8 #include "SDFileSystem.h"
cnckiwi31 5:63063a9fa51c 9 #include "constants.h"
cnckiwi31 5:63063a9fa51c 10
megrootens 0:3855d4588f76 11 #include "as5048.h"
megrootens 0:3855d4588f76 12 #include "lcm101.h"
cnckiwi31 4:1cdce6c6c94e 13 #include "SPTEPressureSensor.h"
cnckiwi31 5:63063a9fa51c 14 #include "Valve.h"
cnckiwi31 5:63063a9fa51c 15
cnckiwi31 5:63063a9fa51c 16 #include "PinDetect.h"
megrootens 0:3855d4588f76 17
megrootens 0:3855d4588f76 18 /**
cnckiwi31 6:02507d7a6f51 19 * Class to read out sensory information from the second test bench:
cnckiwi31 6:02507d7a6f51 20 * the knee joint angle as measured by an AMS AS5048 absolute rotary sensor
cnckiwi31 6:02507d7a6f51 21 * the vertical force applied externally at the hip joint
cnckiwi31 6:02507d7a6f51 22 * the pressure (for example of an actuator used in the device under test).
cnckiwi31 6:02507d7a6f51 23 * Additionally, an on /off valve can pressurise the actuator on the leg
megrootens 0:3855d4588f76 24 */
megrootens 0:3855d4588f76 25 class Bench {
megrootens 0:3855d4588f76 26 public:
megrootens 0:3855d4588f76 27
megrootens 0:3855d4588f76 28 static const float kCutOffDegrees = 180.0f;
megrootens 0:3855d4588f76 29 static const float kCutOffRadians = 3.14159265359f;
megrootens 0:3855d4588f76 30
megrootens 0:3855d4588f76 31 enum Joint {
megrootens 0:3855d4588f76 32 TOES,
megrootens 0:3855d4588f76 33 ANKLE,
megrootens 0:3855d4588f76 34 KNEE,
megrootens 0:3855d4588f76 35 HIP
megrootens 0:3855d4588f76 36 };
cnckiwi31 5:63063a9fa51c 37
cnckiwi31 5:63063a9fa51c 38 // constructor
cnckiwi31 5:63063a9fa51c 39 Bench(PinName mosi = AS5048_MOSI, PinName miso = AS5048_MISO, PinName sck = AS5048_SCLK, PinName cs = AS5048_CS,
cnckiwi31 5:63063a9fa51c 40 bool use5kN = sensors::use5kN,PinName p_lcm101 = LCM101,
cnckiwi31 5:63063a9fa51c 41 PinName p_spte0 = SPTE_0, PinName p_spte1 = SPTE_1,PinName p_valve = VALVE_PIN,
cnckiwi31 5:63063a9fa51c 42 PinName sd_mosi = SD_MOSI, PinName sd_miso = SD_MISO, PinName sd_sck = SD_SCK, PinName sd_cs = SD_CS,
cnckiwi31 5:63063a9fa51c 43 PinName tx = USBTX, PinName rx = USBRX, PinName but0 = SW2, PinName but1 = SW3);
megrootens 0:3855d4588f76 44
cnckiwi31 5:63063a9fa51c 45
cnckiwi31 5:63063a9fa51c 46 //setup
cnckiwi31 5:63063a9fa51c 47 void initialise();
megrootens 0:3855d4588f76 48
cnckiwi31 5:63063a9fa51c 49 void setLoggingFrequency(float logHertz);
cnckiwi31 5:63063a9fa51c 50 void setExtraColumns(string extraColumnNames[], int numCols);
cnckiwi31 5:63063a9fa51c 51 void setExtraData(float data[]);
cnckiwi31 5:63063a9fa51c 52 void update();
megrootens 0:3855d4588f76 53
cnckiwi31 5:63063a9fa51c 54 bool isLogging();//indicates if we are now datalogging
cnckiwi31 5:63063a9fa51c 55 void stopLogging();//halts the data logging if we are now datalogging
cnckiwi31 5:63063a9fa51c 56
cnckiwi31 5:63063a9fa51c 57 //reading angle sensors
cnckiwi31 5:63063a9fa51c 58 As5048* get_as5048();
cnckiwi31 5:63063a9fa51c 59
megrootens 0:3855d4588f76 60 float getDegrees(int i_joint);
megrootens 0:3855d4588f76 61 float getDegrees(Joint joint);
megrootens 0:3855d4588f76 62
megrootens 0:3855d4588f76 63 float getRadians(int i_joint);
megrootens 0:3855d4588f76 64 float getRadians(Joint joint);
megrootens 0:3855d4588f76 65
megrootens 0:3855d4588f76 66 const char* getJointName(int i_joint);
megrootens 0:3855d4588f76 67 const char* getJointName(Joint joint);
megrootens 0:3855d4588f76 68
cnckiwi31 5:63063a9fa51c 69 //reading and calibrating force and pressure sensors
megrootens 0:3855d4588f76 70 float getForce();
cnckiwi31 4:1cdce6c6c94e 71 void nullForce();
cnckiwi31 4:1cdce6c6c94e 72
cnckiwi31 4:1cdce6c6c94e 73 float getPressure0();
cnckiwi31 4:1cdce6c6c94e 74 void nullPressure0();
cnckiwi31 4:1cdce6c6c94e 75 float getPressure1();
cnckiwi31 4:1cdce6c6c94e 76 void nullPressure1();
megrootens 0:3855d4588f76 77
cnckiwi31 5:63063a9fa51c 78 //controlling valve
cnckiwi31 5:63063a9fa51c 79 bool getValve();
cnckiwi31 5:63063a9fa51c 80 void setValve(bool pressurise);
cnckiwi31 5:63063a9fa51c 81
cnckiwi31 8:bc467f5fe7c3 82 /** Object for printing/receiving data to the PC the test rig is connected
cnckiwi31 8:bc467f5fe7c3 83 * to. Note that it uses the MODSERIAL.h class.
cnckiwi31 8:bc467f5fe7c3 84 */
cnckiwi31 5:63063a9fa51c 85 MODSERIAL pc;
cnckiwi31 5:63063a9fa51c 86
cnckiwi31 5:63063a9fa51c 87 void pausePrint();
cnckiwi31 5:63063a9fa51c 88 void resumePrint();
cnckiwi31 5:63063a9fa51c 89
cnckiwi31 5:63063a9fa51c 90 private:
cnckiwi31 5:63063a9fa51c 91 //timing
cnckiwi31 5:63063a9fa51c 92 int loggingUS; //microseconds between recording data logging
cnckiwi31 5:63063a9fa51c 93 float loggingHz;// Hz of data logging
cnckiwi31 5:63063a9fa51c 94
cnckiwi31 5:63063a9fa51c 95 Ticker tick_update, tick_serial, tick_logging; //for the updating of sensor values, printing of serial data and logging of data
cnckiwi31 5:63063a9fa51c 96 Timer timer;
cnckiwi31 5:63063a9fa51c 97 int firstReadMS; //first timer value read
cnckiwi31 5:63063a9fa51c 98 bool startedLogging; //in the middle of a logging cycle
cnckiwi31 5:63063a9fa51c 99
cnckiwi31 5:63063a9fa51c 100 bool is_logging;
cnckiwi31 5:63063a9fa51c 101 bool is_printing;
cnckiwi31 5:63063a9fa51c 102 bool was_printing; //if printing is paused true if is_printing was true
cnckiwi31 5:63063a9fa51c 103
cnckiwi31 5:63063a9fa51c 104 //buttons
cnckiwi31 5:63063a9fa51c 105 PinDetect lowerBut;
cnckiwi31 5:63063a9fa51c 106 PinDetect upperBut;
cnckiwi31 5:63063a9fa51c 107
cnckiwi31 5:63063a9fa51c 108 //joint angle
cnckiwi31 5:63063a9fa51c 109 As5048 as5048_;
cnckiwi31 5:63063a9fa51c 110
cnckiwi31 5:63063a9fa51c 111 //load cells
cnckiwi31 5:63063a9fa51c 112 Lcm101 loadCell5kN;
cnckiwi31 5:63063a9fa51c 113 Lcm101 loadCell1kN;
cnckiwi31 5:63063a9fa51c 114 bool use5kN;//determine which load cell is used
cnckiwi31 5:63063a9fa51c 115
cnckiwi31 5:63063a9fa51c 116 //pressure sensors
cnckiwi31 5:63063a9fa51c 117 SPTEPressureSensor spte0;
cnckiwi31 5:63063a9fa51c 118 SPTEPressureSensor spte1;
cnckiwi31 5:63063a9fa51c 119
cnckiwi31 5:63063a9fa51c 120 //valve
cnckiwi31 5:63063a9fa51c 121 ValveDigital valveFesto;
cnckiwi31 5:63063a9fa51c 122
cnckiwi31 5:63063a9fa51c 123 //SD card
cnckiwi31 5:63063a9fa51c 124 SDFileSystem sd;
cnckiwi31 5:63063a9fa51c 125 FILE * fp_data;
cnckiwi31 5:63063a9fa51c 126 int fname_prepend;//file number
cnckiwi31 5:63063a9fa51c 127 bool sd_card_present;//card detected
cnckiwi31 5:63063a9fa51c 128
cnckiwi31 5:63063a9fa51c 129 static const int maxCols = 5;
cnckiwi31 5:63063a9fa51c 130 int usedExtraCols; //number of extra columns useds
cnckiwi31 5:63063a9fa51c 131 string extraColNames[maxCols];//names of extra columns (up to maxCols allowed with 15 characters)
cnckiwi31 5:63063a9fa51c 132 float extraColValues[maxCols];//value held in extra columns for current time step
cnckiwi31 5:63063a9fa51c 133
cnckiwi31 5:63063a9fa51c 134 void InitSdCard();
cnckiwi31 5:63063a9fa51c 135 void StartLogging(const char * fname_append = "data");
cnckiwi31 5:63063a9fa51c 136 void StopLogging();
cnckiwi31 5:63063a9fa51c 137 void LogData();
cnckiwi31 5:63063a9fa51c 138 void ToggleLogging();
cnckiwi31 5:63063a9fa51c 139
cnckiwi31 5:63063a9fa51c 140 // serial printing
cnckiwi31 5:63063a9fa51c 141 void TogglePrinting();
cnckiwi31 5:63063a9fa51c 142 void PrintStatus();
cnckiwi31 5:63063a9fa51c 143 void PrintMenu();
cnckiwi31 5:63063a9fa51c 144 };
megrootens 0:3855d4588f76 145 #endif