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@10:77fcbad99a31, 2020-02-17 (annotated)
- Committer:
- cnckiwi31
- Date:
- Mon Feb 17 15:15:24 2020 +0000
- Revision:
- 10:77fcbad99a31
- Parent:
- 8:bc467f5fe7c3
- Child:
- 11:fc82dd22a527
- Child:
- 12:b0a6faaa5e9f
Latest commit
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 | 5:63063a9fa51c | 61 | |
cnckiwi31 | 5:63063a9fa51c | 62 | //reading angle sensors |
cnckiwi31 | 5:63063a9fa51c | 63 | As5048* get_as5048(); |
cnckiwi31 | 5:63063a9fa51c | 64 | |
megrootens | 0:3855d4588f76 | 65 | float getDegrees(int i_joint); |
megrootens | 0:3855d4588f76 | 66 | float getDegrees(Joint joint); |
megrootens | 0:3855d4588f76 | 67 | |
megrootens | 0:3855d4588f76 | 68 | float getRadians(int i_joint); |
megrootens | 0:3855d4588f76 | 69 | float getRadians(Joint joint); |
megrootens | 0:3855d4588f76 | 70 | |
megrootens | 0:3855d4588f76 | 71 | const char* getJointName(int i_joint); |
megrootens | 0:3855d4588f76 | 72 | const char* getJointName(Joint joint); |
megrootens | 0:3855d4588f76 | 73 | |
cnckiwi31 | 5:63063a9fa51c | 74 | //reading and calibrating force and pressure sensors |
megrootens | 0:3855d4588f76 | 75 | float getForce(); |
cnckiwi31 | 4:1cdce6c6c94e | 76 | void nullForce(); |
cnckiwi31 | 4:1cdce6c6c94e | 77 | |
cnckiwi31 | 4:1cdce6c6c94e | 78 | float getPressure0(); |
cnckiwi31 | 4:1cdce6c6c94e | 79 | void nullPressure0(); |
cnckiwi31 | 4:1cdce6c6c94e | 80 | float getPressure1(); |
cnckiwi31 | 4:1cdce6c6c94e | 81 | void nullPressure1(); |
megrootens | 0:3855d4588f76 | 82 | |
cnckiwi31 | 10:77fcbad99a31 | 83 | //MAX5322 DACs (two channels per DAC) |
cnckiwi31 | 10:77fcbad99a31 | 84 | void setDACA(DACChannel ch, unsigned int bitValue); |
cnckiwi31 | 10:77fcbad99a31 | 85 | void setDACB(DACChannel ch, unsigned int bitValue); |
cnckiwi31 | 10:77fcbad99a31 | 86 | |
cnckiwi31 | 5:63063a9fa51c | 87 | //controlling valve |
cnckiwi31 | 5:63063a9fa51c | 88 | bool getValve(); |
cnckiwi31 | 5:63063a9fa51c | 89 | void setValve(bool pressurise); |
cnckiwi31 | 5:63063a9fa51c | 90 | |
cnckiwi31 | 8:bc467f5fe7c3 | 91 | /** Object for printing/receiving data to the PC the test rig is connected |
cnckiwi31 | 8:bc467f5fe7c3 | 92 | * to. Note that it uses the MODSERIAL.h class. |
cnckiwi31 | 8:bc467f5fe7c3 | 93 | */ |
cnckiwi31 | 5:63063a9fa51c | 94 | MODSERIAL pc; |
cnckiwi31 | 5:63063a9fa51c | 95 | |
cnckiwi31 | 5:63063a9fa51c | 96 | void pausePrint(); |
cnckiwi31 | 5:63063a9fa51c | 97 | void resumePrint(); |
cnckiwi31 | 5:63063a9fa51c | 98 | |
cnckiwi31 | 5:63063a9fa51c | 99 | private: |
cnckiwi31 | 5:63063a9fa51c | 100 | //timing |
cnckiwi31 | 5:63063a9fa51c | 101 | int loggingUS; //microseconds between recording data logging |
cnckiwi31 | 5:63063a9fa51c | 102 | float loggingHz;// Hz of data logging |
cnckiwi31 | 5:63063a9fa51c | 103 | |
cnckiwi31 | 5:63063a9fa51c | 104 | Ticker tick_update, tick_serial, tick_logging; //for the updating of sensor values, printing of serial data and logging of data |
cnckiwi31 | 5:63063a9fa51c | 105 | Timer timer; |
cnckiwi31 | 5:63063a9fa51c | 106 | int firstReadMS; //first timer value read |
cnckiwi31 | 5:63063a9fa51c | 107 | bool startedLogging; //in the middle of a logging cycle |
cnckiwi31 | 5:63063a9fa51c | 108 | |
cnckiwi31 | 5:63063a9fa51c | 109 | bool is_logging; |
cnckiwi31 | 5:63063a9fa51c | 110 | bool is_printing; |
cnckiwi31 | 5:63063a9fa51c | 111 | bool was_printing; //if printing is paused true if is_printing was true |
cnckiwi31 | 5:63063a9fa51c | 112 | |
cnckiwi31 | 5:63063a9fa51c | 113 | //buttons |
cnckiwi31 | 5:63063a9fa51c | 114 | PinDetect lowerBut; |
cnckiwi31 | 5:63063a9fa51c | 115 | PinDetect upperBut; |
cnckiwi31 | 5:63063a9fa51c | 116 | |
cnckiwi31 | 5:63063a9fa51c | 117 | //joint angle |
cnckiwi31 | 5:63063a9fa51c | 118 | As5048 as5048_; |
cnckiwi31 | 5:63063a9fa51c | 119 | |
cnckiwi31 | 5:63063a9fa51c | 120 | //load cells |
cnckiwi31 | 5:63063a9fa51c | 121 | Lcm101 loadCell5kN; |
cnckiwi31 | 5:63063a9fa51c | 122 | Lcm101 loadCell1kN; |
cnckiwi31 | 5:63063a9fa51c | 123 | bool use5kN;//determine which load cell is used |
cnckiwi31 | 5:63063a9fa51c | 124 | |
cnckiwi31 | 5:63063a9fa51c | 125 | //pressure sensors |
cnckiwi31 | 5:63063a9fa51c | 126 | SPTEPressureSensor spte0; |
cnckiwi31 | 5:63063a9fa51c | 127 | SPTEPressureSensor spte1; |
cnckiwi31 | 5:63063a9fa51c | 128 | |
cnckiwi31 | 5:63063a9fa51c | 129 | //valve |
cnckiwi31 | 5:63063a9fa51c | 130 | ValveDigital valveFesto; |
cnckiwi31 | 5:63063a9fa51c | 131 | |
cnckiwi31 | 5:63063a9fa51c | 132 | //SD card |
cnckiwi31 | 5:63063a9fa51c | 133 | SDFileSystem sd; |
cnckiwi31 | 5:63063a9fa51c | 134 | FILE * fp_data; |
cnckiwi31 | 5:63063a9fa51c | 135 | int fname_prepend;//file number |
cnckiwi31 | 5:63063a9fa51c | 136 | bool sd_card_present;//card detected |
cnckiwi31 | 5:63063a9fa51c | 137 | |
cnckiwi31 | 5:63063a9fa51c | 138 | static const int maxCols = 5; |
cnckiwi31 | 5:63063a9fa51c | 139 | int usedExtraCols; //number of extra columns useds |
cnckiwi31 | 5:63063a9fa51c | 140 | string extraColNames[maxCols];//names of extra columns (up to maxCols allowed with 15 characters) |
cnckiwi31 | 5:63063a9fa51c | 141 | float extraColValues[maxCols];//value held in extra columns for current time step |
cnckiwi31 | 5:63063a9fa51c | 142 | |
cnckiwi31 | 5:63063a9fa51c | 143 | void InitSdCard(); |
cnckiwi31 | 5:63063a9fa51c | 144 | void StartLogging(const char * fname_append = "data"); |
cnckiwi31 | 5:63063a9fa51c | 145 | void StopLogging(); |
cnckiwi31 | 5:63063a9fa51c | 146 | void LogData(); |
cnckiwi31 | 5:63063a9fa51c | 147 | void ToggleLogging(); |
cnckiwi31 | 5:63063a9fa51c | 148 | |
cnckiwi31 | 5:63063a9fa51c | 149 | // serial printing |
cnckiwi31 | 5:63063a9fa51c | 150 | void TogglePrinting(); |
cnckiwi31 | 5:63063a9fa51c | 151 | void PrintStatus(); |
cnckiwi31 | 5:63063a9fa51c | 152 | void PrintMenu(); |
cnckiwi31 | 5:63063a9fa51c | 153 | }; |
megrootens | 0:3855d4588f76 | 154 | #endif |