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
bench.h@12:b0a6faaa5e9f, 2020-02-25 (annotated)
- Committer:
- cnckiwi31
- Date:
- Tue Feb 25 15:04:21 2020 +0000
- Revision:
- 12:b0a6faaa5e9f
- Parent:
- 10:77fcbad99a31
Manual data logging call
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:77fcbad99a31 | 38 | enum DACChannel { |
cnckiwi31 | 10:77fcbad99a31 | 39 | A, |
cnckiwi31 | 10:77fcbad99a31 | 40 | B |
cnckiwi31 | 10:77fcbad99a31 | 41 | }; |
cnckiwi31 | 10:77fcbad99a31 | 42 | |
cnckiwi31 | 5:63063a9fa51c | 43 | // constructor |
cnckiwi31 | 5:63063a9fa51c | 44 | Bench(PinName mosi = AS5048_MOSI, PinName miso = AS5048_MISO, PinName sck = AS5048_SCLK, PinName cs = AS5048_CS, |
cnckiwi31 | 5:63063a9fa51c | 45 | bool use5kN = sensors::use5kN,PinName p_lcm101 = LCM101, |
cnckiwi31 | 5:63063a9fa51c | 46 | PinName p_spte0 = SPTE_0, PinName p_spte1 = SPTE_1,PinName p_valve = VALVE_PIN, |
cnckiwi31 | 5:63063a9fa51c | 47 | PinName sd_mosi = SD_MOSI, PinName sd_miso = SD_MISO, PinName sd_sck = SD_SCK, PinName sd_cs = SD_CS, |
cnckiwi31 | 5:63063a9fa51c | 48 | PinName tx = USBTX, PinName rx = USBRX, PinName but0 = SW2, PinName but1 = SW3); |
megrootens | 0:3855d4588f76 | 49 | |
cnckiwi31 | 5:63063a9fa51c | 50 | |
cnckiwi31 | 5:63063a9fa51c | 51 | //setup |
cnckiwi31 | 5:63063a9fa51c | 52 | void initialise(); |
megrootens | 0:3855d4588f76 | 53 | |
cnckiwi31 | 5:63063a9fa51c | 54 | void setLoggingFrequency(float logHertz); |
cnckiwi31 | 5:63063a9fa51c | 55 | void setExtraColumns(string extraColumnNames[], int numCols); |
cnckiwi31 | 5:63063a9fa51c | 56 | void setExtraData(float data[]); |
cnckiwi31 | 5:63063a9fa51c | 57 | void update(); |
megrootens | 0:3855d4588f76 | 58 | |
cnckiwi31 | 5:63063a9fa51c | 59 | bool isLogging();//indicates if we are now datalogging |
cnckiwi31 | 5:63063a9fa51c | 60 | void stopLogging();//halts the data logging if we are now datalogging |
cnckiwi31 | 12:b0a6faaa5e9f | 61 | |
cnckiwi31 | 12:b0a6faaa5e9f | 62 | void StopLogging(); //halts the data logging if we are now datalogging |
cnckiwi31 | 12:b0a6faaa5e9f | 63 | void StartLogging(const char * fname_append = "data"); //starts datalogging |
cnckiwi31 | 12:b0a6faaa5e9f | 64 | void RestartLogging(const char * fname_append = "data");//restart datalogging |
cnckiwi31 | 12:b0a6faaa5e9f | 65 | void LogData(); |
cnckiwi31 | 5:63063a9fa51c | 66 | |
cnckiwi31 | 5:63063a9fa51c | 67 | //reading angle sensors |
cnckiwi31 | 5:63063a9fa51c | 68 | As5048* get_as5048(); |
cnckiwi31 | 5:63063a9fa51c | 69 | |
megrootens | 0:3855d4588f76 | 70 | float getDegrees(int i_joint); |
megrootens | 0:3855d4588f76 | 71 | float getDegrees(Joint joint); |
megrootens | 0:3855d4588f76 | 72 | |
megrootens | 0:3855d4588f76 | 73 | float getRadians(int i_joint); |
megrootens | 0:3855d4588f76 | 74 | float getRadians(Joint joint); |
megrootens | 0:3855d4588f76 | 75 | |
megrootens | 0:3855d4588f76 | 76 | const char* getJointName(int i_joint); |
megrootens | 0:3855d4588f76 | 77 | const char* getJointName(Joint joint); |
megrootens | 0:3855d4588f76 | 78 | |
cnckiwi31 | 5:63063a9fa51c | 79 | //reading and calibrating force and pressure sensors |
megrootens | 0:3855d4588f76 | 80 | float getForce(); |
cnckiwi31 | 4:1cdce6c6c94e | 81 | void nullForce(); |
cnckiwi31 | 4:1cdce6c6c94e | 82 | |
cnckiwi31 | 4:1cdce6c6c94e | 83 | float getPressure0(); |
cnckiwi31 | 4:1cdce6c6c94e | 84 | void nullPressure0(); |
cnckiwi31 | 4:1cdce6c6c94e | 85 | float getPressure1(); |
cnckiwi31 | 4:1cdce6c6c94e | 86 | void nullPressure1(); |
megrootens | 0:3855d4588f76 | 87 | |
cnckiwi31 | 10:77fcbad99a31 | 88 | //MAX5322 DACs (two channels per DAC) |
cnckiwi31 | 10:77fcbad99a31 | 89 | void setDACA(DACChannel ch, unsigned int bitValue); |
cnckiwi31 | 10:77fcbad99a31 | 90 | void setDACB(DACChannel ch, unsigned int bitValue); |
cnckiwi31 | 10:77fcbad99a31 | 91 | |
cnckiwi31 | 5:63063a9fa51c | 92 | //controlling valve |
cnckiwi31 | 5:63063a9fa51c | 93 | bool getValve(); |
cnckiwi31 | 5:63063a9fa51c | 94 | void setValve(bool pressurise); |
cnckiwi31 | 5:63063a9fa51c | 95 | |
cnckiwi31 | 8:bc467f5fe7c3 | 96 | /** Object for printing/receiving data to the PC the test rig is connected |
cnckiwi31 | 8:bc467f5fe7c3 | 97 | * to. Note that it uses the MODSERIAL.h class. |
cnckiwi31 | 8:bc467f5fe7c3 | 98 | */ |
cnckiwi31 | 5:63063a9fa51c | 99 | MODSERIAL pc; |
cnckiwi31 | 5:63063a9fa51c | 100 | |
cnckiwi31 | 5:63063a9fa51c | 101 | void pausePrint(); |
cnckiwi31 | 5:63063a9fa51c | 102 | void resumePrint(); |
cnckiwi31 | 5:63063a9fa51c | 103 | |
cnckiwi31 | 5:63063a9fa51c | 104 | private: |
cnckiwi31 | 5:63063a9fa51c | 105 | //timing |
cnckiwi31 | 5:63063a9fa51c | 106 | int loggingUS; //microseconds between recording data logging |
cnckiwi31 | 5:63063a9fa51c | 107 | float loggingHz;// Hz of data logging |
cnckiwi31 | 5:63063a9fa51c | 108 | |
cnckiwi31 | 5:63063a9fa51c | 109 | Ticker tick_update, tick_serial, tick_logging; //for the updating of sensor values, printing of serial data and logging of data |
cnckiwi31 | 5:63063a9fa51c | 110 | Timer timer; |
cnckiwi31 | 5:63063a9fa51c | 111 | int firstReadMS; //first timer value read |
cnckiwi31 | 5:63063a9fa51c | 112 | bool startedLogging; //in the middle of a logging cycle |
cnckiwi31 | 5:63063a9fa51c | 113 | |
cnckiwi31 | 5:63063a9fa51c | 114 | bool is_logging; |
cnckiwi31 | 5:63063a9fa51c | 115 | bool is_printing; |
cnckiwi31 | 5:63063a9fa51c | 116 | bool was_printing; //if printing is paused true if is_printing was true |
cnckiwi31 | 5:63063a9fa51c | 117 | |
cnckiwi31 | 5:63063a9fa51c | 118 | //buttons |
cnckiwi31 | 5:63063a9fa51c | 119 | PinDetect lowerBut; |
cnckiwi31 | 5:63063a9fa51c | 120 | PinDetect upperBut; |
cnckiwi31 | 5:63063a9fa51c | 121 | |
cnckiwi31 | 5:63063a9fa51c | 122 | //joint angle |
cnckiwi31 | 5:63063a9fa51c | 123 | As5048 as5048_; |
cnckiwi31 | 5:63063a9fa51c | 124 | |
cnckiwi31 | 5:63063a9fa51c | 125 | //load cells |
cnckiwi31 | 5:63063a9fa51c | 126 | Lcm101 loadCell5kN; |
cnckiwi31 | 5:63063a9fa51c | 127 | Lcm101 loadCell1kN; |
cnckiwi31 | 5:63063a9fa51c | 128 | bool use5kN;//determine which load cell is used |
cnckiwi31 | 5:63063a9fa51c | 129 | |
cnckiwi31 | 5:63063a9fa51c | 130 | //pressure sensors |
cnckiwi31 | 5:63063a9fa51c | 131 | SPTEPressureSensor spte0; |
cnckiwi31 | 5:63063a9fa51c | 132 | SPTEPressureSensor spte1; |
cnckiwi31 | 5:63063a9fa51c | 133 | |
cnckiwi31 | 5:63063a9fa51c | 134 | //valve |
cnckiwi31 | 5:63063a9fa51c | 135 | ValveDigital valveFesto; |
cnckiwi31 | 5:63063a9fa51c | 136 | |
cnckiwi31 | 5:63063a9fa51c | 137 | //SD card |
cnckiwi31 | 5:63063a9fa51c | 138 | SDFileSystem sd; |
cnckiwi31 | 5:63063a9fa51c | 139 | FILE * fp_data; |
cnckiwi31 | 5:63063a9fa51c | 140 | int fname_prepend;//file number |
cnckiwi31 | 5:63063a9fa51c | 141 | bool sd_card_present;//card detected |
cnckiwi31 | 5:63063a9fa51c | 142 | |
cnckiwi31 | 5:63063a9fa51c | 143 | static const int maxCols = 5; |
cnckiwi31 | 5:63063a9fa51c | 144 | int usedExtraCols; //number of extra columns useds |
cnckiwi31 | 5:63063a9fa51c | 145 | string extraColNames[maxCols];//names of extra columns (up to maxCols allowed with 15 characters) |
cnckiwi31 | 5:63063a9fa51c | 146 | float extraColValues[maxCols];//value held in extra columns for current time step |
cnckiwi31 | 5:63063a9fa51c | 147 | |
cnckiwi31 | 12:b0a6faaa5e9f | 148 | void InitSdCard(); |
cnckiwi31 | 12:b0a6faaa5e9f | 149 | |
cnckiwi31 | 5:63063a9fa51c | 150 | void ToggleLogging(); |
cnckiwi31 | 5:63063a9fa51c | 151 | |
cnckiwi31 | 5:63063a9fa51c | 152 | // serial printing |
cnckiwi31 | 5:63063a9fa51c | 153 | void TogglePrinting(); |
cnckiwi31 | 5:63063a9fa51c | 154 | void PrintStatus(); |
cnckiwi31 | 5:63063a9fa51c | 155 | void PrintMenu(); |
cnckiwi31 | 5:63063a9fa51c | 156 | }; |
megrootens | 0:3855d4588f76 | 157 | #endif |