12-10-2019, 14:02
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:
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
