SignalK/signalk-derived-data

drift and set formulas are incorrect

Opened this issue · 4 comments

Math.cos (courseOverGroundTrue-headingMagnetic)

Should be difference of either true or magnetic (can't mix both)

IMHO one should never use magnetic directions in any of the calculations. The only place the where magnetic stuff is involved is when converting a compass reading to true: true heading = compass heading + deviation + variation. If the compass is self-calibrating for deviation then deviation=0. That's it. From there one always use true directions. Saves a lot of headache. If you want to go back to magnetic for output purposes, you can always convert back after the actual calculation.

set/drift must not depend on magnetic variation!

How to calculate set and drift correctly?

SOG and COG follow this equation

(COG,SOG) = (set,drift) + (HDT+leeway,STW)

with (phi,r) being a vector in polar form and + denotes the sum of polar vectors. I would not actually calculate this sum that way. I would rather transform the vectors to cartesian space, add them, transform to polar space.

❗ The angle in the nautical system starts north and goes clockwise!

So you get

(set,drift) = (COG,SOG) - (HDT+leeway,STW)

with

  • COG/SOG - course and speed over ground from GPS
  • HDT - true heading from compass + variation
  • leeway - leeway angle, we can only estimate that based on wind speed and angle or set it to zero (set/drift will then yield a virtual current that causes leeway) see #5
  • STW - water speed from paddle wheel log

Python version of addition of polar vectors

def add_polar(a, b):
    "sum of polar vectors (phi,r)"
    # to cartesian with phi going clock-wise from north
    a = a[1] * sin(radians(a[0])), a[1] * cos(radians(a[0]))
    b = b[1] * sin(radians(b[0])), b[1] * cos(radians(b[0]))
    # sum of cartesian vectors
    s = a[0] + b[0], a[1] + b[1]
    # back to polar with phi going clock-wise from north
    r = sqrt(s[0] ** 2 + s[1] ** 2)
    phi = (90 - degrees(atan2(s[1], s[0])) + 360) % 360
    return phi, r

The output vales do not have any units associated with them in SignalK.

for the calculations these formulas should be used

https://github.com/quantenschaum/mapping/blob/master/coursedata.py