land_detector: big refactor, share update function

This is a big refactor and general cleanup of the land detector. The
main functional change is to share the hysteresis lib across all land
detectors.
This commit is contained in:
Julian Oes
2016-07-30 12:26:56 +02:00
parent 9f928308c4
commit 50cac88e5b
9 changed files with 337 additions and 382 deletions
+20 -31
View File
@@ -36,12 +36,14 @@
* Land detection algorithm for VTOL
*
* @author Roman Bapst <bapstroma@gmail.com>
* @author Julian Oes <julian@oes.ch>
*/
#include "VtolLandDetector.h"
#include <drivers/drv_hrt.h>
namespace landdetection
#include "VtolLandDetector.h"
namespace land_detector
{
VtolLandDetector::VtolLandDetector() : MulticopterLandDetector(),
@@ -56,29 +58,24 @@ VtolLandDetector::VtolLandDetector() : MulticopterLandDetector(),
_paramHandle.maxAirSpeed = param_find("LNDFW_AIRSPD_MAX");
}
void VtolLandDetector::initialize()
void VtolLandDetector::_initialize_topics()
{
MulticopterLandDetector::initialize();
MulticopterLandDetector::_initialize_topics();
_airspeedSub = orb_subscribe(ORB_ID(airspeed));
// download parameters
updateParameterCache(true);
}
void VtolLandDetector::updateSubscriptions()
void VtolLandDetector::_update_topics()
{
MulticopterLandDetector::updateSubscriptions();
MulticopterLandDetector::_update_topics();
orb_update(ORB_ID(airspeed), _airspeedSub, &_airspeed);
_orb_update(ORB_ID(airspeed), _airspeedSub, &_airspeed);
}
LandDetectionResult VtolLandDetector::update()
bool VtolLandDetector::_get_landed_state()
{
updateSubscriptions();
updateParameterCache(false);
// this is returned from the mutlicopter land detector
bool landed = get_landed_state();
bool landed = MulticopterLandDetector::_get_landed_state();
// for vtol we additionally consider airspeed
if (hrt_elapsed_time(&_airspeed.timestamp) < 500 * 1000) {
@@ -97,27 +94,19 @@ LandDetectionResult VtolLandDetector::update()
_was_in_air = !landed;
_state = (landed) ? LANDDETECTION_RES_LANDED : LANDDETECTION_RES_FLYING;
return _state;
return landed;
}
void VtolLandDetector::updateParameterCache(const bool force)
bool VtolLandDetector::_get_freefall_state()
{
MulticopterLandDetector::updateParameterCache(force);
return MulticopterLandDetector::_get_freefall_state();
}
bool updated;
parameter_update_s paramUpdate;
void VtolLandDetector::_update_params()
{
MulticopterLandDetector::_update_params();
orb_check(_parameterSub, &updated);
if (updated) {
orb_copy(ORB_ID(parameter_update), _parameterSub, &paramUpdate);
}
if (updated || force) {
param_get(_paramHandle.maxAirSpeed, &_params.maxAirSpeed);
}
param_get(_paramHandle.maxAirSpeed, &_params.maxAirSpeed);
}
}