Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Control System (http://www.chiefdelphi.com/forums/forumdisplay.php?f=177)
-   -   Thread scheduler for PID period control ? (http://www.chiefdelphi.com/forums/showthread.php?t=125484)

gpetilli 30-01-2014 10:38

Thread scheduler for PID period control ?
 
We are trying to optimize our custom PID loop and appear to be getting conflicting data that I am hoping someone can clarify.

1) From numerous CD threads, I believe that the standard teleopPeriodic time is initiated from the drivers station at approximately a 20ms rate. However, at least two threads mention a 50ms periodic rate (older IFI rate?).
2) I have seen several threads which recommend using a separate thread based on the OS scheduler for tighter tolerance. Team 358 "Timing is Everything" white paper is an excellent reference. 10ms seems like a common period for PID.
3) The PID_control class does use the scheduler to create its own thread. I thought I saw on CD the default period was 20ms, but the Java Docs say it is 50ms.

So now here is our confusion.
4) We set up a timed PID thread with period 10ms. We set up a delta time measurement in both the teleop periodic and timed PID loops and plotted the delta times. The timed loop was 20ms +/- 4ms and the periodic was closer to 50ms +20/-10ms. Setting the period to 20ms gave about the same response.
This was done using Java on the older 8 slot cRIO on our test chassis. We do not yet have access to the production 4 slot cRIO. I can believe the old cRIO cant do the 10ms period but that does not explain the 50ms for the drivers station. I have not hooked up a scope to a DSC pin to confirm that the time reported by the OS is accurate.

The timing is clearly faster and more consistent with the timed loop, but I hate unexplained behaviors.

Does anyone know if the periods on the older cRIO were different and if the driver station software adapts? Is the delta time reported by the OS accurate? What period are people using for PID loops?

Ether 30-01-2014 11:48

Re: Thread scheduler for PID period control ?
 

The TeleOp period is 20ms (50Hz).

The default period for Java PID thread is 50ms (or at least it was in 2013).

Excerpt from 2013 PIDcontroller.java:

Code:

/**
 * Class implements a PID Control Loop.
 *
 * Creates a separate thread which reads the given PIDSource and takes
 * care of the integral calculations, as well as writing the given
 * PIDOutput
 */
public class PIDController implements IUtility, LiveWindowSendable, Controller {

    public static final double kDefaultPeriod = .05;


