Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True Wind Calculation #75

Open
quantenschaum opened this issue Aug 20, 2024 · 7 comments
Open

True Wind Calculation #75

quantenschaum opened this issue Aug 20, 2024 · 7 comments

Comments

@quantenschaum
Copy link
Contributor

quantenschaum commented Aug 20, 2024

First, thanks for this project! 🎩

related to wellenvogel/avnav#367 and https://github.com/kdschmidt1/Sail_Instrument

I noticed that the gateway computes true wind from COG/SOG and AWA/AWS, but I suspect the calculations not to be correct.

Testing

I fed the gateway with the following test data (as return by the GW in PCDIN) and got this output. The test data values were generated using CourseData.

Wind data is sent to the GW as PGN130306 N2kWind_Apparent.

1. No Current

  • SET/DFT = 0 and thus
    • COG/SOG = HDT/STW and
    • true wind = ground wind
print(CourseData(SET=0,DFT=0,HDT=90,STW=5,AWA=-50,AWS=15,angles360=1))
AWA=-50
AWS=15
COG=90.0
DFT=0
GWD=21.99692847308269
GWS=12.392814795155259
HDT=90
SET=90
SOG=5.0
STW=5
TWA=291.9969284730827
TWD=21.996928473082676
TWS=12.39281479515526

GW output

$PCDIN,01F802,0000EF27,14,FFFC5C3D0101FFFF*2A
$GPVTG,90.0,T,,M,5.0,N,9.3,K*56
$PCDIN,01FD02,0000EF28,14,FF040359D302FFFF*23
$GPMWV,310.0,R,7.7,M,A*2B
$GPMWV,292.0,T,6.4,M,A*24
$GPMWD,292.0,T,292.0,M,12.4,N,6.4,M*66
  • VTG COG/SOG = 90°/5kn ✔️
  • MWV-R AWA/AWS = 310°/7.7m/s ✔️
  • MWV-T TWA/TWS = 292°/6.4m/s ✔️
  • MWD TWD/TWS 292°/12.4kn ❌ same as MWV-T but should be true wind direction not angle (need to add HDT) Forwarding this to AvNav results in a wrong TWD.

2. With Current

  • SET/DFT != 0 and thus
    • COG/SOG != HDT/STW and
    • true wind != ground wind
print(CourseData(SET=30,DFT=2,HDT=90,STW=5,AWA=-50,AWS=15,angles360=1))
AWA=-50
AWS=15
COG=73.89788624801398
DFT=2
GWD=20.46505232502011
GWS=10.416016194605621
HDT=90
SET=30
SOG=6.244997998398398
STW=5
TWA=291.9969284730827
TWD=21.996928473082676
TWS=12.39281479515526

GW output

$PCDIN,01F802,0019FB96,14,FFFC62324101FFFF*2F
$GPVTG,73.9,T,,M,6.2,N,11.6,K*6F
$PCDIN,01F503,0019FB98,14,FF0101FFFF00FFFF*29
$GPVHW,90.0,T,,M,5.0,N,9.3,K*5A
$PCDIN,01F112,0019FB9E,14,FF5C3DFF7FFF7FFC*54
$GPHDT,90.0,T*0C
$PCDIN,01FD02,0019FBA9,14,FF040359D302FFFF*5E
$GPMWV,310.0,R,7.7,M,A*2B
$GPMWV,286.5,T,6.2,M,A*22
$GPMWD,286.5,T,286.5,M,12.0,N,6.2,M*64
  • VTG COG/SOG = 73.9°/6.2kn ✔️
  • VHW HDT/STW = 90°/5kn ✔️
  • HDT 90° ✔️
  • MWV-R AWA/AWS = 310°/7.7m/s ✔️
  • MWV-T TWA/TWS = 286.5°/6.2m/s ❌ should be 292° 12.4kn (6.4m/s) because true wind is relative to water and must be calculated from HDT/STW, here COG/SOG is used and yields ground wind instead
  • MWD ❌ same problem as in 1. (angle instead of direction)
  • SET/DFT are not calculated or converted (PGN 130577)

