Browse Source
Preprocessor directives were used to hack in the use of AP_IRLock_SITL. Instead, make it a full backend itself.master
Peter Barker
8 years ago
committed by
Randy Mackay
5 changed files with 115 additions and 7 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
#include <AP_HAL/AP_HAL.h> |
||||
#include "AC_PrecLand_SITL_Gazebo.h" |
||||
|
||||
extern const AP_HAL::HAL& hal; |
||||
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL |
||||
|
||||
// Constructor
|
||||
AC_PrecLand_SITL_Gazebo::AC_PrecLand_SITL_Gazebo(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state) |
||||
: AC_PrecLand_Backend(frontend, state), |
||||
irlock() |
||||
{ |
||||
} |
||||
|
||||
// init - perform initialisation of this backend
|
||||
void AC_PrecLand_SITL_Gazebo::init() |
||||
{ |
||||
irlock.init(); |
||||
} |
||||
|
||||
// update - give chance to driver to get updates from sensor
|
||||
void AC_PrecLand_SITL_Gazebo::update() |
||||
{ |
||||
// update health
|
||||
_state.healthy = irlock.healthy(); |
||||
|
||||
// get new sensor data
|
||||
irlock.update(); |
||||
|
||||
if (irlock.num_targets() > 0 && irlock.last_update_ms() != _los_meas_time_ms) { |
||||
irlock.get_unit_vector_body(_los_meas_body); |
||||
_have_los_meas = true; |
||||
_los_meas_time_ms = irlock.last_update_ms(); |
||||
} |
||||
_have_los_meas = _have_los_meas && AP_HAL::millis()-_los_meas_time_ms <= 1000; |
||||
} |
||||
|
||||
// provides a unit vector towards the target in body frame
|
||||
// returns same as have_los_meas()
|
||||
bool AC_PrecLand_SITL_Gazebo::get_los_body(Vector3f& ret) { |
||||
if (have_los_meas()) { |
||||
ret = _los_meas_body; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
// returns system time in milliseconds of last los measurement
|
||||
uint32_t AC_PrecLand_SITL_Gazebo::los_meas_time_ms() { |
||||
return _los_meas_time_ms; |
||||
} |
||||
|
||||
// return true if there is a valid los measurement available
|
||||
bool AC_PrecLand_SITL_Gazebo::have_los_meas() { |
||||
return _have_los_meas; |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
#pragma once |
||||
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL |
||||
#include <AP_Common/AP_Common.h> |
||||
#include <AP_Math/AP_Math.h> |
||||
#include <AC_PrecLand/AC_PrecLand_Backend.h> |
||||
#include <AP_IRLock/AP_IRLock_SITL.h> |
||||
|
||||
/*
|
||||
* AC_PrecLand_SITL_Gazebo - implements precision landing using target |
||||
* vectors provided Gazebo via a network socket |
||||
*/ |
||||
|
||||
class AC_PrecLand_SITL_Gazebo : public AC_PrecLand_Backend |
||||
{ |
||||
public: |
||||
|
||||
// Constructor
|
||||
AC_PrecLand_SITL_Gazebo(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state); |
||||
|
||||
// perform any required initialisation of backend
|
||||
void init(); |
||||
|
||||
// retrieve updates from sensor
|
||||
void update(); |
||||
|
||||
// provides a unit vector towards the target in body frame
|
||||
// returns same as have_los_meas()
|
||||
bool get_los_body(Vector3f& ret); |
||||
|
||||
// returns system time in milliseconds of last los measurement
|
||||
uint32_t los_meas_time_ms(); |
||||
|
||||
// return true if there is a valid los measurement available
|
||||
bool have_los_meas(); |
||||
|
||||
private: |
||||
AP_IRLock_SITL irlock; |
||||
|
||||
Vector3f _los_meas_body; // unit vector in body frame pointing towards target
|
||||
bool _have_los_meas; // true if there is a valid measurement from the camera
|
||||
uint32_t _los_meas_time_ms; // system time in milliseconds when los was measured
|
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue