This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wind direction averaging
#1
I  adapted the Tx board software a bit so the wind direction is averaged each 15 seconds. 
Too often the wind direction is all over the place in some wind conditions...

At the receiver end I added a 5 minute averaging of the wind direction (and speed also) so when I look at the display I know for sure where the wind is coming from.

This is the Tx board software mod:
Code:
// --- For all other supported Wind Direction Sensors -----------------------
#if (WINDDIR_SENSORTYPE == 20)
double get_WindVane()
{
  windDirAverageCounter += 1;
  //Serial << windDirAverageCounter << '\t';


  analogRead(VANE_PIN); // Do 1 reading to stabilize ADC
  delay(5);

  unsigned int vane_reading = analogRead(VANE_PIN);
  //Serial.println(vane_reading);

  // calc the current wind direction
  windDirection = ((vane_reading - Min_vane_reading) * 360L) / (Max_vane_reading - Min_vane_reading);

  windDirection += WDir_offs;
  // Precaution in case the calibration values are wrong or slightly off
  if (windDirection < 0 || windDirection >= 360)
  {
    windDirection = 0;
  }

  //Serial << "Dir: " << (windDirection) << endl;

  //----------------------------------------------------------------------------
  // calculate wind direction average
  //----------------------------------------------------------------------------
  windDirSinusSum += sin(radians(windDirection));
  windDirCoSinusSum += cos(radians(windDirection));

  if (windDirAverageCounter == 5)
  {
    // calculate the average wind direction.
    // convert result from Radians to Degrees
    atan2Dir = degrees(atan2((windDirSinusSum / windDirAverageCounter),
                             (windDirCoSinusSum / windDirAverageCounter)));

    // if the atan2 calculation result is negative, we need to add 360 to the result!
    if (atan2Dir < 0)
    {
      // multiplication by 10 is needed for round2int function
      windDirAverage = round2int((atan2Dir + 360) * 10);

      // sometimes we get 360 as result so we need to convert that to zero
      if (windDirAverage == 360)
      {
        windDirAverage = 0;
      }
    }
    else
    {
      // multiplication by 10 is needed for round2int function
      windDirAverage = round2int(atan2Dir * 10);
    }

    //Serial << "av: " << windDirAverage << endl << endl;

    // reset counter
    windDirAverageCounter = 0;
    windDirSinusSum = 0;
    windDirCoSinusSum = 0;

    windDirAverage = windDirAverage * 10;
  }
  // return windDirection;
  return windDirAverage;
}
#endif

#endif // End ID2
Reply
#2
(12-10-2019, 14:02)edr1924 Wrote: At the receiver end I added a 5 minute averaging of the wind direction (and speed also) so when I look at the display I know for sure where the wind is coming from.

Changing the RX code to averaging the wind speed doesn't seem to me to be a good idea, because this is already done on the TX before sending data. The TX units sends wind speed as ten and two minutes wind average which are the standard.
On the RX display, wind speed is the standard 10 minutes wind average.
Be careful when changing things on the code, specially if you intend to use it with any weather software such as Cumulus, you may be breaking standard measurements.

Regarding the wind direction, well, if adding the calculation of wind direction vector works better for you, its ok. Now you have something similar to predominant wind direction.
Anyway check the impact of using the sin and cos functions in memory usage.

Wind direction by nature changes very frequently, I use an high quality ultrasonic wind direction / speed sensor (Ventus 200A), which values are read digitally and I also get very frequent changes in wind direction, obviously not radical changes from N to S, but N to NNO or N to NNW are normal.
Reply




Users browsing this thread: 1 Guest(s)