  /**
    * Allocate a PID object with the given constants for P, I, D, and F
    * @param Kp the proportional coefficient
    * @param Ki the integral coefficient
    * @param Kd the derivative coefficient
    * @param Kf the feed forward term
    * @param source The PIDSource object that is used to get values
    * @param output The PIDOutput object that is set to the output percentage
    * @param period the loop time for doing calculations. This particularly effects calculations of the
    * integral and differential terms. The default is 50ms.
    */
    public PIDController(double Kp, double Ki, double Kd, double Kf,
            PIDSource source, PIDOutput output,
            double period) {


Ether 30-01-2014 12:08

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by gpetilli (Post 1334731)
We set up a timed PID thread with period 10ms. We set up a delta time measurement in both the teleop periodic and timed PID loops and plotted the delta times.

Could you give some additional detail on how you set up the delta time measurement?

For example, did you do it like this:

Code:

// begin thread
new_time = get_time();
delta_time = new_time - previous_time;
previous_time = new_time;
.
.// do stuff here
.
// end thread

or like this:

Code:

// begin thread
start_time = get_time();
.
.// do stuff here
.
delta_time = get_time() - begin_time;
// end thread

or something else?



Joe Ross 30-01-2014 12:37

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Ether (Post 1334785)
Could you give some additional detail on how you set up the delta time measurement?

In addition, what method did you use to get the time?



What computer did you run the DS on?

gpetilli 31-01-2014 14:31

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Ether (Post 1334785)
Could you give some additional detail on how you set up the delta time measurement?


[/i]

We did it like this:

Code:

// begin thread
new_time = get_time();
delta_time = new_time - previous_time;
previous_time = new_time;
.
.// do stuff here
.
// end thread


gpetilli 31-01-2014 14:33

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Joe Ross (Post 1334813)
In addition, what method did you use to get the time?



What computer did you run the DS on?

It was a windows 7 lenovo - not sure the exact model but not more than two years old and definitely not a netbook. We did this tethered, not on WiFi.

Joe Ross 31-01-2014 21:58

Re: Thread scheduler for PID period control ?
 
I just ran the following code:

Code:

    double prevTime = 0;
    public void teleopPeriodic() {
        double time = Timer.getFPGATimestamp();
        System.out.println(time-prevTime);
        prevTime=time;
    }

And got the following output:

Code:

[cRIO] 0.014032000000000266
[cRIO] 0.020156000000000063
[cRIO] 0.02008299999999963
[cRIO] 0.019773999999998182
[cRIO] 0.019995999999999015
[cRIO] 0.020203999999999667
[cRIO] 0.01987100000000197
[cRIO] 0.020114999999996996
[cRIO] 0.02004800000000273
[cRIO] 0.02036799999999772
[cRIO] 0.019611000000004708
[cRIO] 0.019765999999997064
[cRIO] 0.019995999999999015
[cRIO] 0.019989000000002477
[cRIO] 0.02004999999999768
[cRIO] 0.019984999999998365
[cRIO] 0.0200450000000032
[cRIO] 0.019925000000000637
[cRIO] 0.019964999999999122
[cRIO] 0.020108999999997934
[cRIO] 0.020091000000000747
[cRIO] 0.019836000000005072
[cRIO] 0.019992999999999483
[cRIO] 0.02026199999999534
[cRIO] 0.019725000000001103
[cRIO] 0.019995999999999015
[cRIO] 0.020110000000002515
[cRIO] 0.019950999999998942
[cRIO] 0.019914999999997463
[cRIO] 0.020150000000001
[cRIO] 0.019964999999999122
[cRIO] 0.019953000000000998
[cRIO] 0.02007000000000403
[cRIO] 0.023333000000000936
[cRIO] 0.016567999999999472
[cRIO] 0.019990999999997427
[cRIO] 0.019987999999997896
[cRIO] 0.02036199999999866
[cRIO] 0.019624000000000308
[cRIO] 0.020121000000003164
[cRIO] 0.02003100000000302
[cRIO] 0.01989399999999364
[cRIO] 0.020100000000006446
[cRIO] 0.019787999999998362
[cRIO] 0.02019099999999696
[cRIO] 0.019915000000004568
[cRIO] 0.019970999999998185
[cRIO] 0.020511999999996533
[cRIO] 0.019507000000004382
[cRIO] 0.020938999999998487
[cRIO] 0.01930399999999821
[cRIO] 0.020080999999997573
[cRIO] 0.019986000000002946
[cRIO] 0.0199089999999984
[cRIO] 0.020019000000004894
[cRIO] 0.019859999999994216
[cRIO] 0.020032000000000494
[cRIO] 0.020005000000004713
[cRIO] 0.01986199999999627
[cRIO] 0.020163000000003706
[cRIO] 0.020060000000000855
[cRIO] 0.019814999999994143
[cRIO] 0.02012300000000522
[cRIO] 0.019915999999994938
[cRIO] 0.019857999999999265
[cRIO] 0.020221000000006484
[cRIO] 0.01981199999999461
[cRIO] 0.02013300000000129
[cRIO] 0.020065000000002442
[cRIO] 0.01982299999999526
[cRIO] 0.020184000000000424
[cRIO] 0.019892000000005794
[cRIO] 0.02009899999999476
[cRIO] 0.01988500000000215
[cRIO] 0.02012200000000064
[cRIO] 0.019989999999999952
[cRIO] 0.019863999999998327
[cRIO] 0.02014700000000147
[cRIO] 0.019995999999999015
[cRIO] 0.020175999999999306
[cRIO] 0.019838000000000022
[cRIO] 0.019888999999999157
[cRIO] 0.020115000000004102
[cRIO] 0.020016999999995733
[cRIO] 0.01998400000000089
[cRIO] 0.020042000000003668
[cRIO] 0.01999999999999602
[cRIO] 0.01975800000000305
[cRIO] 0.0200139999999962
[cRIO] 0.020180000000003417
[cRIO] 0.019850999999995622
[cRIO] 0.02010900000000504
[cRIO] 0.020080000000000098
[cRIO] 0.020117999999996528
[cRIO] 0.019851000000002728
[cRIO] 0.020186999999999955
[cRIO] 0.020111999999997465
[cRIO] 0.020330999999998767
[cRIO] 0.019290000000005136
[cRIO] 0.02057199999999426
[cRIO] 0.019626000000002364
[cRIO] 0.01993500000000381
[cRIO] 0.020097999999997285
[cRIO] 0.021600999999996873
[cRIO] 0.01841500000000451
[cRIO] 0.019878999999995983
[cRIO] 0.020146000000003994
[cRIO] 0.020054000000001793
[cRIO] 0.020954999999993618
[cRIO] 0.018789000000005274
[cRIO] 0.022835000000000605
[cRIO] 0.017481999999994002
[cRIO] 0.019851000000002728
[cRIO] 0.019829999999998904
[cRIO] 0.02016400000000118
[cRIO] 0.020018000000000313
[cRIO] 0.019930000000002224
[cRIO] 0.020049000000000206
[cRIO] 0.020051999999999737
[cRIO] 0.02079599999999715
[cRIO] 0.019050999999997487
[cRIO] 0.022271000000003482
[cRIO] 0.01766800000000046
[cRIO] 0.02002000000000237
[cRIO] 0.020178999999998837
[cRIO] 0.02001899999999779
[cRIO] 0.019908000000000925
[cRIO] 0.020046000000000674
[cRIO] 0.020044999999996094
[cRIO] 0.019980000000003884
[cRIO] 0.01983699999999544
[cRIO] 0.02458000000000027
[cRIO] 0.0157040000000066
[cRIO] 0.01980599999999555
[cRIO] 0.020093000000002803
[cRIO] 0.0201279999999997
[cRIO] 0.019898999999995226
[cRIO] 0.020168000000005293
[cRIO] 0.019810999999997136
[cRIO] 0.020003000000002658
[cRIO] 0.019991999999994903
[cRIO] 0.022979000000006522
[cRIO] 0.01685799999999915
[cRIO] 0.020008999999994614
[cRIO] 0.019876000000003557
[cRIO] 0.02014599999999689
[cRIO] 0.020217000000002372
[cRIO] 0.020510000000001583
[cRIO] 0.019436999999996374
[cRIO] 0.020022000000004425
[cRIO] 0.01999699999999649
[cRIO] 0.019826999999999373
[cRIO] 0.019909000000005506
[cRIO] 0.02016599999999613
[cRIO] 0.01995600000000053
[cRIO] 0.02026299999999992
[cRIO] 0.019973999999997716
[cRIO] 0.019733999999999696
[cRIO] 0.020008000000004245
[cRIO] 0.020130000000001758
[cRIO] 0.0199439999999953
[cRIO] 0.01991699999999952
[cRIO] 0.020014000000003307
[cRIO] 0.02026499999999487
[cRIO] 0.020091000000000747
[cRIO] 0.019711000000000922
[cRIO] 0.02048200000000122
[cRIO] 0.019823999999999842
[cRIO] 0.020276000000002625
[cRIO] 0.019548000000000343
[cRIO] 0.020054999999999268
[cRIO] 0.021468999999996186
[cRIO] 0.01859900000000181
[cRIO] 0.019700000000000273
[cRIO] 0.019939000000000817
[cRIO] 0.021791000000000338
[cRIO] 0.018093999999997834
[cRIO] 0.020206999999999198
[cRIO] 0.019817000000003304
[cRIO] 0.02050700000000205
[cRIO] 0.020139999999997826
[cRIO] 0.022245999999995547
[cRIO] 0.017315000000003522
[cRIO] 0.01983200000000096
[cRIO] 0.02001200000000125
[cRIO] 0.02009699999999981
[cRIO] 0.019945999999997355
[cRIO] 0.020163000000003706
[cRIO] 0.019883000000000095
[cRIO] 0.01994699999999483
[cRIO] 0.020003000000002658
[cRIO] 0.020181000000000893
[cRIO] 0.01998400000000089
[cRIO] 0.019994999999994434
[cRIO] 0.01981800000000078
[cRIO] 0.020724999999998772
[cRIO] 0.01940400000000153
[cRIO] 0.020572000000001367
[cRIO] 0.019492999999997096
[cRIO] 0.020011000000003776
[cRIO] 0.02001200000000125
[cRIO] 0.019867999999995334
[cRIO] 0.01991699999999952
[cRIO] 0.020219000000004428
[cRIO] 0.019978999999999303
[cRIO] 0.02002199999999732
[cRIO] 0.019750999999999408
[cRIO] 0.02012500000000017
[cRIO] 0.020092000000005328
[cRIO] 0.020537999999994838
[cRIO] 0.019495000000006257
[cRIO] 0.020107999999993353
[cRIO] 0.019899999999999807
[cRIO] 0.020124000000002695
[cRIO] 0.020169000000002768
[cRIO] 0.019700000000000273
[cRIO] 0.020637000000000683
[cRIO] 0.01944199999999796
[cRIO] 0.01986800000000244
[cRIO] 0.020131999999996708
[cRIO] 0.020014000000003307
[cRIO] 0.01990499999999429
[cRIO] 0.02029100000000028
[cRIO] 0.019598999999999478
[cRIO] 0.020002000000005182
[cRIO] 0.02232999999999663
[cRIO] 0.017898000000002412
[cRIO] 0.020381000000000427
[cRIO] 0.01945299999999861
[cRIO] 0.019967000000001178
[cRIO] 0.02024799999999516
[cRIO] 0.019709000000005972
[cRIO] 0.01999399999999696
[cRIO] 0.020249999999997215
[cRIO] 0.019863000000000852
[cRIO] 0.020217000000002372
[cRIO] 0.019892999999996164
[cRIO] 0.020042000000003668
[cRIO] 0.019748999999997352
[cRIO] 0.020043000000001143
[cRIO] 0.0200010000000006
[cRIO] 0.020333000000000823
[cRIO] 0.019875999999996452
[cRIO] 0.019884000000004676
[cRIO] 0.020113000000002046
[cRIO] 0.019994999999994434
[cRIO] 0.02008400000000421
[cRIO] 0.02040299999999462
[cRIO] 0.019336000000002684
[cRIO] 0.020540000000004
[cRIO] 0.01947499999999991
[cRIO] 0.020902999999997007
[cRIO] 0.01910999999999774
[cRIO] 0.019978000000001828
[cRIO] 0.020012999999998726
[cRIO] 0.020107000000002984
[cRIO] 0.01981500000000125
[cRIO] 0.020117999999996528
[cRIO] 0.01991199999999793
[cRIO] 0.020054999999999268
[cRIO] 0.020019000000004894
[cRIO] 0.02013799999999577
[cRIO] 0.019870000000004495
[cRIO] 0.02012099999999606
[cRIO] 0.020061000000005436
[cRIO] 0.019942999999997824
[cRIO] 0.019940999999995768
[cRIO] 0.02003100000000302
[cRIO] 0.019827999999996848
[cRIO] 0.019962000000006697
[cRIO] 0.02714199999999778
[cRIO] 0.01292699999999769
[cRIO] 0.019863999999998327
[cRIO] 0.020138000000002876
[cRIO] 0.02063100000000162
[cRIO] 0.019636999999995908
[cRIO] 0.01994300000000493
[cRIO] 0.02027299999999599
[cRIO] 0.019710000000003447
[cRIO] 0.020027999999996382
[cRIO] 0.020064000000004967
[cRIO] 0.019843999999999085
[cRIO] 0.01997199999999566
[cRIO] 0.02011099999999999
[cRIO] 0.019913999999999987
[cRIO] 0.020194000000003598
[cRIO] 0.019945999999997355
[cRIO] 0.01988099999999804
[cRIO] 0.02000600000000219
[cRIO] 0.020093000000002803
[cRIO] 0.020111999999997465
[cRIO] 0.026910000000000878
[cRIO] 0.012717999999999563
[cRIO] 0.020026999999998907
[cRIO] 0.020040000000001612
[cRIO] 0.020037999999999556
[cRIO] 0.02022699999999844
[cRIO] 0.02054300000000353
[cRIO] 0.01946699999999879
[cRIO] 0.01999699999999649
[cRIO] 0.019892000000005794
[cRIO] 0.01996899999999613
[cRIO] 0.02007199999999898
[cRIO] 0.021723999999998966
[cRIO] 0.01812500000000483
[cRIO] 0.020227999999995916
[cRIO] 0.019947000000001935
[cRIO] 0.0199089999999984
[cRIO] 0.02003400000000255
[cRIO] 0.020015000000000782
[cRIO] 0.02004399999999862
[cRIO] 0.020769999999998845
[cRIO] 0.01921300000000059
[cRIO] 0.019786000000003412
[cRIO] 0.019997999999993965
[cRIO] 0.020124000000002695
[cRIO] 0.019961000000002116
[cRIO] 0.020072999999996455
[cRIO] 0.020029000000000963
[cRIO] 0.020017000000002838
[cRIO] 0.01980999999999966
[cRIO] 0.022269999999998902
[cRIO] 0.017738000000001364
[cRIO] 0.019945999999997355
[cRIO] 0.02023799999999909
[cRIO] 0.019825000000004422
[cRIO] 0.01999999999999602
[cRIO] 0.02022500000000349
[cRIO] 0.019962999999997066
[cRIO] 0.019761000000002582
[cRIO] 0.020324999999999704
[cRIO] 0.01984199999999703
[cRIO] 0.020082000000002154
[cRIO] 0.019743999999995765
[cRIO] 0.020238000000006195
[cRIO] 0.020014999999993677
[cRIO] 0.0198040000000006
[cRIO] 0.02026599999999945
[cRIO] 0.01972000000000662
[cRIO] 0.019998999999998546
[cRIO] 0.01994699999999483
[cRIO] 0.02109500000000253
[cRIO] 0.019206000000004053
[cRIO] 0.019966999999994073
[cRIO] 0.020003000000002658
[cRIO] 0.020752000000001658
[cRIO] 0.01915199999999828
[cRIO] 0.020476999999999634
[cRIO] 0.019496000000003733
[cRIO] 0.019954999999995948
[cRIO] 0.02003700000000208
[cRIO] 0.020058999999996274
[cRIO] 0.02009500000000486
[cRIO] 0.020039999999994507
[cRIO] 0.020006999999999664
[cRIO] 0.019711000000000922
[cRIO] 0.019989000000002477
[cRIO] 0.0201849999999979
[cRIO] 0.019786000000003412
[cRIO] 0.02016100000000165
[cRIO] 0.019966999999994073
[cRIO] 0.019948000000006516
[cRIO] 0.020086999999996635
[cRIO] 0.020040999999999087
[cRIO] 0.020315000000003636
[cRIO] 0.020910999999998126
[cRIO] 0.018869000000002245
[cRIO] 0.01991099999999335
[cRIO] 0.0198960000000028
[cRIO] 0.020060000000000855
[cRIO] 0.020119999999998583
[cRIO] 0.01984600000000114
[cRIO] 0.01997599999999977
[cRIO] 0.020156000000000063
[cRIO] 0.019992000000002008
[cRIO] 0.019875999999996452
[cRIO] 0.019952000000003522
[cRIO] 0.02003899999999703
[cRIO] 0.019950999999998942
[cRIO] 0.02415600000000495
[cRIO] 0.017558999999998548
[cRIO] 0.01820099999999769
[cRIO] 0.020138000000002876
[cRIO] 0.02014899999999642
[cRIO] 0.01997400000000482
[cRIO] 0.02056699999999978
[cRIO] 0.019649999999998613
[cRIO] 0.01983699999999544
[cRIO] 0.019916000000002043
[cRIO] 0.019925999999998112
[cRIO] 0.020104000000003452
[cRIO] 0.01996899999999613
[cRIO] 0.020089000000005797
[cRIO] 0.01988399999999757
[cRIO] 0.02015999999999707
[cRIO] 0.020121000000003164
[cRIO] 0.01988399999999757
[cRIO] 0.02070300000000458
[cRIO] 0.019280999999999437
[cRIO] 0.020150000000001
[cRIO] 0.0196550000000002
[cRIO] 0.020775000000000432
[cRIO] 0.019251999999994496
[cRIO] 0.02002600000000143
[cRIO] 0.019967000000001178
[cRIO] 0.020124000000002695
[cRIO] 0.019885999999999626
[cRIO] 0.02072099999999466
[cRIO] 0.01945100000000366
[cRIO] 0.01994499999999988
[cRIO] 0.02018600000000248
[cRIO] 0.019722999999999047
[cRIO] 0.02007499999999851
[cRIO] 0.02379799999999932
[cRIO] 0.016322999999999865
[cRIO] 0.019782999999996775
[cRIO] 0.02015100000000558
[cRIO] 0.020270999999993933
[cRIO] 0.019754000000006045
[cRIO] 0.019815999999998724
[cRIO] 0.020310999999999524
[cRIO] 0.01969700000000074
[cRIO] 0.020060000000000855
[cRIO] 0.01984799999999609
[cRIO] 0.02037299999999931
[cRIO] 0.019815999999998724
[cRIO] 0.01990700000000345
[cRIO] 0.020332000000003347
[cRIO] 0.01992499999999353
[cRIO] 0.02002400000000648
[cRIO] 0.020189999999999486
[cRIO] 0.019765999999997064
[cRIO] 0.0204039999999992
[cRIO] 0.019517999999997926
[cRIO] 0.019838000000000022
[cRIO] 0.020096000000002334
[cRIO] 0.01993500000000381
[cRIO] 0.01998299999999631
[cRIO] 0.020029000000000963
[cRIO] 0.019978000000001828
[cRIO] 0.020064999999995337
[cRIO] 0.019913999999999987
[cRIO] 0.020009999999999195
[cRIO] 0.0201720000000023
[cRIO] 0.019997000000003595
[cRIO] 0.022979999999996892
[cRIO] 0.016818000000000666
[cRIO] 0.020387999999996964
[cRIO] 0.01974100000000334
[cRIO] 0.02002199999999732
[cRIO] 0.020033000000005075
[cRIO] 0.01996399999999454
[cRIO] 0.020049000000000206
[cRIO] 0.019928000000000168
[cRIO] 0.02005900000000338
[cRIO] 0.0199439999999953
[cRIO] 0.019925000000000637
[cRIO] 0.02031700000000569
[cRIO] 0.0196899999999971
[cRIO] 0.020135000000003345
[cRIO] 0.020114999999996996
[cRIO] 0.019871999999999446
[cRIO] 0.020012999999998726
[cRIO] 0.019944000000002404
[cRIO] 0.02004699999999815
[cRIO] 0.020015999999998257
[cRIO] 0.019809000000002186
[cRIO] 0.020138000000002876
[cRIO] 0.021020999999997514
[cRIO] 0.019089000000001022
[cRIO] 0.020018000000000313
[cRIO] 0.020696000000000936
[cRIO] 0.019242999999995902
[cRIO] 0.01981500000000125
[cRIO] 0.020102000000001397
[cRIO] 0.01995600000000053
[cRIO] 0.020029000000000963
[cRIO] 0.020207999999996673
[cRIO] 0.019660000000001787
[cRIO] 0.020089999999996166
[cRIO] 0.020042000000003668
[cRIO] 0.019973999999997716
[cRIO] 0.020473000000002628
[cRIO] 0.019314000000001386
[cRIO] 0.020022999999994795
[cRIO] 0.022302000000003375
[cRIO] 0.017952000000001078
[cRIO] 0.0197819999999993
[cRIO] 0.020102000000001397
[cRIO] 0.019888999999999157
[cRIO] 0.020230999999995447
[cRIO] 0.019927000000002693
[cRIO] 0.019983000000003415
[cRIO] 0.020053999999994687
[cRIO] 0.019967000000001178
[cRIO] 0.020789000000000613
[cRIO] 0.019309999999997274
[cRIO] 0.020400000000002194
[cRIO] 0.01931199999999933
[cRIO] 0.020124000000002695
[cRIO] 0.020106999999995878
[cRIO] 0.01998100000000136
[cRIO] 0.019860999999998796
[cRIO] 0.020028000000003487
[cRIO] 0.020136999999998295
[cRIO] 0.020029999999998438
[cRIO] 0.01998200000000594
[cRIO] 0.01994999999999436
[cRIO] 0.02002600000000143
[cRIO] 0.020383000000002482
[cRIO] 0.022705000000001974
[cRIO] 0.017861999999993827
[cRIO] 0.0212670000000017
[cRIO] 0.017876000000001113
[cRIO] 0.0199089999999984
[cRIO] 0.018914999999999793
[cRIO] 0.020319000000000642
[cRIO] 0.02000900000000172
[cRIO] 0.019713000000002978
[cRIO] 0.020324999999999704
[cRIO] 0.019955999999993423
[cRIO] 0.021434000000006392
[cRIO] 0.018278999999999712
[cRIO] 0.019920999999996525
[cRIO] 0.020091000000000747
[cRIO] 0.020014000000003307
[cRIO] 0.02043099999999498
[cRIO] 0.020060000000000855
[cRIO] 0.020884000000002345
[cRIO] 0.01870699999999914
[cRIO] 0.020175999999999306
[cRIO] 0.021906000000001313
[cRIO] 0.018057999999996355
[cRIO] 0.01976499999999959
[cRIO] 0.02005900000000338
[cRIO] 0.02006399999999786
[cRIO] 0.019984999999998365
[cRIO] 0.020016000000005363
[cRIO] 0.019852000000000203
[cRIO] 0.01999699999999649
[cRIO] 0.020014000000003307
[cRIO] 0.02085999999999899
[cRIO] 0.019115999999996802
[cRIO] 0.01998100000000136
[cRIO] 0.02034799999999848
[cRIO] 0.019743000000005395
[cRIO] 0.019969999999993604
[cRIO] 0.020834000000000685
[cRIO] 0.019154000000000337
[cRIO] 0.020351000000005115
[cRIO] 0.019782999999996775
[cRIO] 0.019863999999998327
[cRIO] 0.01995900000000006
[cRIO] 0.020419000000003962
[cRIO] 0.01973499999999717
[cRIO] 0.020254999999998802
[cRIO] 0.020149000000003525
[cRIO] 0.01984799999999609
[cRIO] 0.019854999999999734
[cRIO] 0.019978000000001828
[cRIO] 0.020330999999998767
[cRIO] 0.019764000000002113
[cRIO] 0.019944000000002404
[cRIO] 0.020730999999997834
[cRIO] 0.019033999999997775
[cRIO] 0.020793000000004724
[cRIO] 0.019093999999995503
[cRIO] 0.020068000000001973
[cRIO] 0.01989300000000327
[cRIO] 0.020155999999992957
[cRIO] 0.01997400000000482
[cRIO] 0.020041999999996563
[cRIO] 0.020545000000005587
[cRIO] 0.02011299999999494
[cRIO] 0.019421000000001243
[cRIO] 0.019908000000000925
[cRIO] 0.02002199999999732
[cRIO] 0.01991999999999905
[cRIO] 0.020029000000000963
[cRIO] 0.019992999999999483
[cRIO] 0.020448000000001798
[cRIO] 0.01956700000000211
[cRIO] 0.020226000000000965
[cRIO] 0.020052999999997212
[cRIO] 0.019679000000003555
[cRIO] 0.020129999999994652
[cRIO] 0.020181000000000893
[cRIO] 0.01988099999999804
[cRIO] 0.019881000000005145
[cRIO] 0.020089999999996166
[cRIO] 0.020166000000003237
[cRIO] 0.019773999999998182
[cRIO] 0.020504999999999995
[cRIO] 0.019983000000003415
[cRIO] 0.02005699999999422
[cRIO] 0.019624000000000308
[cRIO] 0.020502000000000464
[cRIO] 0.020051999999999737
[cRIO] 0.019203000000004522
[cRIO] 0.02033000000000129
[cRIO] 0.01980599999999555
[cRIO] 0.022809999999999775
[cRIO] 0.017161000000001536
[cRIO] 0.019911000000000456
[cRIO] 0.020144999999999413
[cRIO] 0.02002199999999732
[cRIO] 0.01988200000000262
[cRIO] 0.020184000000000424
[cRIO] 0.019803000000003124
[cRIO] 0.020103999999996347
[cRIO] 0.019919000000001574
[cRIO] 0.020341999999999416
[cRIO] 0.019807999999997605
[cRIO] 0.01982100000000031
[cRIO] 0.02013900000000035
[cRIO] 0.02006200000000291
[cRIO] 0.020164999999998656
[cRIO] 0.019975000000002296
[cRIO] 0.019897000000000276
[cRIO] 0.020015999999998257
[cRIO] 0.020395000000000607
[cRIO] 0.019925999999998112
[cRIO] 0.019846999999998616
[cRIO] 0.019803000000003124
[cRIO] 0.019911000000000456
[cRIO] 0.020461999999994873
[cRIO] 0.019856000000004315
[cRIO] 0.01998899999999537
[cRIO] 0.019852000000000203
[cRIO] 0.019776000000000238
[cRIO] 0.020119000000001108
[cRIO] 0.02020300000000219
[cRIO] 0.019680999999998505

How does your test differ?

Ether 31-01-2014 22:26

Re: Thread scheduler for PID period control ?
 
2 Attachment(s)
Quote:

Originally Posted by Joe Ross (Post 1335566)
I just ran the following code:

Code:

    double prevTime = 0;
    public void teleopPeriodic() {
        double time = Timer.getFPGATimestamp();
        System.out.println(time-prevTime);
        prevTime=time;
    }

And got the following output...

I took the liberty of plotting it. Attached.



gpetilli 01-02-2014 08:33

Re: Thread scheduler for PID period control ?
 
That is what I expected, which is why I was confused. I should get the 4 slot cRIO today and will retry. I know the older 8 slot was slower, but it seems strange that they would change the driver station behavior to update less often.

Joe Ross 01-02-2014 10:35

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by gpetilli (Post 1335712)
That is what I expected, which is why I was confused. I should get the 4 slot cRIO today and will retry. I know the older 8 slot was slower, but it seems strange that they would change the driver station behavior to update less often.

My test was run on an 8-slot. The 8-slot has less ram, but the same processor. In this test, it is not slower.

gpetilli 01-02-2014 20:00

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Joe Ross (Post 1335741)
My test was run on an 8-slot. The 8-slot has less ram, but the same processor. In this test, it is not slower.

Thanks for the feedback, i will have them re-run the test. BTW: what period do you use for your PID loops?

gpetilli 01-02-2014 20:05

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Joe Ross (Post 1335566)
I just ran the following code:

Code:

    double prevTime = 0;
    public void teleopPeriodic() {
        double time = Timer.getFPGATimestamp();
        System.out.println(time-prevTime);
        prevTime=time;
    }


How does your test differ?

The major difference is we are reading an I2C 9DOF IMU model GY85. Works great, but maybe the I2C is slowing things down. I did a quick estimate and thought the time would be about 1 to 2ms, but maybe there is more overhead than I guessed.

I guess we just need to try the measurements again.

Greg McKaskle 02-02-2014 10:42

Re: Thread scheduler for PID period control ?
 
Just to reiterate. The 8-slot has less RAM and is a model variation of the same FreeScale processor, meaning it has a less cache. For most situations, it is the same speed.

Greg McKaskle

wireties 02-02-2014 16:48

Re: Thread scheduler for PID period control ?
 
When you create a task and put it in a loop with a delay, the delay is subject to the resolution of the system clock (which is 10ms). So a request to delay for 20ms would have considerable variation. The system is waiting for two clock ticks which could happen in a little over 10ms or a little under 30ms.

The PID class does not use delays, instead it uses the timer OS libraries (last I looked). These fire in the context of the tick timer interrupt routine and are more periodic. The first PID timer callback may run at a variable time after enabling but it will run very periodically afterwards. Does that make sense?

The operating system does have a higher resolution timer (the auxiliary timer) for custom purposes. It is not used by the base OS. And perhaps NI built a service on top of the the auxiliary timer. Plus there is normally a third timer only used for timestamps. But the base timers work as described above.

The periodicity of the messages from the DS is dependent on many things. Ethernet is not strictly deterministic. The teleop loops start after a semaphore is given once the code on the cRIO processes an incoming message and the data is available.

HTH

Joe Johnson 02-02-2014 16:54

Re: Thread scheduler for PID period control ?
 
I am not sure why but the autogenerated code from RobotBuilder does not include the feed forward gain, Kf, and the loop period, so they default to 0 and 50ms.

Here is a code snippet:
public Launch() {
super("Launch", Kp, Ki, Kd, Kf, 0.01);

Note that we had 0.005 as the period at first and it was acting squirrely. I think we were having the PID loop take too much of the CPU time. When we backed off to 10ms, life was good.

YMMV.

Joe J.

tinybob20 08-02-2014 10:34

Re: Thread scheduler for PID period control ?
 
Hi,

we tried using the getFPGATimestamp() instead of the basic .get(), and we were able to get values around 11 - 16 ms for our timed PID loop with the scheduler set to 10ms.

in teleopPeriodic we got values around 21 - 23 ms.

gpetilli 10-02-2014 08:29

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Joe Ross (Post 1335566)
I just ran the following code:

Code:

    double prevTime = 0;
    public void teleopPeriodic() {
        double time = Timer.getFPGATimestamp();
        System.out.println(time-prevTime);
        prevTime=time;
    }


How does your test differ?

Joe,

Post #16 above is from the student we had redo the test. The differences between our original test and this one are switching from an OS timer to the FPGA timer like your code and the new test has the full PID drive code. The ~50ms DS measurement that originally had me questioning what was going on is now ~20ms as expected.
The timed loop measurement is also faster (11->16ms instead of >20ms) , but not the 10ms that we asked for. At this point we intend to set the timed PID loop to 15ms instead of 10ms to hopefully stay within the computation limit of the cRIO. Thanks for your help and example code for more accurate measurements.

Greg McKaskle 14-02-2014 09:31

Re: Thread scheduler for PID period control ?
 
The timer doesn't control the rate of the loop. It merely measures the time from one execution to the next. If you have code within teleop that takes more than 20ms to run, you will skip DS updates. I see this quite often on team DS logs, even teams from Einstein. It would be odd that the periodic is not a multiple of 20ms. And unless the network and/or DS are stressed out, I'd expect jitter numbers like Joe showed above.

I'm not sure how Java PID does its scheduling, and when teams spawn another thread and set its rate, I'm not sure what they are using to schedule.

Team 358's article is about timing using LabVIEW. LabVIEW has two different schedulers. One has ms level resolution and is used for general VI execution. It uses a pool of threads at various priorities, and the LV wait and wait ms functions and a plain while loop will operate in this scheduler. The TimedLoop uses its own scheduler that runs at an elevated priority and has advanced scheduling options -- quite advanced. It can schedule at sub millisecond periods and implements a variety of policies. Only Timed structure code runs in this scheduler.

The timed loop is also instrumented so that it is easy to determine start and stop times, missed deadlines, adjust priorities and other things. I'd highly recommend that you instrument your PID not only to measure its actual period, but also its execution time. You could also do this with a profiler if you have one. This will let you know the cost of the operation you are scheduling.

Greg McKaskle

gpetilli 14-02-2014 11:02

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Greg McKaskle (Post 1342941)
The timer doesn't control the rate of the loop. It merely measures the time from one execution to the next. If you have code within teleop that takes more than 20ms to run, you will skip DS updates. I see this quite often on team DS logs, even teams from Einstein. It would be odd that the periodic is not a multiple of 20ms. And unless the network and/or DS are stressed out, I'd expect jitter numbers like Joe showed above.

I'm not sure how Java PID does its scheduling, and when teams spawn another thread and set its rate, I'm not sure what they are using to schedule.

Team 358's article is about timing using LabVIEW. LabVIEW has two different schedulers. One has ms level resolution and is used for general VI execution. It uses a pool of threads at various priorities, and the LV wait and wait ms functions and a plain while loop will operate in this scheduler. The TimedLoop uses its own scheduler that runs at an elevated priority and has advanced scheduling options -- quite advanced. It can schedule at sub millisecond periods and implements a variety of policies. Only Timed structure code runs in this scheduler.

The timed loop is also instrumented so that it is easy to determine start and stop times, missed deadlines, adjust priorities and other things. I'd highly recommend that you instrument your PID not only to measure its actual period, but also its execution time. You could also do this with a profiler if you have one. This will let you know the cost of the operation you are scheduling.

Greg McKaskle

Yes, we understand that the timer is a free-running stop watch that we are using to instrument our loops. This is why in the OP we were concerned that the teleopPeriodic was reporting 50ms on a program that did nothing but report the time while running tethered. Switching to the FPGA timer now correctly reports a 20ms teleopPeriodic rate.

What we are trying to do is create another thread outside of teleopPeriodic for doing the PID calculations at a faster, more consistent rate. We believe we have accomplished this in JAVA. We were hoping to achieve a 10ms period but appear to be processor limited to 15ms. This seems like a long time given other teams are talking about 5ms loops (not sure if they measured actual loop times). We do have some calculations in our loop, but I would not have expected it to limit the period by so much. We are looking into the bottleneck but time on the robot is limited with bag & tag in a few days. Worst case, the performance with 15ms seems fine for competition.

Ether 14-02-2014 11:40

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by gpetilli (Post 1343002)
What we are trying to do is create another thread outside of teleopPeriodic for doing the PID calculations at a faster, more consistent rate.

Just a heads-up in case you have not yet seen this post:

http://www.chiefdelphi.com/forums/sh....php?p=1342439


Greg McKaskle 14-02-2014 13:21

Re: Thread scheduler for PID period control ?
 
What is your CPU usage when doing the 15ms PID and the rest of your robot code? It is on the charts tab.

If you make it easy to change the period of the PID, you can decrease it and watch the CPU. This will also help understand whether the PID loop is waiting on I/O or CPU bound. Again, it may be useful to know the time spent within the PID routine, so if you add your getFPGA timing to the top and bottom of the function and display that delta as well.

Greg McKaskle

gpetilli 14-02-2014 13:35

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by Greg McKaskle (Post 1343089)
What is your CPU usage when doing the 15ms PID and the rest of your robot code? It is on the charts tab.

If you make it easy to change the period of the PID, you can decrease it and watch the CPU. This will also help understand whether the PID loop is waiting on I/O or CPU bound. Again, it may be useful to know the time spent within the PID routine, so if you add your getFPGA timing to the top and bottom of the function and display that delta as well.

Greg McKaskle

Agreed. We have a variable dt that sets the period for the timed loop as well as changes the PID values. We just need time on the robot to finish our tuning.

TravSatEE 19-03-2014 01:25

Re: Thread scheduler for PID period control ?
 
I'd like the OP or any others that have done PID loop timing changes to share what inputs/outputs they are using. What do these custom PID loops do on the robot (drive, interact with game/field items)? I am curious as to what needs a custom timing rate, as I haven't done anything myself that needed this for a PID controller. What was the behavior that led you to believe you needed a faster timing rate? If you post your code repositories publicly, please share the URL so I can try to follow along with what you did. One of the posts mention a change of "PID values" (I assume the coefficients), why did you do this? Thanks!

gpetilli 19-03-2014 09:15

Re: Thread scheduler for PID period control ?
 
Quote:

Originally Posted by TravSatEE (Post 1361156)
I'd like the OP or any others that have done PID loop timing changes to share what inputs/outputs they are using. What do these custom PID loops do on the robot (drive, interact with game/field items)? I am curious as to what needs a custom timing rate, as I haven't done anything myself that needed this for a PID controller. What was the behavior that led you to believe you needed a faster timing rate? If you post your code repositories publicly, please share the URL so I can try to follow along with what you did. One of the posts mention a change of "PID values" (I assume the coefficients), why did you do this? Thanks!

We are controlling a Killough style holonomic drive (which depends on wheel "slippage") by using two orthogonal instrumented follower wheels (no encoders on gearbox) plus a 9DOF IMU sensor ($16 GY-85). For the X&Y translation velocity PD we use the velocity from followers plus the accellerometer on the IMU. For rotation velocity PI we use the gyro and compass on the IMU.

We found that the 20ms "periodic" loop rate varied too much for repeatable control - it was difficult to tune the overshoot vs. accuracy since we are controlling velocity but observing the integrated distance. We evaluated timed loops and found them to be significantly more consistent. The standard PID loop uses timed loops but defaults to 50ms, which is way too long for good control. There was a visible difference in the overshoot going from a timed loop of 20ms to 10ms, however measurements showed we were really only achieving 14ms. Our competition bot has the loop set for 15ms, is extremely responsive and exhibits very little overshoot.


All times are GMT -5. The time now is 05:28.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi