From c1364c45e452f05a43e4b4f6a204bc819132f8c2 Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 17 Dec 2019 17:26:33 +0100 Subject: [PATCH] add timing tests --- other/filtertest/filtertest.pde | 82 +++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/other/filtertest/filtertest.pde b/other/filtertest/filtertest.pde index 223156c..65ebe20 100644 --- a/other/filtertest/filtertest.pde +++ b/other/filtertest/filtertest.pde @@ -15,8 +15,8 @@ long lastHBLoop=0; int ADC_CALIB_THROTTLE_MIN=2000; //controller int ADC_CALIB_THROTTLE_MAX=3120; //controller int ADC_READTIME=10; //controller. in ms -int adc_throttle_raw=0; //controller. raw value read from adc (here slider) -float adc_throttle=0; //controller. internally filtered value +int adc_throttle_raw=ADC_CALIB_THROTTLE_MIN; //controller. raw value read from adc (here slider) +float adc_throttle=adc_throttle_raw; //controller. internally filtered value float ADC_THROTTLE_FILTER=0.05; //controller int SENDPERIOD=50; //controller. in ms @@ -36,6 +36,13 @@ Slider SoutSpeed; int inputValue = ADC_CALIB_THROTTLE_MIN; int maxvalue=1000; +int timetestMode=0; +long timeteststarted_time=0; +int outSpeedThresholdIncrease=int(1000*0.707); //threshold for timing stop for increasing speed +int outSpeedThresholdDecrease=int(1000*(1-0.707)); //threshold for timing stop for decreasing speed +long timingtest_start=0; //for timing testing +long timingtest_end=0; //for timing testing + void setup() { frameRate(int(1000.0/5)); size(700,400); @@ -62,7 +69,7 @@ void setup() { ; SoutSpeed=cp5.addSlider("outSpeed") - .setPosition(10,50+30+10+20+10+20+10) + .setPosition(1,50+30+10+20+10+20+10) .setSize(500,30) .setRange(0,1000) ; @@ -72,6 +79,73 @@ void setup() { void draw() { long loopmillis=millis(); + + //Time testing + + switch (timetestMode) { + case 0: //started + println("Starting Timing Test 'Increase'. Startvalue="+ADC_CALIB_THROTTLE_MIN); + SinputValue.setValue(ADC_CALIB_THROTTLE_MIN); //reset values to minimum + SfilteredInputValue.setValue(ADC_CALIB_THROTTLE_MIN); + SspeedRate.setValue(0); + SoutSpeed.setValue(0); + timetestMode++; + timeteststarted_time=loopmillis; + break; + case 1: //wait some time + if (loopmillis-timeteststarted_time>1000){ + println("Set input to value="+ADC_CALIB_THROTTLE_MAX); + timetestMode++; + SinputValue.setValue(ADC_CALIB_THROTTLE_MAX); //Jump value + timingtest_start=loopmillis; + } + break; + case 2: //wait until threshold reached + if (outSpeed>=outSpeedThresholdIncrease){ + println("Threshold "+outSpeed+" (outSpeed) reached"); + timetestMode++; + timingtest_end=loopmillis; + println("Increase Time="+(timingtest_end-timingtest_start)+"ms"); + timeteststarted_time=loopmillis; + } + break; + + case 3: //wait some time in between test + if (loopmillis-timeteststarted_time>1000){ + println("Waiting between tests"); + timetestMode++; + timingtest_start=loopmillis; + } + break; + + case 4://started + println("Starting Timing Test 'Decrease'. Startvalue="+ADC_CALIB_THROTTLE_MAX); + SinputValue.setValue(ADC_CALIB_THROTTLE_MAX); //reset values to maximum + SfilteredInputValue.setValue(ADC_CALIB_THROTTLE_MAX); + SspeedRate.setValue(1000); + SoutSpeed.setValue(1000); + timetestMode++; + break; + case 5: //wait some time + if (loopmillis-timeteststarted_time>1000){ + println("Set input to value="+ADC_CALIB_THROTTLE_MIN); + timetestMode++; + SinputValue.setValue(ADC_CALIB_THROTTLE_MIN); //Jump value + timingtest_start=loopmillis; + } + break; + case 6: //wait until threshold reached + if (outSpeed<=outSpeedThresholdDecrease){ + println("Threshold "+outSpeed+" (outSpeed) reached"); + timetestMode++; + timingtest_end=loopmillis; + println("Decrease Time="+(timingtest_end-timingtest_start)+"ms"); + } + break; + } + + + if (loopmillis-lastReadADC>ADC_READTIME){ //frequency of controller adc read/filtering lastReadADC=millis(); adc_throttle_raw = inputValue; //adc_throttle_raw = analogRead(PIN_THROTTLE); @@ -112,6 +186,8 @@ void draw() { //fill(inputValue*1.0/maxvalue*255); //rect(0,0,width,100); + + } /*