|
|
|
@ -25,36 +25,53 @@ AP_WindVane_SITL::AP_WindVane_SITL(AP_WindVane &frontend) :
@@ -25,36 +25,53 @@ AP_WindVane_SITL::AP_WindVane_SITL(AP_WindVane &frontend) :
|
|
|
|
|
|
|
|
|
|
void AP_WindVane_SITL::update_direction() |
|
|
|
|
{ |
|
|
|
|
// temporarily store true speed and direction for easy access
|
|
|
|
|
const float wind_speed = AP::sitl()->wind_speed_active; |
|
|
|
|
const float wind_dir_rad = radians(AP::sitl()->wind_direction_active); |
|
|
|
|
if (_frontend._direction_type == _frontend.WindVaneType::WINDVANE_SITL_TRUE) { |
|
|
|
|
// read in the true wind direction and calculate the apparent
|
|
|
|
|
|
|
|
|
|
// Note than the SITL wind direction is defined as the direction the wind is traveling to
|
|
|
|
|
// This is accounted for in these calculations
|
|
|
|
|
// temporarily store true speed and direction for easy access
|
|
|
|
|
const float wind_speed = AP::sitl()->wind_speed_active; |
|
|
|
|
const float wind_dir_rad = radians(AP::sitl()->wind_direction_active); |
|
|
|
|
|
|
|
|
|
// convert true wind speed and direction into a 2D vector
|
|
|
|
|
Vector2f wind_vector_ef(cosf(wind_dir_rad) * wind_speed, sinf(wind_dir_rad) * wind_speed); |
|
|
|
|
// Note than the SITL wind direction is defined as the direction the wind is traveling to
|
|
|
|
|
// This is accounted for in these calculations
|
|
|
|
|
|
|
|
|
|
// add vehicle speed to get apparent wind vector
|
|
|
|
|
wind_vector_ef.x += AP::sitl()->state.speedN; |
|
|
|
|
wind_vector_ef.y += AP::sitl()->state.speedE; |
|
|
|
|
// convert true wind speed and direction into a 2D vector
|
|
|
|
|
Vector2f wind_vector_ef(cosf(wind_dir_rad) * wind_speed, sinf(wind_dir_rad) * wind_speed); |
|
|
|
|
|
|
|
|
|
// add vehicle speed to get apparent wind vector
|
|
|
|
|
wind_vector_ef.x += AP::sitl()->state.speedN; |
|
|
|
|
wind_vector_ef.y += AP::sitl()->state.speedE; |
|
|
|
|
|
|
|
|
|
direction_update_frontend(atan2f(wind_vector_ef.y, wind_vector_ef.x)); |
|
|
|
|
|
|
|
|
|
} else { // WINDVANE_SITL_APARRENT
|
|
|
|
|
// directly read the apparent wind from as set by physics backend
|
|
|
|
|
direction_update_frontend(AP::sitl()->get_apparent_wind_dir()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
direction_update_frontend(atan2f(wind_vector_ef.y, wind_vector_ef.x)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AP_WindVane_SITL::update_speed() |
|
|
|
|
{ |
|
|
|
|
// temporarily store true speed and direction for easy access
|
|
|
|
|
const float wind_speed = AP::sitl()->wind_speed_active; |
|
|
|
|
const float wind_dir_rad = radians(AP::sitl()->wind_direction_active); |
|
|
|
|
if (_frontend._speed_sensor_type == _frontend.Speed_type::WINDSPEED_SITL_TRUE) { |
|
|
|
|
// read in the true wind direction and calculate the apparent
|
|
|
|
|
|
|
|
|
|
// temporarily store true speed and direction for easy access
|
|
|
|
|
const float wind_speed = AP::sitl()->wind_speed_active; |
|
|
|
|
const float wind_dir_rad = radians(AP::sitl()->wind_direction_active); |
|
|
|
|
|
|
|
|
|
// convert true wind speed and direction into a 2D vector
|
|
|
|
|
Vector2f wind_vector_ef(cosf(wind_dir_rad) * wind_speed, sinf(wind_dir_rad) * wind_speed); |
|
|
|
|
|
|
|
|
|
// convert true wind speed and direction into a 2D vector
|
|
|
|
|
Vector2f wind_vector_ef(cosf(wind_dir_rad) * wind_speed, sinf(wind_dir_rad) * wind_speed); |
|
|
|
|
// add vehicle speed to get apparent wind vector
|
|
|
|
|
wind_vector_ef.x += AP::sitl()->state.speedN; |
|
|
|
|
wind_vector_ef.y += AP::sitl()->state.speedE; |
|
|
|
|
|
|
|
|
|
// add vehicle speed to get apparent wind vector
|
|
|
|
|
wind_vector_ef.x += AP::sitl()->state.speedN; |
|
|
|
|
wind_vector_ef.y += AP::sitl()->state.speedE; |
|
|
|
|
speed_update_frontend(wind_vector_ef.length()); |
|
|
|
|
|
|
|
|
|
speed_update_frontend(wind_vector_ef.length()); |
|
|
|
|
} else { // WINDSPEED_SITL_APARRENT
|
|
|
|
|
// directly read the apparent wind from as set by physics backend
|
|
|
|
|
speed_update_frontend(AP::sitl()->get_apparent_wind_spd()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|