wellenvogel / esp32-nmea2000

nmea2000 gateway with ESP32
GNU General Public License v2.0
65 stars 30 forks source link

True Wind Calculation #75

Open quantenschaum opened 3 months ago

quantenschaum commented 3 months ago

First, thanks for this project! :tophat:

related to https://github.com/wellenvogel/avnav/issues/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

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

2. With Current

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

Workaround

Blacklisting MWD, but MWV-T is still wrong.

Suggestions

wellenvogel commented 3 months ago

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

quantenschaum commented 3 months ago

OK

The conversions also seem to be wrong.

So, there is a confusion of (see https://github.com/wellenvogel/avnav/issues/367)

quantenschaum commented 3 months ago

N2K-0183-Conversion

For NMEA0183 sentences and PGNs see https://github.com/wellenvogel/avnav/issues/367.

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

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 commented 3 months ago

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

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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.

wellenvogel commented 1 week ago

first steps with https://github.com/wellenvogel/esp32-nmea2000/releases/tag/20241114