AP_WindVane_SITL.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "AP_WindVane_SITL.h"
  14. // constructor
  15. AP_WindVane_SITL::AP_WindVane_SITL(AP_WindVane &frontend) :
  16. AP_WindVane_Backend(frontend)
  17. {
  18. }
  19. #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
  20. void AP_WindVane_SITL::update_direction()
  21. {
  22. // temporarily store true speed and direction for easy access
  23. const float wind_speed = AP::sitl()->wind_speed_active;
  24. const float wind_dir_rad = radians(AP::sitl()->wind_direction_active);
  25. // Note than the SITL wind direction is defined as the direction the wind is traveling to
  26. // This is accounted for in these calculations
  27. // convert true wind speed and direction into a 2D vector
  28. Vector2f wind_vector_ef(cosf(wind_dir_rad) * wind_speed, sinf(wind_dir_rad) * wind_speed);
  29. // add vehicle speed to get apparent wind vector
  30. wind_vector_ef.x += AP::sitl()->state.speedN;
  31. wind_vector_ef.y += AP::sitl()->state.speedE;
  32. direction_update_frontend(atan2f(wind_vector_ef.y, wind_vector_ef.x));
  33. }
  34. void AP_WindVane_SITL::update_speed()
  35. {
  36. // temporarily store true speed and direction for easy access
  37. const float wind_speed = AP::sitl()->wind_speed_active;
  38. const float wind_dir_rad = radians(AP::sitl()->wind_direction_active);
  39. // convert true wind speed and direction into a 2D vector
  40. Vector2f wind_vector_ef(cosf(wind_dir_rad) * wind_speed, sinf(wind_dir_rad) * wind_speed);
  41. // add vehicle speed to get apparent wind vector
  42. wind_vector_ef.x += AP::sitl()->state.speedN;
  43. wind_vector_ef.y += AP::sitl()->state.speedE;
  44. speed_update_frontend(wind_vector_ef.length());
  45. }
  46. #endif