Math question RE: GPS track

Discussion in 'Chit Chat' started by Benh, Jul 3, 2009.

  1. Benh

    Benh Member Licensed User

    I want to calculate rate of change of track acorss ground (in degrees). You could call it rate of turn.

    OK, it's simple....all you do is subtract the incoming reading from the privious one. Well not quite.......all is dandy until you sweep over the 360 degrees line. If you were turning clockwise you could get 359 - 1 = 358, where what you really want is '2'.

    Any ideas how you do this would be appriciated.

    Many thanks, Ben
     
  2. derez

    derez Expert Licensed User

    The problem happens only for one reading, until you reach the next time around.
    You can ignore this specific reading by a simple test:

    if abs(new_track - old_track) < x then
    .....
    end if

    where X must be larger than the maximum expected turn per second.

    for continuity of display use for this specific "non reading" the previous value.

    Edit:
    If you do want that reading, since you know by using the test above that you have the difference of 360 degrees to the result, add or subtract according to the sign of the difference, the value 360.
     
    Last edited: Jul 3, 2009
  3. Benh

    Benh Member Licensed User

    Thanks derez

    Sounds like a good idea. I'll give it a try.

    Ben
     
  4. klaus

    klaus Expert Licensed User

    If you take the difference of the incoming reading - previous reading you get a value.
    Clockwise turning is positive and counterclockwise turning is negative.
    In your example:
    incoming reading 1°
    previous reading 359°
    so 1 - 359 = -358°
    This means a counterclockwise turning of 358°
    But this also means a clockwise turning of 2°
    The following code will give you the turn in +/- 180°

    Code:
    [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]DeltaDir = Direction(i) - Direction(i-[/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [/SIZE][/
    FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Abs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](DeltaDir) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]180 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] DeltaDir < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]  DeltaDir = DeltaDir + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]360[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Else[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]  DeltaDir = DeltaDir - [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]360[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] End [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
    Best regards.
     
  5. Benh

    Benh Member Licensed User

    Thanks Klaus

    That's exactly what I ended up with!

    Cheers, Ben
     
  6. nl1007

    nl1007 Member Licensed User

    you don't need the Abs() line, and extra 'If' level; just use:

    If DeltaDir < 180 Then
    DeltaDir = DeltaDir + 360
    ElseIf DeltaDir > 180 Then
    DeltaDir = DeltaDir - 360
    End If
     
  7. klaus

    klaus Expert Licensed User

    Are you really shure ?

    In the case when
    incoming reading 150°
    previous reading 120°
    DeltaDir=150-120=30

    in your example DeltaDir<180 Then
    DeltaDir = DeltaDir + 360 = 390
    Do you want that ?

    That's not what I want, I want results between -180 to + 180

    In my code the result remains 30 because Abs(DeltaDir) is less than 180

    Best regards.
     
    Last edited: Jul 6, 2009
  8. nl1007

    nl1007 Member Licensed User

    sorry, should have been < -180
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice