HeRoS: read out and log joint angles and force sensor data from the leg test bench. Now with additional features to read pressure sensors and set the null values of the pressure and force sensors

Dependencies:   SPTE_10Bar_5V mbed AS5048 SDFileSystem MODSERIAL PinDetect Valve LCM101

Fork of heros_leg_readout_torque_addition by K K

main.cpp

Committer:
cnckiwi31
Date:
2019-12-09
Revision:
5:63063a9fa51c
Parent:
4:1cdce6c6c94e
Child:
10:77fcbad99a31

File content as of revision 5:63063a9fa51c:

/**
* Author: Allan Veale
* Date: 27/11/19
* Purpose: Datalog from the active wearable test rig fitted with the first
* realistic (foam tissue) leg
*/

//Both the general mbed header and the test rig bench header are needed 
#include "mbed.h"
#include "bench.h"

//Example experiment method 
void runDemoExperiment0(int cycles, float targetkPa);

// Create bench object - this is used to control the test rig
Bench leg;

/**
 * Main loop
 */
int main()
{   
    leg.setLoggingFrequency(100); //Set datalogging frequency
    
    /* Two extra columns of data will be recorded in this experiment.
    One for the target pressure, and the other for the number of sit and 
    stand cycles currently completed in the experiment */ 
    string colNames[] = {"Target pressure (kPa)","Cycle"}; //add data headings
    leg.setExtraColumns(colNames,2);
    
    float targetP = 200; //Target pressure in kPa
    int expCycles = 2; //Number of sit to stand to sit cycles 
    float vals[] = {targetP,0}; //set initial values of data that will be logged
    leg.setExtraData(vals);
    
    /* Setup all peripherals on rig, display info about SD card and the 
    user interface menu */ 
    leg.initialise(); 

      
    /*Run an experiment when the button is pressed to start datalogging and 
    stop it if the button is pressed again to stop datalogging 
    (or when experiment stops - then datalogging stops by itself) */
    while (true) {
        if (leg.isLogging()) {
            runDemoExperiment0(expCycles,targetP);            
        }
    }
}

/**
 * Shows how a demo experiment works. This experiment pressurises the leg to 
 * pressure targetkPa, depressurises it, and then repeats the process cycles 
 * number of times
 * @param cycles: the number of cycles the leg goes up and down
 * @param targetkPa: the pressure at which the valve is opened to let the leg go down
 */
void runDemoExperiment0(int cycles, float targetkPa) 
{
    //The experiment starts when logging does
    bool experimentRunning = leg.isLogging(); 
    
    //Stop the Bench class from printing, so this method can print
    leg.pausePrint();
    
    if (experimentRunning) {
        // Pressurise and depressurise the leg cycles number of times
        for (int i=0; i<cycles; i++) {
            leg.pc.printf("\r\nCycle: \t%i out of \t%i",i+1,cycles);
            
            //Update cycles logged
            float data[] = {targetkPa,i+1};
            leg.setExtraData(data);

            //Pressurise
            leg.setValve(true);

            //Wait until measured pressure reaches target pressure
            float measureP = 0;
            while(measureP < targetkPa) {
                //Keep checking logging is going
                experimentRunning = leg.isLogging(); 
                
                if (experimentRunning) {
                    measureP = leg.getPressure0()*100;//Conversion of bar to kPa
                    wait(0.2);//Wait a bit
                } else { //Logging stopped
                    leg.stopLogging(); //Stop logging data
                    leg.setValve(false); //Depressurise
                    leg.resumePrint(); //Let the Bench class print
                    return;
                }
            }

            //Depressurise
            leg.setValve(false);

            /*Wait until depressurised (completely depressurised is 
            around 10-12 kPa due to current sensor calibration)*/
            while(measureP > 15) {
                //Keep checking logging is going
                experimentRunning = leg.isLogging();
                
                if (experimentRunning) {
                    measureP = leg.getPressure0()*100;//Conversion of bar to kpa
                    wait(0.2);//Wait a bit
                } else { //Logging stopped
                    leg.stopLogging(); //Stop logging data
                    leg.resumePrint(); //Let the Bench class print
                    return;
                }
            }
        }
        // Logging stopped as experiment is fully completed
        leg.stopLogging(); //Stop logging data
        leg.resumePrint(); //Let the Bench class print
    }
}