Workaround

Blacklisting MWD, but MWV-T is still wrong.

Suggestions

  • The calculation should be fixed like it is done in the Sail_Instrument.
    • Leeway estimation makes this more complicated.
  • Set and drift should be calculated and/or converted as well.
  • There should be a config option to turn off all calculations, so only conversion is performed by the gateway and the calculations are done by downstream software. (It is not possible to just blacklist calculated sentences, MWV is sent in two flavors which cannot be blocked separately.)
@wellenvogel
Copy link
Owner

I agree...
Mainly old code there.
And switching of computations is for sure a good idea.

@quantenschaum
Copy link
Contributor Author

quantenschaum commented Aug 21, 2024

OK

The conversions also seem to be wrong.

So, there is a confusion of (see wellenvogel/avnav#367)

  • true wind and ground wind and
  • direction and angle

@quantenschaum
Copy link
Contributor Author

quantenschaum commented Aug 21, 2024

N2K-0183-Conversion

For NMEA0183 sentences and PGNs see wellenvogel/avnav#367.

AFAIK there are only 2 possible direct conversions between N2K and 0183.

  • PGN130306-Apparent <-> MWV-R (AWA/AWS) (as well as VWR)
  • PGN130306-True_water <-> MWV-T (TWA/TWS) ❗ ANGLE (not direction)

There is no PGN containing TWD, it must be calculated as TWD=TWA+HDT to be able to send MWD (analogous for reception).

There are no NMEA0183 sentences for ground wind.

I suspect that many of the (expensive) devices out there do not exactly follow these specs and send/receive wrong wind data or process them incorrectly. It's a mess. And then you wonder why your $$$ instruments display funny numbers.

@quantenschaum
Copy link
Contributor Author

quantenschaum commented Aug 21, 2024

To make the converter work correctly with systems that send wrong wind data (i.e. true wind in 130306-True_North [ground wind]) it would make sense to have a config option to select how the data in PGN130306 is interpreted. Like 2 pairs of dropdown boxes N2K <-> 0183 with the following options

N2K 0183
0 true north ground dir AWA/S
1 magnetic ground dir TWA/S
2 apparent angle TWD/S
3 ground angle GWA/S
4 true angle GWD/S

Then you could select something like

  • 2 apparent angle <--> AWA/S
  • 0 true north ground dir <--> TWD/S

which tell the GW how to translate the data.

This way you can tell the GW to do the conversion right even if your devices on the bus send the data with the wrong reference flags.

@wellenvogel
Copy link
Owner

I started to implement the proposed mappings for the N2K wind reference.
As far as I see we currently can only use 3 values at the NMEA0183 side: AWA/S,TWA/S,TWD/S.
For the others we would need to implement more computations - similar to Sail_Instrument.
Finally I'm not really sure if this would make sense in the gateway...
@quantenschaum: could you imagine to write a short summary for the wind definitions and issues that we could directly add to the documentation? Maybe just a wind.md in the doc directory?
Currently the information is a bit distributed and potentially hard to follow for the normal user.

@quantenschaum
Copy link
Contributor Author

That sounds good!

could you imagine to write a short summary for the wind definitions
Currently the information is a bit distributed and potentially hard to follow

That's true. Sure, I could wrap this up. I would merge the information from

Finally I'm not really sure if this would make sense in the gateway

Performing calculations in the gateway can make sense in certain cases when the devices receiving the data need these fields but are not capable of calculating them on their own. But it should be optional. Performing the calculations downstream in the receiving devices/software might be more flexible.

@wellenvogel
Copy link
Owner

Performing calculations in the gateway can make sense in certain cases when the devices receiving the data need these fields but are not capable of calculating them on their own. But it should be optional. Performing the calculations downstream in the receiving devices/software might be more flexible.

Completely agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants