ardupilot/libraries/AP_WindVane/AP_WindVane_SITL.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.9 KiB
C++
Raw Normal View History

2019-05-09 21:14:18 -03:00
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AP_WindVane_SITL.h"
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
2022-02-25 01:06:30 -04:00
#include <SITL/SITL.h>
#include <AP_AHRS/AP_AHRS.h>
2019-05-09 21:14:18 -03:00
void AP_WindVane_SITL::update_direction()
{
if (_frontend._direction_type == _frontend.WindVaneType::WINDVANE_SITL_TRUE) {
// read in the true wind direction and calculate the apparent
2019-05-09 21:14:18 -03:00
// 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);
2019-05-09 21:14:18 -03:00
// Note than the SITL wind direction is defined as the direction the wind is traveling to
// This is accounted for in these calculations
2019-05-09 21:14:18 -03:00
// 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;
_frontend._direction_apparent_raw = wrap_PI(atan2f(wind_vector_ef.y, wind_vector_ef.x) - AP::ahrs().yaw);
} else { // WINDVANE_SITL_APARRENT
// directly read the body frame apparent wind set by physics backend
_frontend._direction_apparent_raw = wrap_PI(AP::sitl()->get_apparent_wind_dir());
}
2019-05-09 21:14:18 -03:00
}
void AP_WindVane_SITL::update_speed()
{
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);
2019-05-09 21:14:18 -03:00
// add vehicle speed to get apparent wind vector
wind_vector_ef.x += AP::sitl()->state.speedN;
wind_vector_ef.y += AP::sitl()->state.speedE;
2019-05-09 21:14:18 -03:00
_frontend._speed_apparent_raw = wind_vector_ef.length();
2019-05-09 21:14:18 -03:00
} else { // WINDSPEED_SITL_APARRENT
// directly read the apparent wind from as set by physics backend
_frontend._speed_apparent_raw = AP::sitl()->get_apparent_wind_spd();
}
2019-05-09 21:14:18 -03:00
}
#endif