Has anybody successfully used Pressure Sensor History to Determine Current (previous X seconds) Slope/Gradient

Hi I am looking to add Slope / Gradient to my data field.  It would seem that Sensor History Pressure would be the most accurate way to go.

1) Has anybody else done this?

2) Are there any code snippets online to help me out?

3) Is there a definition for how often pressure values are stored in the history.  Is this variable by device?  Is it defined anywhere?

  • It's variable by device is my guess.  On a real device, you can compare the "when" between two samples and see how often they are saved. Maybe every minute or two.

    Depending on your app type, you can get more timely data from Sensor or Activity.

  • Don't Garmin use the pressure history to determine 'floors climbed'.  I was hoping if this was the case they would need to be logging every 1-2s.  I don't have a large number of devices and the simulator isn't much help here (as the data is not very real).

    I was hoping someone might have some real world experience of calculating slope / grade.  I assume that the GPS would be even more inaccurate over short periods of time.

    I think I need 4-5 readings across a 10s timeframe to make this useable.  Maybe I need to query the sensor directly on each Compute.

  • No, for floors it looks for change, so it uses the second by second pressure. 10'/3m in a fairly short amount of time. 

    SensorHistory is used for things like widgets to show a graph. In fact you'll find the number of samples can vary based on the width of the graph in the widget, so it can show 4 hours (or whatever) of data.

  • Thanks, that is what I have done now and it seems to be working.  Checking every 5s and calculating alt and distance changes.

  • Robert,

    I have just upgraded to the edge 1040. I did have the 1030 and noticed the elevation on the 1040 is much more stable than the 1030 was. So I have been experimenting with the internal pressure sensor to calculate the gradient on the 1040. I did use elevation to calculate gradient on the 1030, but this has a large delay in the results (about 5-10 seconds) Pressure seems to work well on the 1040. Did try ambient pressure, but this also has a delay, probably because it is filtered. I'm now using raw ambient pressure and this responds quickly. It is a little bit jumpy (can go between -1% and 1% on a flat road) but generally works well. Code is:

    DistanceArray.add(Distance);
    DistanceArray.remove(DistanceArray[0]);
    PressureArray.add(Pressure);
    PressureArray.remove(PressureArray[0]);
    if (DistanceArray[0]==0) {
    } else {
    if (DistanceArray[1] > DistanceArray[0]) {
    ErrorArray.add(8.4947*(PressureArray[0]-PressureArray[1])/(DistanceArray[1]-DistanceArray[0])-Gradient);
    ErrorArray.remove(ErrorArray[0]);
    GradientArray.add(Gradient+0.2*ErrorArray[1]+0.12*ErrorArray[0]); // P=0.16, I=0.08, D=0.04, E0=I+D, E1=P+I-D
    GradientArray.remove(GradientArray[0]);
    }
    }
    if (SpeedCurrent < 4.5) {
    Gradient = Math.mean(GradientArray);
    } else {
    Gradient = GradientArray[1];
    }

    I use a basic PID controller to filter the gradient calc. All arrays are two digits.