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
main.cpp@15:a84d54e25775, 2020-10-26 (annotated)
- Committer:
- cnckiwi31
- Date:
- Mon Oct 26 11:55:27 2020 +0000
- Revision:
- 15:a84d54e25775
- Parent:
- 14:dd4193213be9
Code ready for inclusion in documentation (compiles, but no last check on runBenchmarkExperiment1() code done)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cnckiwi31 | 14:dd4193213be9 | 1 | /* Copyright 2020 Allan Joshua Veale |
cnckiwi31 | 14:dd4193213be9 | 2 | |
cnckiwi31 | 14:dd4193213be9 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
cnckiwi31 | 14:dd4193213be9 | 4 | you may not use this file except in compliance with the License. |
cnckiwi31 | 14:dd4193213be9 | 5 | You may obtain a copy of the License at |
cnckiwi31 | 14:dd4193213be9 | 6 | |
cnckiwi31 | 14:dd4193213be9 | 7 | http://www.apache.org/licenses/LICENSE-2.0 |
cnckiwi31 | 14:dd4193213be9 | 8 | |
cnckiwi31 | 14:dd4193213be9 | 9 | Unless required by applicable law or agreed to in writing, software |
cnckiwi31 | 14:dd4193213be9 | 10 | distributed under the License is distributed on an "AS IS" BASIS, |
cnckiwi31 | 14:dd4193213be9 | 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
cnckiwi31 | 14:dd4193213be9 | 12 | See the License for the specific language governing permissions and |
cnckiwi31 | 14:dd4193213be9 | 13 | limitations under the License. |
cnckiwi31 | 14:dd4193213be9 | 14 | */ |
cnckiwi31 | 14:dd4193213be9 | 15 | |
cnckiwi31 | 5:63063a9fa51c | 16 | /** |
cnckiwi31 | 14:dd4193213be9 | 17 | * Author: Allan Veale and Suraj Giri |
cnckiwi31 | 14:dd4193213be9 | 18 | * Date: 23/10/2020 |
cnckiwi31 | 5:63063a9fa51c | 19 | * Purpose: Datalog from the active wearable test rig fitted with the first |
cnckiwi31 | 14:dd4193213be9 | 20 | * realistic (foam tissue) leg. Note that the test rig electronics (mbed) needs to be |
cnckiwi31 | 14:dd4193213be9 | 21 | * connected with a USB cable to the mini-USB connector closest to the reset button |
cnckiwi31 | 14:dd4193213be9 | 22 | * The data logging and test rig is controlled with a PC running a serial terminal |
cnckiwi31 | 14:dd4193213be9 | 23 | * at 115200. One terminal that works well is found at https://www.putty.org/ |
cnckiwi31 | 5:63063a9fa51c | 24 | */ |
megrootens | 0:3855d4588f76 | 25 | |
cnckiwi31 | 5:63063a9fa51c | 26 | //Both the general mbed header and the test rig bench header are needed |
cnckiwi31 | 5:63063a9fa51c | 27 | #include "mbed.h" |
cnckiwi31 | 5:63063a9fa51c | 28 | #include "bench.h" |
cnckiwi31 | 10:77fcbad99a31 | 29 | |
cnckiwi31 | 14:dd4193213be9 | 30 | //Methods describing the tests |
cnckiwi31 | 15:a84d54e25775 | 31 | void runFatigueExperiment0(int cycles, float targetkPa, float inflateTimeOut,float deflateTimeOut,int logHz); |
cnckiwi31 | 15:a84d54e25775 | 32 | void runFailureExperiment0(float targetkPa,int logHz); |
cnckiwi31 | 15:a84d54e25775 | 33 | void runBenchmarkExperiment0(int logHz); |
cnckiwi31 | 14:dd4193213be9 | 34 | void runBenchmarkExperiment1(int minForce, float maxAngle, float inflationT, int pwm, int cycles, int logHz); |
cnckiwi31 | 10:77fcbad99a31 | 35 | |
cnckiwi31 | 5:63063a9fa51c | 36 | // Create bench object - this is used to control the test rig |
cnckiwi31 | 5:63063a9fa51c | 37 | Bench leg; |
megrootens | 0:3855d4588f76 | 38 | |
megrootens | 0:3855d4588f76 | 39 | /** |
cnckiwi31 | 5:63063a9fa51c | 40 | * Main loop |
megrootens | 0:3855d4588f76 | 41 | */ |
megrootens | 0:3855d4588f76 | 42 | int main() |
cnckiwi31 | 15:a84d54e25775 | 43 | { |
cnckiwi31 | 5:63063a9fa51c | 44 | /* Two extra columns of data will be recorded in this experiment. |
cnckiwi31 | 14:dd4193213be9 | 45 | One for the target pressure, and the other for the number of inflation-deflation |
cnckiwi31 | 14:dd4193213be9 | 46 | cycles currently completed in the experiment */ |
cnckiwi31 | 15:a84d54e25775 | 47 | string colNames[] = {"Target pressure (kPa)","Cycle"}; //add data headings |
cnckiwi31 | 5:63063a9fa51c | 48 | leg.setExtraColumns(colNames,2); |
megrootens | 0:3855d4588f76 | 49 | |
cnckiwi31 | 15:a84d54e25775 | 50 | int logHz = 10; //(Hz) datalogging frequency |
cnckiwi31 | 15:a84d54e25775 | 51 | float targetP = 300; //Pressure at which inflation is stopped and deflation begins (kPa) |
cnckiwi31 | 15:a84d54e25775 | 52 | |
cnckiwi31 | 15:a84d54e25775 | 53 | int fatCycles = 40; //Number of inflation cycles for the fatigue test |
cnckiwi31 | 15:a84d54e25775 | 54 | float infTimeAllow = 10;// (s) time allowed for inflation in a fatigue cycle |
cnckiwi31 | 15:a84d54e25775 | 55 | float defTimeAllow = 10;// (s) time allowed for deflation in a fatigue cycle |
cnckiwi31 | 15:a84d54e25775 | 56 | |
cnckiwi31 | 15:a84d54e25775 | 57 | //for benchmark experiment |
cnckiwi31 | 15:a84d54e25775 | 58 | float minForce = 5;//(N) force threshold at which leg extension changes to flexion |
cnckiwi31 | 15:a84d54e25775 | 59 | float maxAngle = 70;//(deg) angle threshold at which leg flexion changes to extension |
cnckiwi31 | 15:a84d54e25775 | 60 | float inflationTime = 3;//(s) time actuator given to inflate before starting experiment |
cnckiwi31 | 15:a84d54e25775 | 61 | int pwm = 75; //(%) linear actuator motor pwm |
cnckiwi31 | 15:a84d54e25775 | 62 | int benchCycles = 1;//(-) number of flexion/extension cycles |
cnckiwi31 | 15:a84d54e25775 | 63 | |
cnckiwi31 | 14:dd4193213be9 | 64 | float vals[] = {targetP,0}; //set of initial values of data that will be logged |
cnckiwi31 | 5:63063a9fa51c | 65 | leg.setExtraData(vals); |
cnckiwi31 | 4:1cdce6c6c94e | 66 | |
cnckiwi31 | 5:63063a9fa51c | 67 | /* Setup all peripherals on rig, display info about SD card and the |
cnckiwi31 | 5:63063a9fa51c | 68 | user interface menu */ |
cnckiwi31 | 14:dd4193213be9 | 69 | leg.initialise(); |
cnckiwi31 | 14:dd4193213be9 | 70 | |
cnckiwi31 | 5:63063a9fa51c | 71 | /*Run an experiment when the button is pressed to start datalogging and |
cnckiwi31 | 5:63063a9fa51c | 72 | stop it if the button is pressed again to stop datalogging |
cnckiwi31 | 5:63063a9fa51c | 73 | (or when experiment stops - then datalogging stops by itself) */ |
cnckiwi31 | 5:63063a9fa51c | 74 | while (true) { |
cnckiwi31 | 15:a84d54e25775 | 75 | if (leg.isLogging()) {//check if logging has started, if so, run an experiment procedure |
cnckiwi31 | 15:a84d54e25775 | 76 | leg.pc.printf("Logging started");//user feedback |
cnckiwi31 | 15:a84d54e25775 | 77 | |
cnckiwi31 | 15:a84d54e25775 | 78 | //uncomment the type of experiment you want to try |
cnckiwi31 | 15:a84d54e25775 | 79 | runFatigueExperiment0(fatCycles,targetP,infTimeAllow,defTimeAllow,logHz); |
cnckiwi31 | 15:a84d54e25775 | 80 | //runBenchmarkExperiment0(logHz); |
cnckiwi31 | 15:a84d54e25775 | 81 | //runBenchmarkExperiment1(minForce, maxAngle, inflationTime, pwm, benchCycles, logHz); |
cnckiwi31 | 15:a84d54e25775 | 82 | //runFailureExperiment0(targetP,logHz); |
cnckiwi31 | 5:63063a9fa51c | 83 | } |
cnckiwi31 | 15:a84d54e25775 | 84 | wait(0.5);//wait a bit before checking again |
megrootens | 0:3855d4588f76 | 85 | } |
megrootens | 0:3855d4588f76 | 86 | } |
megrootens | 0:3855d4588f76 | 87 | |
cnckiwi31 | 5:63063a9fa51c | 88 | /** |
cnckiwi31 | 14:dd4193213be9 | 89 | * This experiment pressurises the leg to |
cnckiwi31 | 5:63063a9fa51c | 90 | * pressure targetkPa, depressurises it, and then repeats the process cycles |
cnckiwi31 | 5:63063a9fa51c | 91 | * number of times |
cnckiwi31 | 5:63063a9fa51c | 92 | * @param cycles: the number of cycles the leg goes up and down |
cnckiwi31 | 14:dd4193213be9 | 93 | * @param targetkPa: the pressure at which the valve is opened to let the leg go down (kPa) |
cnckiwi31 | 14:dd4193213be9 | 94 | * @param inflateTimeOut: (s) if inflation takes longer than this, experiment is assumed to fail and stops, saving data |
cnckiwi31 | 14:dd4193213be9 | 95 | * @param deflateTimeOut: (s) if deflation takes longer than this, experiment is assumed to fail and stops, saving data |
cnckiwi31 | 15:a84d54e25775 | 96 | * @param logHz: datalogging frequency |
cnckiwi31 | 5:63063a9fa51c | 97 | */ |
cnckiwi31 | 15:a84d54e25775 | 98 | void runFatigueExperiment0(int cycles, float targetkPa, float inflateTimeOut, float deflateTimeOut,int logHz) |
megrootens | 0:3855d4588f76 | 99 | { |
cnckiwi31 | 14:dd4193213be9 | 100 | //method constants |
cnckiwi31 | 14:dd4193213be9 | 101 | Timer flowT;//timer used to time flow into and out of actuator |
cnckiwi31 | 15:a84d54e25775 | 102 | |
cnckiwi31 | 15:a84d54e25775 | 103 | float loopTime = 1/logHz; //(s) time between checking pressure |
cnckiwi31 | 15:a84d54e25775 | 104 | |
cnckiwi31 | 15:a84d54e25775 | 105 | //number of data files to save (so we can create a safety barrier |
cnckiwi31 | 15:a84d54e25775 | 106 | //when lots of cycles are done e.g. you may want 100 cycles in each file |
cnckiwi31 | 15:a84d54e25775 | 107 | //so if something goes wrong, you will have most of the data, to within a 100 cycles) |
cnckiwi31 | 15:a84d54e25775 | 108 | int num_file = 1; |
cnckiwi31 | 5:63063a9fa51c | 109 | |
surajgiri | 11:fc82dd22a527 | 110 | for (int i=0; i<num_file; i++) { |
cnckiwi31 | 14:dd4193213be9 | 111 | //record data |
cnckiwi31 | 14:dd4193213be9 | 112 | leg.StartLogging(); |
cnckiwi31 | 14:dd4193213be9 | 113 | //Stop the Bench class from printing, so this method can print |
cnckiwi31 | 14:dd4193213be9 | 114 | leg.pausePrint(); |
cnckiwi31 | 14:dd4193213be9 | 115 | |
cnckiwi31 | 14:dd4193213be9 | 116 | // Pressurise and depressurise the leg cycles number of times |
cnckiwi31 | 5:63063a9fa51c | 117 | for (int i=0; i<cycles; i++) { |
cnckiwi31 | 14:dd4193213be9 | 118 | leg.pc.printf("\r\nCycle: \t%i out of \t%i",i+1,cycles);//print the cycle number |
cnckiwi31 | 14:dd4193213be9 | 119 | |
cnckiwi31 | 5:63063a9fa51c | 120 | //Update cycles logged |
cnckiwi31 | 5:63063a9fa51c | 121 | float data[] = {targetkPa,i+1}; |
cnckiwi31 | 5:63063a9fa51c | 122 | leg.setExtraData(data); |
cnckiwi31 | 5:63063a9fa51c | 123 | |
cnckiwi31 | 5:63063a9fa51c | 124 | //Pressurise |
cnckiwi31 | 5:63063a9fa51c | 125 | leg.setValve(true); |
surajgiri | 11:fc82dd22a527 | 126 | flowT.reset(); |
surajgiri | 11:fc82dd22a527 | 127 | flowT.start();// start inflation timer |
cnckiwi31 | 14:dd4193213be9 | 128 | |
cnckiwi31 | 14:dd4193213be9 | 129 | //Wait until measured pressure reaches target pressure or inflation time out is reached |
cnckiwi31 | 14:dd4193213be9 | 130 | while((leg.getPressure0()*100 < targetkPa) && (flowT.read() < inflateTimeOut)) { |
cnckiwi31 | 14:dd4193213be9 | 131 | //if Logging stopped (by user) |
cnckiwi31 | 14:dd4193213be9 | 132 | if (!leg.isLogging()) { |
cnckiwi31 | 14:dd4193213be9 | 133 | leg.pc.printf("\r\nUser stop during inflation exit"); |
cnckiwi31 | 14:dd4193213be9 | 134 | leg.setValve(false); //Depressurise |
cnckiwi31 | 14:dd4193213be9 | 135 | leg.StopLogging(); //Stop logging data |
cnckiwi31 | 14:dd4193213be9 | 136 | leg.resumePrint(); //Let the Bench class print |
cnckiwi31 | 14:dd4193213be9 | 137 | return;//exit method |
cnckiwi31 | 14:dd4193213be9 | 138 | } |
cnckiwi31 | 14:dd4193213be9 | 139 | leg.LogData();//record datapoint |
cnckiwi31 | 14:dd4193213be9 | 140 | wait(loopTime);//Wait a bit |
cnckiwi31 | 14:dd4193213be9 | 141 | } |
cnckiwi31 | 14:dd4193213be9 | 142 | |
cnckiwi31 | 14:dd4193213be9 | 143 | leg.pc.printf("\r\nTimer inflate: \t%7.2f",flowT.read()); |
cnckiwi31 | 14:dd4193213be9 | 144 | //if inflation timer times out |
cnckiwi31 | 14:dd4193213be9 | 145 | if(flowT.read() >= inflateTimeOut) { |
cnckiwi31 | 14:dd4193213be9 | 146 | leg.pc.printf("\r\nInflation timeout exit"); |
cnckiwi31 | 14:dd4193213be9 | 147 | leg.setValve(false); //Depressurise |
cnckiwi31 | 14:dd4193213be9 | 148 | leg.StopLogging(); //Stop logging data |
cnckiwi31 | 14:dd4193213be9 | 149 | leg.resumePrint(); //Let the Bench class print |
cnckiwi31 | 14:dd4193213be9 | 150 | return;//exit method |
cnckiwi31 | 14:dd4193213be9 | 151 | } |
cnckiwi31 | 14:dd4193213be9 | 152 | |
cnckiwi31 | 14:dd4193213be9 | 153 | //Depressurise |
cnckiwi31 | 14:dd4193213be9 | 154 | leg.setValve(false); |
cnckiwi31 | 14:dd4193213be9 | 155 | flowT.reset(); //reset timer (no need to start as it is already going) |
surajgiri | 11:fc82dd22a527 | 156 | |
cnckiwi31 | 14:dd4193213be9 | 157 | /*Wait until depressurised (completely depressurised is |
cnckiwi31 | 14:dd4193213be9 | 158 | around 10-12 kPa due to current sensor calibration) or deflation |
cnckiwi31 | 14:dd4193213be9 | 159 | timeout is reached*/ |
cnckiwi31 | 14:dd4193213be9 | 160 | while((leg.getPressure0()*100 > 15) && (flowT.read() < deflateTimeOut)) { |
cnckiwi31 | 14:dd4193213be9 | 161 | //if Logging stopped (by user) |
surajgiri | 11:fc82dd22a527 | 162 | if (!leg.isLogging()) { |
cnckiwi31 | 14:dd4193213be9 | 163 | leg.pc.printf("\r\nUser stop during deflation exit"); |
cnckiwi31 | 5:63063a9fa51c | 164 | leg.setValve(false); //Depressurise |
surajgiri | 11:fc82dd22a527 | 165 | leg.StopLogging(); //Stop logging data |
cnckiwi31 | 5:63063a9fa51c | 166 | leg.resumePrint(); //Let the Bench class print |
cnckiwi31 | 5:63063a9fa51c | 167 | return; |
cnckiwi31 | 5:63063a9fa51c | 168 | } |
cnckiwi31 | 14:dd4193213be9 | 169 | leg.LogData();//record a datapoint |
surajgiri | 11:fc82dd22a527 | 170 | wait(loopTime);//Wait a bit |
surajgiri | 11:fc82dd22a527 | 171 | } |
surajgiri | 11:fc82dd22a527 | 172 | |
cnckiwi31 | 14:dd4193213be9 | 173 | leg.pc.printf("\r\nTimer deflate: \t%7.2f",flowT.read()); |
cnckiwi31 | 14:dd4193213be9 | 174 | //if inflation timer runs out |
cnckiwi31 | 14:dd4193213be9 | 175 | if(flowT.read() >= deflateTimeOut) { |
cnckiwi31 | 14:dd4193213be9 | 176 | leg.pc.printf("\r\nDeflation timeout exit"); |
surajgiri | 11:fc82dd22a527 | 177 | leg.setValve(false); //Depressurise |
surajgiri | 11:fc82dd22a527 | 178 | leg.StopLogging(); //Stop logging data |
surajgiri | 11:fc82dd22a527 | 179 | leg.resumePrint(); //Let the Bench class print |
surajgiri | 11:fc82dd22a527 | 180 | return; |
cnckiwi31 | 5:63063a9fa51c | 181 | } |
surajgiri | 11:fc82dd22a527 | 182 | } |
megrootens | 0:3855d4588f76 | 183 | |
cnckiwi31 | 14:dd4193213be9 | 184 | /* Logging stopped as experiment is fully completed (desired number of cycles |
cnckiwi31 | 14:dd4193213be9 | 185 | reached)*/ |
cnckiwi31 | 15:a84d54e25775 | 186 | leg.pc.printf("\r\nExit Fatigue Test"); |
cnckiwi31 | 14:dd4193213be9 | 187 | leg.setValve(false); //Depressurise |
cnckiwi31 | 14:dd4193213be9 | 188 | leg.StopLogging(); //Stop logging data |
cnckiwi31 | 14:dd4193213be9 | 189 | leg.resumePrint(); //Let the Bench class print |
megrootens | 0:3855d4588f76 | 190 | } |
megrootens | 0:3855d4588f76 | 191 | } |
megrootens | 0:3855d4588f76 | 192 | |
cnckiwi31 | 14:dd4193213be9 | 193 | /** |
cnckiwi31 | 14:dd4193213be9 | 194 | * This experiment pressurises the actuator under test to |
cnckiwi31 | 14:dd4193213be9 | 195 | * pressure targetkPa and then depressurises it. It is assumed the user is slowly |
cnckiwi31 | 14:dd4193213be9 | 196 | * increasing the actuator pressure by manually opening up the pressure regulator |
cnckiwi31 | 14:dd4193213be9 | 197 | * connected to the actuator. It is also assumed that the user will stop inflation |
cnckiwi31 | 14:dd4193213be9 | 198 | * if they deem the actuator to have failed. |
cnckiwi31 | 14:dd4193213be9 | 199 | * @param targetkPa: the pressure at which the valve is opened to deflate the actuator (kPa) |
cnckiwi31 | 15:a84d54e25775 | 200 | * @param logHz: datalogging frequency |
cnckiwi31 | 14:dd4193213be9 | 201 | */ |
cnckiwi31 | 15:a84d54e25775 | 202 | void runFailureExperiment0(float targetkPa,int logHz) |
cnckiwi31 | 14:dd4193213be9 | 203 | { |
cnckiwi31 | 15:a84d54e25775 | 204 | double logTime = 1/logHz;//s interval between logging data |
cnckiwi31 | 15:a84d54e25775 | 205 | |
cnckiwi31 | 14:dd4193213be9 | 206 | //Pressurise the actuator under test |
surajgiri | 11:fc82dd22a527 | 207 | leg.StartLogging(); |
cnckiwi31 | 14:dd4193213be9 | 208 | leg.setValve(true); |
cnckiwi31 | 14:dd4193213be9 | 209 | |
cnckiwi31 | 14:dd4193213be9 | 210 | //until the user presses the key to stop datalogging or the target max test |
cnckiwi31 | 14:dd4193213be9 | 211 | //pressure is reached |
cnckiwi31 | 14:dd4193213be9 | 212 | while(leg.isLogging() && (leg.getPressure0()*100 < targetkPa)) { |
cnckiwi31 | 14:dd4193213be9 | 213 | leg.pc.printf("\r\nPressure (kPa): \t%7.2f",leg.getPressure0()*100);//print the pressure |
cnckiwi31 | 14:dd4193213be9 | 214 | leg.LogData();//record a datapoint |
cnckiwi31 | 15:a84d54e25775 | 215 | wait(logTime);//wait |
surajgiri | 11:fc82dd22a527 | 216 | } |
cnckiwi31 | 14:dd4193213be9 | 217 | |
cnckiwi31 | 14:dd4193213be9 | 218 | //Depressurise when the user is done with benchmarking or the target pressure is |
cnckiwi31 | 14:dd4193213be9 | 219 | //reached |
cnckiwi31 | 15:a84d54e25775 | 220 | leg.pc.printf("\r\nExit Failure Test"); |
surajgiri | 11:fc82dd22a527 | 221 | leg.setValve(false); |
surajgiri | 11:fc82dd22a527 | 222 | leg.StopLogging(); //Stop logging data |
cnckiwi31 | 14:dd4193213be9 | 223 | leg.resumePrint(); //Let the Bench class print |
surajgiri | 11:fc82dd22a527 | 224 | } |
surajgiri | 11:fc82dd22a527 | 225 | |
surajgiri | 11:fc82dd22a527 | 226 | /** |
cnckiwi31 | 14:dd4193213be9 | 227 | * A method used to benchmark the actuator under test before the linear actuator |
cnckiwi31 | 14:dd4193213be9 | 228 | * was fitted to the test rig. It simply pressurises the actuator and records data |
cnckiwi31 | 15:a84d54e25775 | 229 | * @param logHz: datalogging frequency |
cnckiwi31 | 14:dd4193213be9 | 230 | */ |
cnckiwi31 | 15:a84d54e25775 | 231 | void runBenchmarkExperiment0(int logHz) |
cnckiwi31 | 14:dd4193213be9 | 232 | { |
cnckiwi31 | 15:a84d54e25775 | 233 | double logTime = 1/logHz;//s interval between logging data |
cnckiwi31 | 15:a84d54e25775 | 234 | |
cnckiwi31 | 14:dd4193213be9 | 235 | //Pressurise the actuator under test |
cnckiwi31 | 14:dd4193213be9 | 236 | leg.StartLogging(); |
cnckiwi31 | 14:dd4193213be9 | 237 | leg.setValve(true);//inflation |
cnckiwi31 | 14:dd4193213be9 | 238 | while(leg.isLogging()) {//until the user presses the key to stop datalogging |
cnckiwi31 | 14:dd4193213be9 | 239 | leg.pc.printf("\r\nPressure (kPa): \t%7.2f",leg.getPressure0()*100); //print the pressure |
cnckiwi31 | 14:dd4193213be9 | 240 | leg.LogData();//record a datapoint |
cnckiwi31 | 15:a84d54e25775 | 241 | wait(logTime);//wait |
cnckiwi31 | 14:dd4193213be9 | 242 | } |
cnckiwi31 | 14:dd4193213be9 | 243 | |
cnckiwi31 | 14:dd4193213be9 | 244 | //Depressurise when the user is done with benchmarking |
cnckiwi31 | 14:dd4193213be9 | 245 | leg.pc.printf("\r\nExit Benchmarking Test"); |
cnckiwi31 | 14:dd4193213be9 | 246 | leg.setValve(false);//deflate |
cnckiwi31 | 14:dd4193213be9 | 247 | leg.StopLogging(); //Stop logging data |
cnckiwi31 | 14:dd4193213be9 | 248 | leg.resumePrint(); //Let the Bench class print |
cnckiwi31 | 14:dd4193213be9 | 249 | } |
cnckiwi31 | 14:dd4193213be9 | 250 | |
cnckiwi31 | 14:dd4193213be9 | 251 | /** |
cnckiwi31 | 15:a84d54e25775 | 252 | * A benchmark test with the linear actuator. The actuator is cycled from its flexed position, |
cnckiwi31 | 15:a84d54e25775 | 253 | * to the point at which it no longer produces force, and back again. This is considered its range of motion. |
cnckiwi31 | 14:dd4193213be9 | 254 | * NOTE - not extensively tested |
cnckiwi31 | 14:dd4193213be9 | 255 | * @param minForce: (N) force at which cycle goes from extension to flexion |
cnckiwi31 | 14:dd4193213be9 | 256 | * @param maxAngle: (deg) angle at which cycle goes from flexion to extension |
cnckiwi31 | 14:dd4193213be9 | 257 | * @param inflationT: (s) time allowed for actuator to inflate |
cnckiwi31 | 14:dd4193213be9 | 258 | * @param pwm: actuator speed (in %, from 0-100. > 50 is needed to move actuator in practice). |
surajgiri | 11:fc82dd22a527 | 259 | * @param cycles: the number of up and down cycles of the leg |
surajgiri | 11:fc82dd22a527 | 260 | * @param logHz: datalogging frequency |
surajgiri | 11:fc82dd22a527 | 261 | */ |
cnckiwi31 | 14:dd4193213be9 | 262 | void runBenchmarkExperiment1(int minForce, float maxAngle, float inflationT, int pwm, int cycles, int logHz) |
surajgiri | 11:fc82dd22a527 | 263 | { |
surajgiri | 11:fc82dd22a527 | 264 | double logTime = 1/logHz;//s interval between logging data |
cnckiwi31 | 14:dd4193213be9 | 265 | |
surajgiri | 11:fc82dd22a527 | 266 | //Stop the Bench class from printing, so this method can print |
surajgiri | 11:fc82dd22a527 | 267 | leg.pausePrint(); |
surajgiri | 11:fc82dd22a527 | 268 | |
cnckiwi31 | 14:dd4193213be9 | 269 | //Pressurise the actuator, giving it inflationT to do so |
surajgiri | 11:fc82dd22a527 | 270 | leg.setValve(true); |
surajgiri | 11:fc82dd22a527 | 271 | Timer t; |
surajgiri | 11:fc82dd22a527 | 272 | t.reset(); |
surajgiri | 11:fc82dd22a527 | 273 | t.start(); |
cnckiwi31 | 14:dd4193213be9 | 274 | while(leg.isLogging() && t.read() < inflationT) { |
cnckiwi31 | 14:dd4193213be9 | 275 | leg.pc.printf("\r\nPressure (kPa): \t%7.2f",leg.getPressure0()*100);//print the pressure |
cnckiwi31 | 14:dd4193213be9 | 276 | wait(0.2);//wait a bit |
surajgiri | 11:fc82dd22a527 | 277 | } |
cnckiwi31 | 14:dd4193213be9 | 278 | |
cnckiwi31 | 14:dd4193213be9 | 279 | //Now actuator is inflated, the test can start |
surajgiri | 11:fc82dd22a527 | 280 | leg.StartLogging(); |
surajgiri | 11:fc82dd22a527 | 281 | // in loop |
surajgiri | 11:fc82dd22a527 | 282 | for (int i=0; i<cycles; i++) { |
surajgiri | 11:fc82dd22a527 | 283 | //allow leg to go up until force is below threshold |
surajgiri | 11:fc82dd22a527 | 284 | leg.setPWM(pwm); |
surajgiri | 11:fc82dd22a527 | 285 | leg.setDir(0); |
cnckiwi31 | 14:dd4193213be9 | 286 | |
cnckiwi31 | 14:dd4193213be9 | 287 | leg.pc.printf("\r\nExtending: \t%i",cycles);//print which cycle we are on |
cnckiwi31 | 14:dd4193213be9 | 288 | |
cnckiwi31 | 14:dd4193213be9 | 289 | //continue while force is above threshold and the user has not stopped logging |
surajgiri | 11:fc82dd22a527 | 290 | while((leg.getForce() >= minForce) && leg.isLogging()) { |
cnckiwi31 | 14:dd4193213be9 | 291 | leg.pc.printf("\r\nForce (N): \t%7.2f",leg.getForce());//feedback on force printed |
cnckiwi31 | 14:dd4193213be9 | 292 | leg.LogData();//record datapoint |
cnckiwi31 | 14:dd4193213be9 | 293 | wait(logTime);//wait |
surajgiri | 11:fc82dd22a527 | 294 | } |
cnckiwi31 | 14:dd4193213be9 | 295 | |
cnckiwi31 | 15:a84d54e25775 | 296 | //If the user stopped |
cnckiwi31 | 15:a84d54e25775 | 297 | if (!leg.isLogging()) { |
cnckiwi31 | 14:dd4193213be9 | 298 | leg.pc.printf("\r\nUser stopped during extension Exit"); |
cnckiwi31 | 14:dd4193213be9 | 299 | leg.setPWM(0); //turn off linear actuator |
surajgiri | 11:fc82dd22a527 | 300 | leg.setValve(false);//Depressurise |
surajgiri | 11:fc82dd22a527 | 301 | leg.StopLogging(); //Stop logging data |
surajgiri | 11:fc82dd22a527 | 302 | leg.resumePrint(); //Let the Bench class print |
surajgiri | 11:fc82dd22a527 | 303 | return; |
surajgiri | 11:fc82dd22a527 | 304 | } |
surajgiri | 11:fc82dd22a527 | 305 | |
surajgiri | 11:fc82dd22a527 | 306 | //allow leg to go down until angle is greater than threshold |
surajgiri | 11:fc82dd22a527 | 307 | leg.setPWM(pwm); |
surajgiri | 11:fc82dd22a527 | 308 | leg.setDir(1); |
cnckiwi31 | 14:dd4193213be9 | 309 | |
cnckiwi31 | 14:dd4193213be9 | 310 | leg.pc.printf("\r\nFlexing: \t%i",cycles); //print which cycle we are on |
cnckiwi31 | 14:dd4193213be9 | 311 | |
cnckiwi31 | 14:dd4193213be9 | 312 | //continue while the angle is less than the threshold and the user has not stopped logging |
surajgiri | 11:fc82dd22a527 | 313 | while((leg.getDegrees(0) <= maxAngle) && leg.isLogging()) { |
cnckiwi31 | 14:dd4193213be9 | 314 | leg.pc.printf("\r\nAngle (deg): \t%7.2f",leg.getDegrees(0));//feedback on angle printed |
cnckiwi31 | 14:dd4193213be9 | 315 | leg.LogData();//record datapoint |
cnckiwi31 | 14:dd4193213be9 | 316 | wait(logTime);//wait |
surajgiri | 11:fc82dd22a527 | 317 | } |
cnckiwi31 | 14:dd4193213be9 | 318 | |
cnckiwi31 | 15:a84d54e25775 | 319 | //If the user stopped |
cnckiwi31 | 15:a84d54e25775 | 320 | if (!leg.isLogging()) { |
cnckiwi31 | 14:dd4193213be9 | 321 | leg.pc.printf("\r\nUser stopped during flexion Exit"); |
surajgiri | 11:fc82dd22a527 | 322 | leg.setPWM(0); |
surajgiri | 11:fc82dd22a527 | 323 | leg.setValve(false);//Depressurise |
surajgiri | 11:fc82dd22a527 | 324 | leg.StopLogging(); //Stop logging data |
surajgiri | 11:fc82dd22a527 | 325 | leg.resumePrint(); //Let the Bench class print |
surajgiri | 11:fc82dd22a527 | 326 | return; |
surajgiri | 11:fc82dd22a527 | 327 | } |
surajgiri | 11:fc82dd22a527 | 328 | } |
cnckiwi31 | 14:dd4193213be9 | 329 | |
cnckiwi31 | 14:dd4193213be9 | 330 | //Depressurise when the desired number of cycles are completed |
surajgiri | 11:fc82dd22a527 | 331 | leg.pc.printf("\r\nExit Benchmarking Test"); |
cnckiwi31 | 14:dd4193213be9 | 332 | leg.setPWM(0);//motor off |
cnckiwi31 | 14:dd4193213be9 | 333 | leg.setValve(false);//actuator depressurised |
surajgiri | 11:fc82dd22a527 | 334 | leg.StopLogging(); //Stop logging data |
surajgiri | 11:fc82dd22a527 | 335 | leg.resumePrint(); //Let the Bench class print |
surajgiri | 11:fc82dd22a527 | 336 | } |
surajgiri | 11:fc82dd22a527 | 337 |