mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 21:43:33 +08:00
parameter_update use uORB::Subscription consistently
This commit is contained in:
@@ -145,8 +145,7 @@ void Module::run()
|
||||
fds[0].events = POLLIN;
|
||||
|
||||
// initialize parameters
|
||||
int parameter_update_sub = orb_subscribe(ORB_ID(parameter_update));
|
||||
parameters_update(parameter_update_sub, true);
|
||||
parameters_update(true);
|
||||
|
||||
while (!should_exit()) {
|
||||
|
||||
@@ -170,26 +169,21 @@ void Module::run()
|
||||
|
||||
}
|
||||
|
||||
|
||||
parameters_update(parameter_update_sub);
|
||||
parameters_update();
|
||||
}
|
||||
|
||||
orb_unsubscribe(sensor_combined_sub);
|
||||
orb_unsubscribe(parameter_update_sub);
|
||||
}
|
||||
|
||||
void Module::parameters_update(int parameter_update_sub, bool force)
|
||||
void Module::parameters_update(bool force)
|
||||
{
|
||||
bool updated;
|
||||
struct parameter_update_s param_upd;
|
||||
// check for parameter updates
|
||||
if (_parameter_update_sub.updated() || force) {
|
||||
// clear update
|
||||
parameter_update_s update;
|
||||
_parameter_update_sub.copy(&update);
|
||||
|
||||
orb_check(parameter_update_sub, &updated);
|
||||
|
||||
if (updated) {
|
||||
orb_copy(ORB_ID(parameter_update), parameter_update_sub, ¶m_upd);
|
||||
}
|
||||
|
||||
if (force || updated) {
|
||||
// update parameters from storage
|
||||
updateParams();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <px4_module.h>
|
||||
#include <px4_module_params.h>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
|
||||
extern "C" __EXPORT int module_main(int argc, char *argv[]);
|
||||
|
||||
@@ -71,12 +73,16 @@ private:
|
||||
* @param parameter_update_sub uorb subscription to parameter_update
|
||||
* @param force for a parameter update
|
||||
*/
|
||||
void parameters_update(int parameter_update_sub, bool force = false);
|
||||
void parameters_update(bool force = false);
|
||||
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamInt<px4::params::SYS_AUTOSTART>) _param_sys_autostart, /**< example parameter */
|
||||
(ParamInt<px4::params::SYS_AUTOCONFIG>) _param_sys_autoconfig /**< another parameter */
|
||||
)
|
||||
|
||||
// Subscriptions
|
||||
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user