mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 19:43:33 +08:00
Added room in land_detector code for free-fall detection
This commit is contained in:
@@ -45,6 +45,9 @@
|
||||
#include <px4_config.h>
|
||||
#include <px4_defines.h>
|
||||
|
||||
namespace landdetection
|
||||
{
|
||||
|
||||
LandDetector::LandDetector() :
|
||||
_landDetectedPub(0),
|
||||
_landDetected( {0, false}),
|
||||
@@ -88,6 +91,7 @@ void LandDetector::cycle()
|
||||
// advertise the first land detected uORB
|
||||
_landDetected.timestamp = hrt_absolute_time();
|
||||
_landDetected.landed = false;
|
||||
_landDetected.freefall = false;
|
||||
_landDetectedPub = orb_advertise(ORB_ID(vehicle_land_detected), &_landDetected);
|
||||
|
||||
// initialize land detection algorithm
|
||||
@@ -98,12 +102,15 @@ void LandDetector::cycle()
|
||||
_taskShouldExit = false;
|
||||
}
|
||||
|
||||
bool landDetected = update();
|
||||
LandDetectionResult current_state = update();
|
||||
bool landDetected = (current_state==LANDDETECTION_RES_LANDED);
|
||||
bool freefallDetected = (current_state==LANDDETECTION_RES_FREEFALL);
|
||||
|
||||
// publish if land detection state has changed
|
||||
if (_landDetected.landed != landDetected) {
|
||||
if ((_landDetected.landed != landDetected) || (_landDetected.freefall != freefallDetected)) {
|
||||
_landDetected.timestamp = hrt_absolute_time();
|
||||
_landDetected.landed = landDetected;
|
||||
_landDetected.freefall = freefallDetected;
|
||||
|
||||
// publish the land detected broadcast
|
||||
orb_publish(ORB_ID(vehicle_land_detected), (orb_advert_t)_landDetectedPub, &_landDetected);
|
||||
@@ -135,3 +142,5 @@ bool LandDetector::orb_update(const struct orb_metadata *meta, int handle, void
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user