From 0d2b33cba58400a14de5d2a2096471c480ab4f81 Mon Sep 17 00:00:00 2001 From: Blaubart Date: Sun, 24 Mar 2024 11:53:26 +0100 Subject: [PATCH] Moved query for external wind to OnSensorUpdate and used Haeding from Larus The previously used track is not available on the ground, giving the impression that the wind arrows are not responding. Furthermore, Larus' heading is certainly much more accurate. I moved the if statement to OnSensorUpdate because high wind accuracy is desired. This is not guaranteed with OnCalculatedUpdate. including relative wind vector Including relative wind vector from external device like Larus, Anemoi, etc. If external wind is not available calculated wind from XCSoar/OpenSoar is displayed. conversion of basic.track.Degrees() to integer removed - conversion of basic.track.Degrees() to integer removed - checked for the calculated wind, whether the external wind is definitely invalid --- src/Device/Driver/FreeVario.cpp | 43 ++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Device/Driver/FreeVario.cpp b/src/Device/Driver/FreeVario.cpp index 7fcaa701ef1..59fca62bfa8 100755 --- a/src/Device/Driver/FreeVario.cpp +++ b/src/Device/Driver/FreeVario.cpp @@ -246,9 +246,9 @@ FreeVarioDevice::ParseNMEA(const char *_line, NMEAInfo &info) } /* - * Send total_energy_vario to FreeVario device on every sensor update. - * Is needed to have a good refresh rate on the external device showing the - * vario values + * Send total_energy_vario, external wind direction and external wind speed to + * FreeVario device on every sensor update. Is needed to have a good refresh + * rate on the external device showing the vario and external wind values. */ void FreeVarioDevice::OnSensorUpdate(const MoreData &basic) @@ -256,10 +256,28 @@ FreeVarioDevice::OnSensorUpdate(const MoreData &basic) NullOperationEnvironment env; char nmeaOutbuffer[80]; - if (basic.total_energy_vario_available.IsValid()) { - sprintf(nmeaOutbuffer,"PFV,VAR,%f", basic.total_energy_vario); - PortWriteNMEA(port, nmeaOutbuffer, env); - } + if (basic.total_energy_vario_available.IsValid()) { + sprintf(nmeaOutbuffer,"PFV,VAR,%f", basic.total_energy_vario); + PortWriteNMEA(port, nmeaOutbuffer, env); + } + + if (basic.external_wind_available.IsValid() && basic.attitude.heading_available){ + double relWindDirection = basic.external_wind.bearing.Degrees() - basic.attitude.heading.Degrees() + 180; + double norm = basic.external_wind.norm; + sprintf(nmeaOutbuffer,"PFV,AWD,%f", relWindDirection); + PortWriteNMEA(port, nmeaOutbuffer, env); + sprintf(nmeaOutbuffer,"PFV,AWS,%f", norm); + PortWriteNMEA(port, nmeaOutbuffer, env); + } + + if (basic.external_instantaneous_wind_available.IsValid() && basic.attitude.heading_available){ + double relWindDirection = basic.external_instantaneous_wind.bearing.Degrees() - basic.attitude.heading.Degrees() + 180; + double norm = basic.external_instantaneous_wind.norm; + sprintf(nmeaOutbuffer,"PFV,CWD,%f", relWindDirection); + PortWriteNMEA(port, nmeaOutbuffer, env); + sprintf(nmeaOutbuffer,"PFV,CWS,%f", norm); + PortWriteNMEA(port, nmeaOutbuffer, env); + } // TODO(August2111): basic.netto_variable has no timestamp unfortunately? // if (basic.netto_vario_available.IsValid()) { @@ -268,7 +286,6 @@ FreeVarioDevice::OnSensorUpdate(const MoreData &basic) // } } - /* * Always send the calculated updated values to the FreeVario to have a good * refresh rate on the external device @@ -280,7 +297,15 @@ FreeVarioDevice::OnCalculatedUpdate(const MoreData &basic, NullOperationEnvironment env; char nmeaOutbuffer[80]; - + if (!basic.external_instantaneous_wind_available.IsValid() && calculated.wind.IsNonZero() && basic.track_available){ + double relWindDirection = calculated.wind.bearing.Degrees() - basic.track.Degrees() + 180; + double norm = calculated.wind.norm; + sprintf(nmeaOutbuffer,"PFV,AWD,%f", relWindDirection); + PortWriteNMEA(port, nmeaOutbuffer, env); + sprintf(nmeaOutbuffer,"PFV,AWS,%f", norm); + PortWriteNMEA(port, nmeaOutbuffer, env); + } + if (basic.baro_altitude_available.IsValid()){ sprintf(nmeaOutbuffer,"PFV,HIG,%f", basic.baro_altitude); PortWriteNMEA(port, nmeaOutbuffer, env);