AC_PrecLand_SITL_Gazebo.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <AP_HAL/AP_HAL.h>
  2. #include "AC_PrecLand_SITL_Gazebo.h"
  3. extern const AP_HAL::HAL& hal;
  4. #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
  5. // Constructor
  6. AC_PrecLand_SITL_Gazebo::AC_PrecLand_SITL_Gazebo(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state)
  7. : AC_PrecLand_Backend(frontend, state),
  8. irlock()
  9. {
  10. }
  11. // init - perform initialisation of this backend
  12. void AC_PrecLand_SITL_Gazebo::init()
  13. {
  14. irlock.init(get_bus());
  15. }
  16. // update - give chance to driver to get updates from sensor
  17. void AC_PrecLand_SITL_Gazebo::update()
  18. {
  19. // update health
  20. _state.healthy = irlock.healthy();
  21. // get new sensor data
  22. irlock.update();
  23. if (irlock.num_targets() > 0 && irlock.last_update_ms() != _los_meas_time_ms) {
  24. irlock.get_unit_vector_body(_los_meas_body);
  25. _have_los_meas = true;
  26. _los_meas_time_ms = irlock.last_update_ms();
  27. }
  28. _have_los_meas = _have_los_meas && AP_HAL::millis()-_los_meas_time_ms <= 1000;
  29. }
  30. // provides a unit vector towards the target in body frame
  31. // returns same as have_los_meas()
  32. bool AC_PrecLand_SITL_Gazebo::get_los_body(Vector3f& ret) {
  33. if (have_los_meas()) {
  34. ret = _los_meas_body;
  35. return true;
  36. }
  37. return false;
  38. }
  39. // returns system time in milliseconds of last los measurement
  40. uint32_t AC_PrecLand_SITL_Gazebo::los_meas_time_ms() {
  41. return _los_meas_time_ms;
  42. }
  43. // return true if there is a valid los measurement available
  44. bool AC_PrecLand_SITL_Gazebo::have_los_meas() {
  45. return _have_los_meas;
  46. }
  47. #endif