stimav4: getSDFromUV bug for slow wind
pat1 opened this issue · 1 comments
pat1 commented
La funzione:
void ElaborateDataTask::getSDFromUV(float u, float v, float *speed, float *direction)
{
*speed = sqrt(u * u + v * v);
*direction = RAD_TO_DEG * atan2(-u, -v);
int16_t tmp_dir = round(*direction);
if(tmp_dir < 0) tmp_dir += 360;
*direction = tmp_dir % 360;
if(*speed < CALM_WIND_MAX_MED_VECT) {
*speed = 0;
*direction = 0;
} else if (*direction == 0) {
*direction = WIND_DIRECTION_MAX; // Translate 0 -> 360 (WIND_DIRECTION_MAX)
}
}
manca del test per intensità molto basse o zero
Il test è necessario per evitare errori di troncamento successivi
e fondamentalmente perchè atan2(0,0) ha risultato indefinito
Questa la versione corretta:
void getSDFromUV (float u, float v, uint16_t *speed, uint16_t *direction) {
if (abs(u) < CALM_WIND_MAX_MS*100 && abs(v) < CALM_WIND_MAX_MS*100){
*speed = 0;
*direction = 0;
} else{
*speed = round(sqrt(u*u + v*v));
*direction = round(RAD_TO_DEG * atan2(-u, -v));
*direction = *direction % 360;
}
digitecomg commented
Inserito check su limite ATAN2