land_detector move orb subscriptions to uORB::Subscription

This commit is contained in:
Daniel Agar
2019-06-04 18:10:21 -04:00
parent 2320088541
commit 53aa4130a8
10 changed files with 34 additions and 125 deletions
+3 -48
View File
@@ -46,7 +46,7 @@
#include <px4_config.h>
#include <px4_defines.h>
#include <drivers/drv_hrt.h>
#include "uORB/topics/parameter_update.h"
#include <uORB/topics/parameter_update.h>
using namespace time_literals;
@@ -61,18 +61,6 @@ LandDetector::LandDetector() :
LandDetector::~LandDetector()
{
perf_free(_cycle_perf);
if (_armingSub >= 0) {
orb_unsubscribe(_armingSub);
}
if (_parameterSub >= 0) {
orb_unsubscribe(_parameterSub);
}
if (_landDetectedPub) {
orb_unadvertise(_landDetectedPub);
}
}
int LandDetector::start()
@@ -104,18 +92,13 @@ void LandDetector::_cycle()
_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI");
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO");
// Initialize uORB topics.
_armingSub = orb_subscribe(ORB_ID(actuator_armed));
_parameterSub = orb_subscribe(ORB_ID(parameter_update));
_initialize_topics();
_check_params(true);
_object.store(this);
}
_check_params(false);
_orb_update(ORB_ID(actuator_armed), _armingSub, &_arming);
_armingSub.update(&_arming);
_update_topics();
_update_state();
@@ -184,16 +167,9 @@ void LandDetector::_cycle()
}
void LandDetector::_check_params(const bool force)
{
bool updated;
parameter_update_s paramUpdate;
orb_check(_parameterSub, &updated);
if (updated) {
orb_copy(ORB_ID(parameter_update), _parameterSub, &paramUpdate);
}
if (updated || force) {
if (_parameterSub.update(&paramUpdate) || force) {
_update_params();
uint32_t flight_time;
param_get(_p_total_flight_time_high, (int32_t *)&flight_time);
@@ -231,25 +207,4 @@ void LandDetector::_update_state()
}
}
bool LandDetector::_orb_update(const struct orb_metadata *meta, int handle, void *buffer)
{
bool newData = false;
// check if there is new data to grab
if (orb_check(handle, &newData) != OK) {
return false;
}
if (!newData) {
return false;
}
if (orb_copy(meta, handle, buffer) != OK) {
return false;
}
return true;
}
} // namespace land_detector