4 changed files with 112 additions and 1 deletions
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
#include <AP_HAL/AP_HAL.h> |
||||
#include "AC_PrecLand_SITL.h" |
||||
|
||||
extern const AP_HAL::HAL& hal; |
||||
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL |
||||
|
||||
#include <stdio.h> |
||||
|
||||
// Constructor
|
||||
AC_PrecLand_SITL::AC_PrecLand_SITL(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state) |
||||
: AC_PrecLand_Backend(frontend, state) |
||||
{ |
||||
} |
||||
|
||||
// init - perform initialisation of this backend
|
||||
void AC_PrecLand_SITL::init() |
||||
{ |
||||
} |
||||
|
||||
// update - give chance to driver to get updates from sensor
|
||||
void AC_PrecLand_SITL::update() |
||||
{ |
||||
const uint32_t now = AP_HAL::millis(); |
||||
if (_los_meas_time_ms + 10 > now) { // 100Hz update
|
||||
return; |
||||
} |
||||
|
||||
// get new sensor data; we always point home
|
||||
Vector3f home; |
||||
if (! _frontend._ahrs.get_relative_position_NED(home)) { |
||||
_state.healthy = false; |
||||
return; |
||||
} |
||||
if (home.length() > 10.0f) { // we can see the target out to 10 metres
|
||||
return; |
||||
} |
||||
_state.healthy = true; |
||||
|
||||
const Matrix3f &body_to_ned = _frontend._ahrs.get_rotation_body_to_ned(); |
||||
|
||||
_los_meas_body = body_to_ned.mul_transpose(-home); |
||||
_los_meas_body /= _los_meas_body.length(); |
||||
_los_meas_time_ms = now; |
||||
} |
||||
|
||||
bool AC_PrecLand_SITL::have_los_meas() { |
||||
return 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::get_los_body(Vector3f& ret) { |
||||
if (AP_HAL::millis() - _los_meas_time_ms > 1000) { |
||||
// no measurement for a full second; no vector available
|
||||
return false; |
||||
} |
||||
ret = _los_meas_body; |
||||
return true; |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
#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> |
||||
|
||||
/*
|
||||
* AC_PrecLand_SITL - supplies vectors to a fake landing target |
||||
*/ |
||||
|
||||
class AC_PrecLand_SITL : public AC_PrecLand_Backend |
||||
{ |
||||
public: |
||||
|
||||
// Constructor
|
||||
AC_PrecLand_SITL(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 _los_meas_time_ms; } |
||||
|
||||
// return true if there is a valid los measurement available
|
||||
bool have_los_meas(); |
||||
|
||||
private: |
||||
|
||||
Vector3f _los_meas_body; // unit vector in body frame pointing towards target
|
||||
uint32_t _los_meas_time_ms; // system time in milliseconds when los was measured
|
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue