parameter_update use uORB::Subscription consistently

This commit is contained in:
Daniel Agar
2019-07-28 11:55:52 -04:00
parent bbb96cbd0c
commit c8e59c4e39
47 changed files with 274 additions and 259 deletions
+6 -2
View File
@@ -292,9 +292,13 @@ float Heater::temperature_setpoint(char *argv[])
void Heater::update_params(const bool force) void Heater::update_params(const bool force)
{ {
parameter_update_s param_update; // check for parameter updates
if (_parameter_update_sub.updated() || force) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (_params_sub.update(&param_update) || force) { // update parameters from storage
ModuleParams::updateParams(); ModuleParams::updateParams();
} }
} }
+1 -1
View File
@@ -174,7 +174,7 @@ private:
float _integrator_value = 0.0f; float _integrator_value = 0.0f;
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
float _proportional_value = 0.0f; float _proportional_value = 0.0f;
+6 -3
View File
@@ -80,7 +80,8 @@ private:
volatile bool _running{false}; volatile bool _running{false};
volatile bool _should_run{true}; volatile bool _should_run{true};
bool _leds_enabled{true}; bool _leds_enabled{true};
uORB::Subscription _param_sub{ORB_ID(parameter_update)};
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
LedController _led_controller; LedController _led_controller;
@@ -202,11 +203,13 @@ RGBLED::Run()
return; return;
} }
if (_param_sub.updated()) { // check for parameter updates
if (_parameter_update_sub.updated()) {
// clear update // clear update
parameter_update_s pupdate; parameter_update_s pupdate;
_param_sub.copy(&pupdate); _parameter_update_sub.copy(&pupdate);
// update parameters from storage
update_params(); update_params();
// Immediately update to change brightness // Immediately update to change brightness
@@ -80,7 +80,8 @@ private:
volatile bool _running{false}; volatile bool _running{false};
volatile bool _should_run{true}; volatile bool _should_run{true};
bool _leds_enabled{true}; bool _leds_enabled{true};
uORB::Subscription _param_sub{ORB_ID(parameter_update)};
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
LedController _led_controller; LedController _led_controller;
@@ -166,11 +167,13 @@ RGBLED_NPC5623C::Run()
return; return;
} }
if (_param_sub.updated()) { // check for parameter updates
if (_parameter_update_sub.updated()) {
// clear update // clear update
parameter_update_s pupdate; parameter_update_s pupdate;
_param_sub.copy(&pupdate); _parameter_update_sub.copy(&pupdate);
// update parameters from storage
update_params(); update_params();
// Immediately update to change brightness // Immediately update to change brightness
+8 -13
View File
@@ -42,7 +42,7 @@
#include <px4_getopt.h> #include <px4_getopt.h>
#include <px4_posix.h> #include <px4_posix.h>
#include <uORB/uORB.h> #include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_controls.h> #include <uORB/topics/actuator_controls.h>
#include <uORB/topics/actuator_outputs.h> #include <uORB/topics/actuator_outputs.h>
#include <uORB/topics/actuator_armed.h> #include <uORB/topics/actuator_armed.h>
@@ -260,7 +260,7 @@ void task_main(int argc, char *argv[])
Mixer::Airmode airmode = Mixer::Airmode::disabled; Mixer::Airmode airmode = Mixer::Airmode::disabled;
update_params(airmode); update_params(airmode);
int params_sub = orb_subscribe(ORB_ID(parameter_update)); uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
int rc_channels_sub = -1; int rc_channels_sub = -1;
@@ -418,16 +418,15 @@ void task_main(int argc, char *argv[])
_task_should_exit = true; _task_should_exit = true;
} }
/* check for parameter updates */ // check for parameter updates
bool param_updated = false; if (parameter_update_sub.updated()) {
orb_check(params_sub, &param_updated); // clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
if (param_updated) { // update parameters from storage
struct parameter_update_s update;
orb_copy(ORB_ID(parameter_update), params_sub, &update);
update_params(airmode); update_params(airmode);
} }
} }
delete pwm_out; delete pwm_out;
@@ -447,10 +446,6 @@ void task_main(int argc, char *argv[])
orb_unsubscribe(rc_channels_sub); orb_unsubscribe(rc_channels_sub);
} }
if (params_sub != -1) {
orb_unsubscribe(params_sub);
}
perf_free(_perf_control_latency); perf_free(_perf_control_latency);
_is_running = false; _is_running = false;
+9 -8
View File
@@ -36,6 +36,8 @@
#include <px4_time.h> #include <px4_time.h>
#include <mathlib/mathlib.h> #include <mathlib/mathlib.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/multirotor_motor_limits.h> #include <uORB/topics/multirotor_motor_limits.h>
PWMSim::PWMSim() : PWMSim::PWMSim() :
@@ -162,7 +164,7 @@ PWMSim::run()
_armed_sub = orb_subscribe(ORB_ID(actuator_armed)); _armed_sub = orb_subscribe(ORB_ID(actuator_armed));
update_params(); update_params();
int params_sub = orb_subscribe(ORB_ID(parameter_update)); uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
/* loop until killed */ /* loop until killed */
while (!should_exit()) { while (!should_exit()) {
@@ -323,13 +325,13 @@ PWMSim::run()
} }
} }
/* check for parameter updates */ // check for parameter updates
bool param_updated = false; if (parameter_update_sub.updated()) {
orb_check(params_sub, &param_updated); // clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
if (param_updated) { // update parameters from storage
struct parameter_update_s update;
orb_copy(ORB_ID(parameter_update), params_sub, &update);
update_params(); update_params();
} }
} }
@@ -341,7 +343,6 @@ PWMSim::run()
} }
orb_unsubscribe(_armed_sub); orb_unsubscribe(_armed_sub);
orb_unsubscribe(params_sub);
} }
int int
+8 -6
View File
@@ -177,7 +177,7 @@ private:
unsigned _current_update_rate{0}; unsigned _current_update_rate{0};
uORB::Subscription _param_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
unsigned _num_outputs{0}; unsigned _num_outputs{0};
@@ -767,7 +767,13 @@ PX4FMU::Run()
update_pwm_out_state(pwm_on); update_pwm_out_state(pwm_on);
} }
if (_param_sub.updated()) { // check for parameter updates
if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
// update parameters from storage
update_params(); update_params();
} }
@@ -783,16 +789,12 @@ PX4FMU::Run()
void PX4FMU::update_params() void PX4FMU::update_params()
{ {
parameter_update_s pupdate;
_param_sub.update(&pupdate);
update_pwm_rev_mask(); update_pwm_rev_mask();
update_pwm_trims(); update_pwm_trims();
updateParams(); updateParams();
} }
int int
PX4FMU::ioctl(file *filp, int cmd, unsigned long arg) PX4FMU::ioctl(file *filp, int cmd, unsigned long arg)
{ {
+8 -4
View File
@@ -256,7 +256,7 @@ private:
uORB::Subscription _t_actuator_controls_3{ORB_ID(actuator_controls_3)};; ///< actuator controls group 3 topic uORB::Subscription _t_actuator_controls_3{ORB_ID(actuator_controls_3)};; ///< actuator controls group 3 topic
uORB::Subscription _t_actuator_armed{ORB_ID(actuator_armed)}; ///< system armed control topic uORB::Subscription _t_actuator_armed{ORB_ID(actuator_armed)}; ///< system armed control topic
uORB::Subscription _t_vehicle_control_mode{ORB_ID(vehicle_control_mode)}; ///< vehicle control mode topic uORB::Subscription _t_vehicle_control_mode{ORB_ID(vehicle_control_mode)}; ///< vehicle control mode topic
uORB::Subscription _t_param{ORB_ID(parameter_update)}; ///< parameter update topic uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; ///< parameter update topic
uORB::Subscription _t_vehicle_command{ORB_ID(vehicle_command)}; ///< vehicle command topic uORB::Subscription _t_vehicle_command{ORB_ID(vehicle_command)}; ///< vehicle command topic
bool _param_update_force; ///< force a parameter update bool _param_update_force; ///< force a parameter update
@@ -997,10 +997,14 @@ PX4IO::task_main()
* *
* XXX this may be a bit spammy * XXX this may be a bit spammy
*/ */
if (_t_param.updated() || _param_update_force) {
_param_update_force = false; // check for parameter updates
if (_parameter_update_sub.updated() || _param_update_force) {
// clear update
parameter_update_s pupdate; parameter_update_s pupdate;
_t_param.copy(&pupdate); _parameter_update_sub.copy(&pupdate);
_param_update_force = false;
if (!_rc_handling_disabled) { if (!_rc_handling_disabled) {
/* re-upload RC input config as it may have changed */ /* re-upload RC input config as it may have changed */
@@ -40,7 +40,7 @@
#include <cmath> // NAN #include <cmath> // NAN
#include <string.h> #include <string.h>
#include <uORB/uORB.h> #include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_controls.h> #include <uORB/topics/actuator_controls.h>
#include <uORB/topics/actuator_outputs.h> #include <uORB/topics/actuator_outputs.h>
#include <uORB/topics/actuator_armed.h> #include <uORB/topics/actuator_armed.h>
@@ -357,7 +357,7 @@ void task_main(int argc, char *argv[])
Mixer::Airmode airmode = Mixer::Airmode::disabled; Mixer::Airmode airmode = Mixer::Airmode::disabled;
update_params(airmode); update_params(airmode);
int params_sub = orb_subscribe(ORB_ID(parameter_update)); uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
// Start disarmed // Start disarmed
_armed.armed = false; _armed.armed = false;
@@ -471,13 +471,13 @@ void task_main(int argc, char *argv[])
} }
} }
/* check for parameter updates */ // check for parameter updates
bool param_updated = false; if (parameter_update_sub.updated()) {
orb_check(params_sub, &param_updated); // clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
if (param_updated) { // update parameters from storage
struct parameter_update_s update;
orb_copy(ORB_ID(parameter_update), params_sub, &update);
update_params(airmode); update_params(airmode);
} }
} }
@@ -491,7 +491,6 @@ void task_main(int argc, char *argv[])
} }
orb_unsubscribe(_armed_sub); orb_unsubscribe(_armed_sub);
orb_unsubscribe(params_sub);
perf_free(_perf_control_latency); perf_free(_perf_control_latency);
+10 -10
View File
@@ -47,7 +47,7 @@
#include <lib/cdev/CDev.hpp> #include <lib/cdev/CDev.hpp>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <px4_module_params.h> #include <px4_module_params.h>
#include <uORB/uORB.h> #include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_controls.h> #include <uORB/topics/actuator_controls.h>
#include <uORB/topics/actuator_outputs.h> #include <uORB/topics/actuator_outputs.h>
#include <uORB/topics/actuator_armed.h> #include <uORB/topics/actuator_armed.h>
@@ -114,7 +114,9 @@ private:
bool _is_armed = false; bool _is_armed = false;
int _armed_sub = -1; int _armed_sub = -1;
int _test_motor_sub = -1; int _test_motor_sub = -1;
int _params_sub = -1;
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
orb_advert_t _outputs_pub = nullptr; orb_advert_t _outputs_pub = nullptr;
actuator_outputs_s _outputs = {}; actuator_outputs_s _outputs = {};
actuator_armed_s _armed = {}; actuator_armed_s _armed = {};
@@ -191,7 +193,6 @@ TAP_ESC::~TAP_ESC()
orb_unsubscribe(_armed_sub); orb_unsubscribe(_armed_sub);
orb_unsubscribe(_test_motor_sub); orb_unsubscribe(_test_motor_sub);
orb_unsubscribe(_params_sub);
orb_unadvertise(_outputs_pub); orb_unadvertise(_outputs_pub);
orb_unadvertise(_esc_feedback_pub); orb_unadvertise(_esc_feedback_pub);
@@ -336,7 +337,6 @@ int TAP_ESC::init()
_armed_sub = orb_subscribe(ORB_ID(actuator_armed)); _armed_sub = orb_subscribe(ORB_ID(actuator_armed));
_test_motor_sub = orb_subscribe(ORB_ID(test_motor)); _test_motor_sub = orb_subscribe(ORB_ID(test_motor));
_params_sub = orb_subscribe(ORB_ID(parameter_update));
return ret; return ret;
} }
@@ -609,13 +609,13 @@ void TAP_ESC::cycle()
} }
/* check for parameter updates */ // check for parameter updates
bool param_updated = false; if (_parameter_update_sub.updated()) {
orb_check(_params_sub, &param_updated); // clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (param_updated) { // update parameters from storage
struct parameter_update_s update;
orb_copy(ORB_ID(parameter_update), _params_sub, &update);
updateParams(); updateParams();
} }
} }
+8 -9
View File
@@ -55,6 +55,7 @@
#include <arch/board/board.h> #include <arch/board/board.h>
#include <arch/chip/chip.h> #include <arch/chip/chip.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/esc_status.h> #include <uORB/topics/esc_status.h>
#include <uORB/topics/parameter_update.h> #include <uORB/topics/parameter_update.h>
@@ -810,17 +811,17 @@ int UavcanNode::run()
update_params(); update_params();
int params_sub = orb_subscribe(ORB_ID(parameter_update)); uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
while (!_task_should_exit) { while (!_task_should_exit) {
/* check for parameter updates */ // check for parameter updates
bool param_updated = false; if (parameter_update_sub.updated()) {
orb_check(params_sub, &param_updated); // clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
if (param_updated) { // update parameters from storage
struct parameter_update_s update;
orb_copy(ORB_ID(parameter_update), params_sub, &update);
update_params(); update_params();
} }
@@ -995,8 +996,6 @@ int UavcanNode::run()
} }
} }
orb_unsubscribe(params_sub);
(void)::close(busevent_fd); (void)::close(busevent_fd);
teardown(); teardown();
+7 -10
View File
@@ -55,7 +55,7 @@
#include <drivers/device/device.h> #include <drivers/device/device.h>
#include <drivers/drv_hrt.h> #include <drivers/drv_hrt.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include <uORB/uORB.h> #include <uORB/Subscription.hpp>
#include <uORB/topics/vehicle_command.h> #include <uORB/topics/vehicle_command.h>
#include <uORB/topics/actuator_controls.h> #include <uORB/topics/actuator_controls.h>
#include <uORB/topics/wind_estimate.h> #include <uORB/topics/wind_estimate.h>
@@ -411,9 +411,7 @@ BottleDrop::task_main()
int vehicle_global_position_sub = orb_subscribe(ORB_ID(vehicle_global_position)); int vehicle_global_position_sub = orb_subscribe(ORB_ID(vehicle_global_position));
struct parameter_update_s update; uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
memset(&update, 0, sizeof(update));
int parameter_update_sub = orb_subscribe(ORB_ID(parameter_update));
struct mission_item_s flight_vector_s {}; struct mission_item_s flight_vector_s {};
struct mission_item_s flight_vector_e {}; struct mission_item_s flight_vector_e {};
@@ -492,12 +490,11 @@ BottleDrop::task_main()
orb_copy(ORB_ID(vehicle_global_position), vehicle_global_position_sub, &_global_pos); orb_copy(ORB_ID(vehicle_global_position), vehicle_global_position_sub, &_global_pos);
} }
// Get parameter updates // check for parameter updates
orb_check(parameter_update_sub, &updated); if (parameter_update_sub.updated()) {
// clear update
if (updated) { parameter_update_s pupdate;
// copy global position parameter_update_sub.copy(&pupdate);
orb_copy(ORB_ID(parameter_update), parameter_update_sub, &update);
// update all parameters // update all parameters
param_get(param_gproperties, &z_0); param_get(param_gproperties, &z_0);
+13 -13
View File
@@ -54,6 +54,7 @@
#include <systemlib/err.h> #include <systemlib/err.h>
#include <parameters/param.h> #include <parameters/param.h>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_controls.h> #include <uORB/topics/actuator_controls.h>
#include <uORB/topics/manual_control_setpoint.h> #include <uORB/topics/manual_control_setpoint.h>
#include <uORB/topics/parameter_update.h> #include <uORB/topics/parameter_update.h>
@@ -326,15 +327,14 @@ int fixedwing_control_thread_main(int argc, char *argv[])
int manual_sp_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); int manual_sp_sub = orb_subscribe(ORB_ID(manual_control_setpoint));
int vstatus_sub = orb_subscribe(ORB_ID(vehicle_status)); int vstatus_sub = orb_subscribe(ORB_ID(vehicle_status));
int global_sp_sub = orb_subscribe(ORB_ID(position_setpoint_triplet)); int global_sp_sub = orb_subscribe(ORB_ID(position_setpoint_triplet));
int param_sub = orb_subscribe(ORB_ID(parameter_update));
uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
/* Setup of loop */ /* Setup of loop */
struct pollfd fds[2] = {}; struct pollfd fds[1] {};
fds[0].fd = param_sub; fds[0].fd = att_sub;
fds[0].events = POLLIN; fds[0].events = POLLIN;
fds[1].fd = att_sub;
fds[1].events = POLLIN;
while (!thread_should_exit) { while (!thread_should_exit) {
@@ -348,7 +348,7 @@ int fixedwing_control_thread_main(int argc, char *argv[])
* This design pattern makes the controller also agnostic of the attitude * This design pattern makes the controller also agnostic of the attitude
* update speed - it runs as fast as the attitude updates with minimal latency. * update speed - it runs as fast as the attitude updates with minimal latency.
*/ */
int ret = poll(fds, 2, 500); int ret = poll(fds, 1, 500);
if (ret < 0) { if (ret < 0) {
/* /*
@@ -361,18 +361,18 @@ int fixedwing_control_thread_main(int argc, char *argv[])
/* no return value = nothing changed for 500 ms, ignore */ /* no return value = nothing changed for 500 ms, ignore */
} else { } else {
/* only update parameters if they changed */ // check for parameter updates
if (fds[0].revents & POLLIN) { if (parameter_update_sub.updated()) {
/* read from param to clear updated flag (uORB API requirement) */ // clear update
struct parameter_update_s update; parameter_update_s pupdate;
orb_copy(ORB_ID(parameter_update), param_sub, &update); parameter_update_sub.copy(&pupdate);
/* if a param update occured, re-read our parameters */ // if a param update occured, re-read our parameters
parameters_update(&ph, &p); parameters_update(&ph, &p);
} }
/* only run controller if attitude changed */ /* only run controller if attitude changed */
if (fds[1].revents & POLLIN) { if (fds[0].revents & POLLIN) {
/* Check if there is a new position measurement or position setpoint */ /* Check if there is a new position measurement or position setpoint */
+12 -16
View File
@@ -51,7 +51,7 @@
#include <poll.h> #include <poll.h>
#include <time.h> #include <time.h>
#include <drivers/drv_hrt.h> #include <drivers/drv_hrt.h>
#include <uORB/uORB.h> #include <uORB/Subscription.hpp>
#include <uORB/topics/vehicle_global_position.h> #include <uORB/topics/vehicle_global_position.h>
#include <uORB/topics/position_setpoint_triplet.h> #include <uORB/topics/position_setpoint_triplet.h>
#include <uORB/topics/vehicle_attitude.h> #include <uORB/topics/vehicle_attitude.h>
@@ -271,20 +271,16 @@ int rover_steering_control_thread_main(int argc, char *argv[])
int att_sp_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint)); int att_sp_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint));
int param_sub = orb_subscribe(ORB_ID(parameter_update)); uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
/* Setup of loop */ /* Setup of loop */
struct pollfd fds[2]; struct pollfd fds[1] {};
fds[0].fd = param_sub; fds[0].fd = att_sub;
fds[0].events = POLLIN; fds[0].events = POLLIN;
fds[1].fd = att_sub;
fds[1].events = POLLIN;
while (!thread_should_exit) { while (!thread_should_exit) {
/* /*
@@ -297,7 +293,7 @@ int rover_steering_control_thread_main(int argc, char *argv[])
* This design pattern makes the controller also agnostic of the attitude * This design pattern makes the controller also agnostic of the attitude
* update speed - it runs as fast as the attitude updates with minimal latency. * update speed - it runs as fast as the attitude updates with minimal latency.
*/ */
int ret = poll(fds, 2, 500); int ret = poll(fds, 1, 500);
if (ret < 0) { if (ret < 0) {
/* /*
@@ -310,18 +306,18 @@ int rover_steering_control_thread_main(int argc, char *argv[])
/* no return value = nothing changed for 500 ms, ignore */ /* no return value = nothing changed for 500 ms, ignore */
} else { } else {
/* only update parameters if they changed */ // check for parameter updates
if (fds[0].revents & POLLIN) { if (parameter_update_sub.updated()) {
/* read from param to clear updated flag (uORB API requirement) */ // clear update
struct parameter_update_s update; parameter_update_s pupdate;
orb_copy(ORB_ID(parameter_update), param_sub, &update); parameter_update_sub.copy(&pupdate);
/* if a param update occured, re-read our parameters */ // if a param update occured, re-read our parameters
parameters_update(&ph, &pp); parameters_update(&ph, &pp);
} }
/* only run controller if attitude changed */ /* only run controller if attitude changed */
if (fds[1].revents & POLLIN) { if (fds[0].revents & POLLIN) {
/* Check if there is a new position measurement or position setpoint */ /* Check if there is a new position measurement or position setpoint */
@@ -109,7 +109,7 @@ private:
int _sensors_sub = -1; int _sensors_sub = -1;
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
uORB::Subscription _global_pos_sub{ORB_ID(vehicle_global_position)}; uORB::Subscription _global_pos_sub{ORB_ID(vehicle_global_position)};
uORB::Subscription _vision_odom_sub{ORB_ID(vehicle_visual_odometry)}; uORB::Subscription _vision_odom_sub{ORB_ID(vehicle_visual_odometry)};
uORB::Subscription _mocap_odom_sub{ORB_ID(vehicle_mocap_odometry)}; uORB::Subscription _mocap_odom_sub{ORB_ID(vehicle_mocap_odometry)};
@@ -437,10 +437,13 @@ void AttitudeEstimatorQ::task_main()
void AttitudeEstimatorQ::update_parameters(bool force) void AttitudeEstimatorQ::update_parameters(bool force)
{ {
if (_params_sub.updated()) { // check for parameter updates
parameter_update_s param_update; if (_parameter_update_sub.updated() || force) {
_params_sub.copy(&param_update); // clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
// update parameters
param_get(_params_handles.w_acc, &_w_accel); param_get(_params_handles.w_acc, &_w_accel);
param_get(_params_handles.w_mag, &_w_mag); param_get(_params_handles.w_mag, &_w_mag);
+5 -7
View File
@@ -87,7 +87,6 @@
#include <uORB/topics/manual_control_setpoint.h> #include <uORB/topics/manual_control_setpoint.h>
#include <uORB/topics/mavlink_log.h> #include <uORB/topics/mavlink_log.h>
#include <uORB/topics/mission.h> #include <uORB/topics/mission.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/power_button_state.h> #include <uORB/topics/power_button_state.h>
#include <uORB/topics/safety.h> #include <uORB/topics/safety.h>
#include <uORB/topics/subsystem_info.h> #include <uORB/topics/subsystem_info.h>
@@ -1297,7 +1296,6 @@ Commander::run()
uORB::Subscription cpuload_sub{ORB_ID(cpuload)}; uORB::Subscription cpuload_sub{ORB_ID(cpuload)};
uORB::Subscription geofence_result_sub{ORB_ID(geofence_result)}; uORB::Subscription geofence_result_sub{ORB_ID(geofence_result)};
uORB::Subscription land_detector_sub{ORB_ID(vehicle_land_detected)}; uORB::Subscription land_detector_sub{ORB_ID(vehicle_land_detected)};
uORB::Subscription param_changed_sub{ORB_ID(parameter_update)};
uORB::Subscription safety_sub{ORB_ID(safety)}; uORB::Subscription safety_sub{ORB_ID(safety)};
uORB::Subscription sp_man_sub{ORB_ID(manual_control_setpoint)}; uORB::Subscription sp_man_sub{ORB_ID(manual_control_setpoint)};
uORB::Subscription subsys_sub{ORB_ID(subsystem_info)}; uORB::Subscription subsys_sub{ORB_ID(subsystem_info)};
@@ -1418,14 +1416,14 @@ Commander::run()
transition_result_t arming_ret = TRANSITION_NOT_CHANGED; transition_result_t arming_ret = TRANSITION_NOT_CHANGED;
/* update parameters */ /* update parameters */
bool params_updated = param_changed_sub.updated(); bool params_updated = _parameter_update_sub.updated();
if (params_updated || param_init_forced) { if (params_updated || param_init_forced) {
// clear update
parameter_update_s update;
_parameter_update_sub.copy(&update);
/* parameters changed */ // update parameters from storage
parameter_update_s param_changed;
param_changed_sub.copy(&param_changed);
updateParams(); updateParams();
/* update parameters */ /* update parameters */
+2
View File
@@ -60,6 +60,7 @@
#include <uORB/topics/iridiumsbd_status.h> #include <uORB/topics/iridiumsbd_status.h>
#include <uORB/topics/mission_result.h> #include <uORB/topics/mission_result.h>
#include <uORB/topics/offboard_control_mode.h> #include <uORB/topics/offboard_control_mode.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/telemetry_status.h> #include <uORB/topics/telemetry_status.h>
#include <uORB/topics/vehicle_acceleration.h> #include <uORB/topics/vehicle_acceleration.h>
#include <uORB/topics/vehicle_command.h> #include <uORB/topics/vehicle_command.h>
@@ -274,6 +275,7 @@ private:
bool _print_avoidance_msg_once{false}; bool _print_avoidance_msg_once{false};
// Subscriptions // Subscriptions
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)}; uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)};
uORB::SubscriptionData<airspeed_s> _airspeed_sub{ORB_ID(airspeed)}; uORB::SubscriptionData<airspeed_s> _airspeed_sub{ORB_ID(airspeed)};
+8 -5
View File
@@ -265,7 +265,7 @@ private:
uORB::Subscription _landing_target_pose_sub{ORB_ID(landing_target_pose)}; uORB::Subscription _landing_target_pose_sub{ORB_ID(landing_target_pose)};
uORB::Subscription _magnetometer_sub{ORB_ID(vehicle_magnetometer)}; uORB::Subscription _magnetometer_sub{ORB_ID(vehicle_magnetometer)};
uORB::Subscription _optical_flow_sub{ORB_ID(optical_flow)}; uORB::Subscription _optical_flow_sub{ORB_ID(optical_flow)};
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
uORB::Subscription _sensor_selection_sub{ORB_ID(sensor_selection)}; uORB::Subscription _sensor_selection_sub{ORB_ID(sensor_selection)};
uORB::Subscription _status_sub{ORB_ID(vehicle_status)}; uORB::Subscription _status_sub{ORB_ID(vehicle_status)};
uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)}; uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)};
@@ -739,10 +739,13 @@ void Ekf2::run()
perf_begin(_perf_update_data); perf_begin(_perf_update_data);
if (_params_sub.updated()) { // check for parameter updates
// read from param to clear updated flag if (_parameter_update_sub.updated()) {
parameter_update_s update; // clear update
_params_sub.copy(&update); parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
// update parameters from storage
updateParams(); updateParams();
} }
@@ -454,15 +454,16 @@ void FixedwingAttitudeControl::Run()
if (_att_sub.update(&_att)) { if (_att_sub.update(&_att)) {
/* only update parameters if they changed */ // only update parameters if they changed
bool params_updated = _params_sub.updated(); bool params_updated = _parameter_update_sub.updated();
// check for parameter updates
if (params_updated) { if (params_updated) {
/* read from param to clear updated flag */ // clear update
parameter_update_s update; parameter_update_s pupdate;
_params_sub.copy(&update); _parameter_update_sub.copy(&pupdate);
/* update parameters from storage */ // update parameters from storage
parameters_update(); parameters_update();
} }
@@ -101,7 +101,7 @@ private:
uORB::Subscription _battery_status_sub{ORB_ID(battery_status)}; /**< battery status subscription */ uORB::Subscription _battery_status_sub{ORB_ID(battery_status)}; /**< battery status subscription */
uORB::Subscription _global_pos_sub{ORB_ID(vehicle_global_position)}; /**< global position subscription */ uORB::Subscription _global_pos_sub{ORB_ID(vehicle_global_position)}; /**< global position subscription */
uORB::Subscription _manual_sub{ORB_ID(manual_control_setpoint)}; /**< notification of manual control updates */ uORB::Subscription _manual_sub{ORB_ID(manual_control_setpoint)}; /**< notification of manual control updates */
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */ uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
uORB::Subscription _rates_sp_sub{ORB_ID(vehicle_rates_setpoint)}; /**< vehicle rates setpoint */ uORB::Subscription _rates_sp_sub{ORB_ID(vehicle_rates_setpoint)}; /**< vehicle rates setpoint */
uORB::Subscription _vcontrol_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle status subscription */ uORB::Subscription _vcontrol_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle status subscription */
uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)}; /**< vehicle land detected subscription */ uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)}; /**< vehicle land detected subscription */
@@ -1662,15 +1662,13 @@ FixedwingPositionControl::Run()
/* only run controller if position changed */ /* only run controller if position changed */
if (_global_pos_sub.update(&_global_pos)) { if (_global_pos_sub.update(&_global_pos)) {
/* only update parameters if they changed */ // check for parameter updates
bool params_updated = _params_sub.updated(); if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (params_updated) { // update parameters from storage
/* read from param to clear updated flag */
parameter_update_s update;
_params_sub.copy(&update);
/* update parameters from storage */
parameters_update(); parameters_update();
} }
@@ -156,7 +156,7 @@ private:
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)}; ///< control mode subscription */ uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)}; ///< control mode subscription */
uORB::Subscription _local_pos_sub{ORB_ID(vehicle_local_position)}; uORB::Subscription _local_pos_sub{ORB_ID(vehicle_local_position)};
uORB::Subscription _manual_control_sub{ORB_ID(manual_control_setpoint)}; ///< notification of manual control updates */ uORB::Subscription _manual_control_sub{ORB_ID(manual_control_setpoint)}; ///< notification of manual control updates */
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; ///< notification of parameter updates */ uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; ///< notification of parameter updates */
uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)}; uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)};
uORB::Subscription _sensor_baro_sub{ORB_ID(sensor_baro)}; uORB::Subscription _sensor_baro_sub{ORB_ID(sensor_baro)};
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)}; ///< vehicle attitude subscription */ uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)}; ///< vehicle attitude subscription */
@@ -62,9 +62,13 @@ void FixedwingLandDetector::_update_topics()
void FixedwingLandDetector::_update_params() void FixedwingLandDetector::_update_params()
{ {
parameter_update_s param_update; // check for parameter updates
if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (_param_update_sub.update(&param_update)) { // update parameters from storage
_update_params(); _update_params();
} }
} }
@@ -73,7 +73,7 @@ private:
static constexpr hrt_abstime FLYING_TRIGGER_TIME_US = 0_us; static constexpr hrt_abstime FLYING_TRIGGER_TIME_US = 0_us;
uORB::Subscription _airspeed_sub{ORB_ID(airspeed)}; uORB::Subscription _airspeed_sub{ORB_ID(airspeed)};
uORB::Subscription _param_update_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)}; uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)};
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)}; uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
+7 -2
View File
@@ -151,10 +151,15 @@ void LandDetector::Run()
void LandDetector::_check_params(const bool force) void LandDetector::_check_params(const bool force)
{ {
parameter_update_s param_update; // check for parameter updates
if (_parameter_update_sub.updated() || force) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (_param_update_sub.update(&param_update) || force) { // update parameters from storage
_update_params(); _update_params();
_update_total_flight_time(); _update_total_flight_time();
} }
} }
+1 -1
View File
@@ -174,7 +174,7 @@ private:
perf_counter_t _cycle_perf{perf_alloc(PC_ELAPSED, "land_detector_cycle")}; perf_counter_t _cycle_perf{perf_alloc(PC_ELAPSED, "land_detector_cycle")};
uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)}; uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)};
uORB::Subscription _param_update_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
DEFINE_PARAMETERS_CUSTOM_PARENT( DEFINE_PARAMETERS_CUSTOM_PARENT(
ModuleParams, ModuleParams,
+4 -2
View File
@@ -976,9 +976,11 @@ void Logger::run()
/* Check if parameters have changed */ /* Check if parameters have changed */
if (!_should_stop_file_log) { // do not record param changes after disarming if (!_should_stop_file_log) { // do not record param changes after disarming
parameter_update_s param_update; if (parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
if (parameter_update_sub.update(&param_update)) {
write_changed_parameters(LogType::Full); write_changed_parameters(LogType::Full);
} }
} }
+9 -5
View File
@@ -2141,9 +2141,9 @@ Mavlink::task_main(int argc, char *argv[])
pthread_mutex_init(&_message_buffer_mutex, nullptr); pthread_mutex_init(&_message_buffer_mutex, nullptr);
} }
uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
MavlinkOrbSubscription *cmd_sub = add_orb_subscription(ORB_ID(vehicle_command), 0, true); MavlinkOrbSubscription *cmd_sub = add_orb_subscription(ORB_ID(vehicle_command), 0, true);
MavlinkOrbSubscription *param_sub = add_orb_subscription(ORB_ID(parameter_update));
uint64_t param_time = 0;
MavlinkOrbSubscription *status_sub = add_orb_subscription(ORB_ID(vehicle_status)); MavlinkOrbSubscription *status_sub = add_orb_subscription(ORB_ID(vehicle_status));
uint64_t status_time = 0; uint64_t status_time = 0;
MavlinkOrbSubscription *ack_sub = add_orb_subscription(ORB_ID(vehicle_command_ack), 0, true); MavlinkOrbSubscription *ack_sub = add_orb_subscription(ORB_ID(vehicle_command_ack), 0, true);
@@ -2239,9 +2239,13 @@ Mavlink::task_main(int argc, char *argv[])
update_rate_mult(); update_rate_mult();
parameter_update_s param_update; // check for parameter updates
if (parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
if (param_sub->update(&param_time, &param_update)) { // update parameters from storage
mavlink_update_parameters(); mavlink_update_parameters();
#if defined(CONFIG_NET) #if defined(CONFIG_NET)
@@ -2250,7 +2254,7 @@ Mavlink::task_main(int argc, char *argv[])
_src_addr_initialized = false; _src_addr_initialized = false;
} }
#endif #endif // CONFIG_NET
} }
check_radio_config(); check_radio_config();
+9 -11
View File
@@ -2569,9 +2569,15 @@ MavlinkReceiver::Run()
hrt_abstime last_send_update = 0; hrt_abstime last_send_update = 0;
while (!_mavlink->_task_should_exit) { while (!_mavlink->_task_should_exit) {
// Check for updated parameters.
if (_param_update_sub.updated()) { // check for parameter updates
update_params(); if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
// update parameters from storage
updateParams();
} }
if (poll(&fds[0], 1, timeout) > 0) { if (poll(&fds[0], 1, timeout) > 0) {
@@ -2718,11 +2724,3 @@ MavlinkReceiver::receive_start(pthread_t *thread, Mavlink *parent)
pthread_attr_destroy(&receiveloop_attr); pthread_attr_destroy(&receiveloop_attr);
} }
void
MavlinkReceiver::update_params()
{
parameter_update_s param_update;
_param_update_sub.update(&param_update);
updateParams();
}
+1 -1
View File
@@ -259,7 +259,7 @@ private:
// ORB subscriptions // ORB subscriptions
uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)}; uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)};
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)}; uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)};
uORB::Subscription _param_update_sub{ORB_ID(parameter_update)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)}; uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)}; uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
@@ -146,7 +146,7 @@ private:
uORB::Subscription _v_att_sp_sub{ORB_ID(vehicle_attitude_setpoint)}; /**< vehicle attitude setpoint subscription */ uORB::Subscription _v_att_sp_sub{ORB_ID(vehicle_attitude_setpoint)}; /**< vehicle attitude setpoint subscription */
uORB::Subscription _v_rates_sp_sub{ORB_ID(vehicle_rates_setpoint)}; /**< vehicle rates setpoint subscription */ uORB::Subscription _v_rates_sp_sub{ORB_ID(vehicle_rates_setpoint)}; /**< vehicle rates setpoint subscription */
uORB::Subscription _v_control_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */ uORB::Subscription _v_control_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; /**< parameter updates subscription */ uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< parameter updates subscription */
uORB::Subscription _manual_control_sp_sub{ORB_ID(manual_control_setpoint)}; /**< manual control setpoint subscription */ uORB::Subscription _manual_control_sp_sub{ORB_ID(manual_control_setpoint)}; /**< manual control setpoint subscription */
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; /**< vehicle status subscription */ uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; /**< vehicle status subscription */
uORB::Subscription _motor_limits_sub{ORB_ID(multirotor_motor_limits)}; /**< motor limits subscription */ uORB::Subscription _motor_limits_sub{ORB_ID(multirotor_motor_limits)}; /**< motor limits subscription */
@@ -137,11 +137,13 @@ MulticopterAttitudeControl::parameters_updated()
void void
MulticopterAttitudeControl::parameter_update_poll() MulticopterAttitudeControl::parameter_update_poll()
{ {
/* Check if parameters have changed */ // check for parameter updates
parameter_update_s param_update; if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (_params_sub.update(&param_update)) { // update parameters from storage
updateParams();
parameters_updated(); parameters_updated();
} }
} }
@@ -123,7 +123,7 @@ private:
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; /**< vehicle status subscription */ uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; /**< vehicle status subscription */
uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)}; /**< vehicle land detected subscription */ uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)}; /**< vehicle land detected subscription */
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */ uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */ uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
uORB::Subscription _att_sub{ORB_ID(vehicle_attitude)}; /**< vehicle attitude */ uORB::Subscription _att_sub{ORB_ID(vehicle_attitude)}; /**< vehicle attitude */
uORB::Subscription _home_pos_sub{ORB_ID(home_position)}; /**< home position */ uORB::Subscription _home_pos_sub{ORB_ID(home_position)}; /**< home position */
@@ -312,10 +312,13 @@ MulticopterPositionControl::warn_rate_limited(const char *string)
int int
MulticopterPositionControl::parameters_update(bool force) MulticopterPositionControl::parameters_update(bool force)
{ {
parameter_update_s param_upd; // check for parameter updates
bool updated = _params_sub.update(&param_upd); if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
if (updated || force) { // update parameters from storage
ModuleParams::updateParams(); ModuleParams::updateParams();
SuperBlock::updateParams(); SuperBlock::updateParams();
+1 -1
View File
@@ -317,7 +317,7 @@ private:
uORB::Subscription _gps_pos_sub{ORB_ID(vehicle_gps_position)}; /**< gps position subscription */ uORB::Subscription _gps_pos_sub{ORB_ID(vehicle_gps_position)}; /**< gps position subscription */
uORB::Subscription _home_pos_sub{ORB_ID(home_position)}; /**< home position subscription */ uORB::Subscription _home_pos_sub{ORB_ID(home_position)}; /**< home position subscription */
uORB::Subscription _land_detected_sub{ORB_ID(vehicle_land_detected)}; /**< vehicle land detected subscription */ uORB::Subscription _land_detected_sub{ORB_ID(vehicle_land_detected)}; /**< vehicle land detected subscription */
uORB::Subscription _param_update_sub{ORB_ID(parameter_update)}; /**< param update subscription */ uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< param update subscription */
uORB::Subscription _pos_ctrl_landing_status_sub{ORB_ID(position_controller_landing_status)}; /**< position controller landing status subscription */ uORB::Subscription _pos_ctrl_landing_status_sub{ORB_ID(position_controller_landing_status)}; /**< position controller landing status subscription */
uORB::Subscription _traffic_sub{ORB_ID(transponder_report)}; /**< traffic subscription */ uORB::Subscription _traffic_sub{ORB_ID(transponder_report)}; /**< traffic subscription */
uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)}; /**< vehicle commands (onboard and offboard) */ uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)}; /**< vehicle commands (onboard and offboard) */
+7 -5
View File
@@ -119,9 +119,6 @@ Navigator::~Navigator()
void void
Navigator::params_update() Navigator::params_update()
{ {
parameter_update_s param_update;
_param_update_sub.update(&param_update);
updateParams(); updateParams();
if (_handle_back_trans_dec_mss != PARAM_INVALID) { if (_handle_back_trans_dec_mss != PARAM_INVALID) {
@@ -202,8 +199,13 @@ Navigator::run()
} }
} }
/* parameters updated */ // check for parameter updates
if (_param_update_sub.updated()) { if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
// update parameters from storage
params_update(); params_update();
} }
@@ -70,18 +70,15 @@ RoverPositionControl::~RoverPositionControl()
perf_free(_loop_perf); perf_free(_loop_perf);
} }
void RoverPositionControl::parameters_update(int parameter_update_sub, bool force) void RoverPositionControl::parameters_update(bool force)
{ {
bool updated; // check for parameter updates
struct parameter_update_s param_upd; if (_parameter_update_sub.updated() || force) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
orb_check(parameter_update_sub, &updated); // update parameters from storage
if (updated) {
orb_copy(ORB_ID(parameter_update), parameter_update_sub, &param_upd);
}
if (force || updated) {
updateParams(); updateParams();
_gnd_control.set_l1_damping(_param_l1_damping.get()); _gnd_control.set_l1_damping(_param_l1_damping.get());
@@ -275,7 +272,6 @@ RoverPositionControl::run()
_global_pos_sub = orb_subscribe(ORB_ID(vehicle_global_position)); _global_pos_sub = orb_subscribe(ORB_ID(vehicle_global_position));
_local_pos_sub = orb_subscribe(ORB_ID(vehicle_local_position)); _local_pos_sub = orb_subscribe(ORB_ID(vehicle_local_position));
_manual_control_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); _manual_control_sub = orb_subscribe(ORB_ID(manual_control_setpoint));
_params_sub = orb_subscribe(ORB_ID(parameter_update));
_pos_sp_triplet_sub = orb_subscribe(ORB_ID(position_setpoint_triplet)); _pos_sp_triplet_sub = orb_subscribe(ORB_ID(position_setpoint_triplet));
_vehicle_attitude_sub = orb_subscribe(ORB_ID(vehicle_attitude)); _vehicle_attitude_sub = orb_subscribe(ORB_ID(vehicle_attitude));
_sensor_combined_sub = orb_subscribe(ORB_ID(sensor_combined)); _sensor_combined_sub = orb_subscribe(ORB_ID(sensor_combined));
@@ -287,7 +283,7 @@ RoverPositionControl::run()
orb_set_interval(_global_pos_sub, 20); orb_set_interval(_global_pos_sub, 20);
orb_set_interval(_local_pos_sub, 20); orb_set_interval(_local_pos_sub, 20);
parameters_update(_params_sub, true); parameters_update(true);
/* wakeup source(s) */ /* wakeup source(s) */
px4_pollfd_struct_t fds[3]; px4_pollfd_struct_t fds[3];
@@ -318,7 +314,7 @@ RoverPositionControl::run()
_vehicle_acceleration_sub.update(); _vehicle_acceleration_sub.update();
/* update parameters from storage */ /* update parameters from storage */
parameters_update(_params_sub); parameters_update();
bool manual_mode = _control_mode.flag_control_manual_enabled; bool manual_mode = _control_mode.flag_control_manual_enabled;
@@ -430,7 +426,6 @@ RoverPositionControl::run()
orb_unsubscribe(_global_pos_sub); orb_unsubscribe(_global_pos_sub);
orb_unsubscribe(_local_pos_sub); orb_unsubscribe(_local_pos_sub);
orb_unsubscribe(_manual_control_sub); orb_unsubscribe(_manual_control_sub);
orb_unsubscribe(_params_sub);
orb_unsubscribe(_pos_sp_triplet_sub); orb_unsubscribe(_pos_sp_triplet_sub);
orb_unsubscribe(_vehicle_attitude_sub); orb_unsubscribe(_vehicle_attitude_sub);
orb_unsubscribe(_sensor_combined_sub); orb_unsubscribe(_sensor_combined_sub);
@@ -105,11 +105,12 @@ private:
int _global_pos_sub{-1}; int _global_pos_sub{-1};
int _local_pos_sub{-1}; int _local_pos_sub{-1};
int _manual_control_sub{-1}; /**< notification of manual control updates */ int _manual_control_sub{-1}; /**< notification of manual control updates */
int _params_sub{-1}; /**< notification of parameter updates */
int _pos_sp_triplet_sub{-1}; int _pos_sp_triplet_sub{-1};
int _vehicle_attitude_sub{-1}; int _vehicle_attitude_sub{-1};
int _sensor_combined_sub{-1}; int _sensor_combined_sub{-1};
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
manual_control_setpoint_s _manual{}; /**< r/c channel data */ manual_control_setpoint_s _manual{}; /**< r/c channel data */
position_setpoint_triplet_s _pos_sp_triplet{}; /**< triplet of mission items */ position_setpoint_triplet_s _pos_sp_triplet{}; /**< triplet of mission items */
vehicle_control_mode_s _control_mode{}; /**< control mode */ vehicle_control_mode_s _control_mode{}; /**< control mode */
@@ -167,7 +168,7 @@ private:
/** /**
* Update our local parameter cache. * Update our local parameter cache.
*/ */
void parameters_update(int parameter_update_sub, bool force = false); void parameters_update(bool force = false);
void manual_control_setpoint_poll(); void manual_control_setpoint_poll();
void position_setpoint_triplet_poll(); void position_setpoint_triplet_poll();
+7 -6
View File
@@ -168,7 +168,7 @@ private:
uORB::Subscription _actuator_ctrl_0_sub{ORB_ID(actuator_controls_0)}; /**< attitude controls sub */ uORB::Subscription _actuator_ctrl_0_sub{ORB_ID(actuator_controls_0)}; /**< attitude controls sub */
uORB::Subscription _diff_pres_sub{ORB_ID(differential_pressure)}; /**< raw differential pressure subscription */ uORB::Subscription _diff_pres_sub{ORB_ID(differential_pressure)}; /**< raw differential pressure subscription */
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */ uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
uORB::Subscription _vcontrol_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */ uORB::Subscription _vcontrol_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */
uORB::Publication<airspeed_s> _airspeed_pub{ORB_ID(airspeed)}; /**< airspeed */ uORB::Publication<airspeed_s> _airspeed_pub{ORB_ID(airspeed)}; /**< airspeed */
@@ -364,12 +364,13 @@ Sensors::diff_pres_poll(const vehicle_air_data_s &raw)
void void
Sensors::parameter_update_poll(bool forced) Sensors::parameter_update_poll(bool forced)
{ {
/* Check if any parameter has changed */ // check for parameter updates
parameter_update_s update; if (_parameter_update_sub.updated() || forced) {
// clear update
if (_params_sub.update(&update) || forced) { parameter_update_s pupdate;
/* read from param to clear updated flag */ _parameter_update_sub.copy(&pupdate);
// update parameters from storage
parameters_update(); parameters_update();
updateParams(); updateParams();
+6 -8
View File
@@ -110,7 +110,6 @@ void Sih::run()
_actuator_out_sub = orb_subscribe(ORB_ID(actuator_outputs)); _actuator_out_sub = orb_subscribe(ORB_ID(actuator_outputs));
// initialize parameters // initialize parameters
_parameter_update_sub = orb_subscribe(ORB_ID(parameter_update));
parameters_update_poll(); parameters_update_poll();
init_variables(); init_variables();
@@ -143,7 +142,6 @@ void Sih::run()
hrt_cancel(&_timer_call); // close the periodic timer interruption hrt_cancel(&_timer_call); // close the periodic timer interruption
px4_sem_destroy(&_data_semaphore); px4_sem_destroy(&_data_semaphore);
orb_unsubscribe(_actuator_out_sub); orb_unsubscribe(_actuator_out_sub);
orb_unsubscribe(_parameter_update_sub);
} }
// timer_callback() is used as a real time callback to post the semaphore // timer_callback() is used as a real time callback to post the semaphore
@@ -186,13 +184,13 @@ void Sih::inner_loop()
void Sih::parameters_update_poll() void Sih::parameters_update_poll()
{ {
bool updated = false; // check for parameter updates
struct parameter_update_s param_upd; if (_parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
orb_check(_parameter_update_sub, &updated); // update parameters from storage
if (updated) {
orb_copy(ORB_ID(parameter_update), _parameter_update_sub, &param_upd);
updateParams(); updateParams();
parameters_updated(); parameters_updated();
} }
+2 -1
View File
@@ -46,6 +46,7 @@
#include <lib/drivers/gyroscope/PX4Gyroscope.hpp> #include <lib/drivers/gyroscope/PX4Gyroscope.hpp>
#include <lib/drivers/magnetometer/PX4Magnetometer.hpp> #include <lib/drivers/magnetometer/PX4Magnetometer.hpp>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/parameter_update.h> #include <uORB/topics/parameter_update.h>
#include <uORB/topics/vehicle_angular_velocity.h> // to publish groundtruth #include <uORB/topics/vehicle_angular_velocity.h> // to publish groundtruth
#include <uORB/topics/vehicle_attitude.h> // to publish groundtruth #include <uORB/topics/vehicle_attitude.h> // to publish groundtruth
@@ -119,7 +120,7 @@ private:
vehicle_global_position_s _gpos_gt{}; vehicle_global_position_s _gpos_gt{};
orb_advert_t _gpos_gt_pub{nullptr}; orb_advert_t _gpos_gt_pub{nullptr};
int _parameter_update_sub {-1}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
int _actuator_out_sub {-1}; int _actuator_out_sub {-1};
// hard constants // hard constants
+6 -10
View File
@@ -77,17 +77,13 @@ void Simulator::write_gps_data(void *buf)
void Simulator::parameters_update(bool force) void Simulator::parameters_update(bool force)
{ {
bool updated; // check for parameter updates
struct parameter_update_s param_upd; if (_parameter_update_sub.updated() || force) {
// clear update
parameter_update_s pupdate;
_parameter_update_sub.copy(&pupdate);
orb_check(_param_sub, &updated); // update parameters from storage
if (updated) {
orb_copy(ORB_ID(parameter_update), _param_sub, &param_upd);
}
if (updated || force) {
// update C++ param system
updateParams(); updateParams();
} }
} }
+2 -6
View File
@@ -53,6 +53,7 @@
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <px4_module_params.h> #include <px4_module_params.h>
#include <px4_posix.h> #include <px4_posix.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_outputs.h> #include <uORB/topics/actuator_outputs.h>
#include <uORB/topics/battery_status.h> #include <uORB/topics/battery_status.h>
#include <uORB/topics/differential_pressure.h> #include <uORB/topics/differential_pressure.h>
@@ -181,8 +182,6 @@ private:
_gps.writeData(&gps_data); _gps.writeData(&gps_data);
_param_sub = orb_subscribe(ORB_ID(parameter_update));
_battery_status.timestamp = hrt_absolute_time(); _battery_status.timestamp = hrt_absolute_time();
_px4_accel.set_sample_rate(250); _px4_accel.set_sample_rate(250);
@@ -191,9 +190,6 @@ private:
~Simulator() ~Simulator()
{ {
// Unsubscribe from uORB topics.
orb_unsubscribe(_param_sub);
// free perf counters // free perf counters
perf_free(_perf_gps); perf_free(_perf_gps);
perf_free(_perf_sim_delay); perf_free(_perf_sim_delay);
@@ -230,7 +226,7 @@ private:
orb_advert_t _irlock_report_pub{nullptr}; orb_advert_t _irlock_report_pub{nullptr};
orb_advert_t _visual_odometry_pub{nullptr}; orb_advert_t _visual_odometry_pub{nullptr};
int _param_sub{-1}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
unsigned int _port{14560}; unsigned int _port{14560};
+9 -10
View File
@@ -61,7 +61,7 @@
#include "output_rc.h" #include "output_rc.h"
#include "output_mavlink.h" #include "output_mavlink.h"
#include <uORB/uORB.h> #include <uORB/Subscription.hpp>
#include <uORB/topics/parameter_update.h> #include <uORB/topics/parameter_update.h>
#include <px4_config.h> #include <px4_config.h>
@@ -216,7 +216,7 @@ static int vmount_thread_main(int argc, char *argv[])
return -1; return -1;
} }
int parameter_update_sub = orb_subscribe(ORB_ID(parameter_update)); uORB::Subscription parameter_update_sub{ORB_ID(parameter_update)};
thread_running = true; thread_running = true;
ControlData *control_data = nullptr; ControlData *control_data = nullptr;
g_thread_data = &thread_data; g_thread_data = &thread_data;
@@ -370,13 +370,14 @@ static int vmount_thread_main(int argc, char *argv[])
break; break;
} }
// check for parameter updates
if (parameter_update_sub.updated()) {
// clear update
parameter_update_s pupdate;
parameter_update_sub.copy(&pupdate);
//check for parameter changes // update parameters from storage
bool updated; bool updated = false;
if (orb_check(parameter_update_sub, &updated) == 0 && updated) {
parameter_update_s param_update;
orb_copy(ORB_ID(parameter_update), parameter_update_sub, &param_update);
update_params(param_handles, params, updated); update_params(param_handles, params, updated);
if (updated) { if (updated) {
@@ -402,8 +403,6 @@ static int vmount_thread_main(int argc, char *argv[])
g_thread_data = nullptr; g_thread_data = nullptr;
orb_unsubscribe(parameter_update_sub);
for (int i = 0; i < input_objs_len_max; ++i) { for (int i = 0; i < input_objs_len_max; ++i) {
if (thread_data.input_objs[i]) { if (thread_data.input_objs[i]) {
delete (thread_data.input_objs[i]); delete (thread_data.input_objs[i]);
@@ -333,13 +333,13 @@ VtolAttitudeControl::Run()
} }
if (should_run) { if (should_run) {
/* only update parameters if they changed */ // check for parameter updates
if (_params_sub.updated()) { if (_parameter_update_sub.updated()) {
/* read from param to clear updated flag */ // clear update
parameter_update_s update; parameter_update_s pupdate;
_params_sub.copy(&update); _parameter_update_sub.copy(&pupdate);
/* update parameters from storage */ // update parameters from storage
parameters_update(); parameters_update();
} }
@@ -143,7 +143,7 @@ private:
uORB::Subscription _local_pos_sub{ORB_ID(vehicle_local_position)}; // sensor subscription uORB::Subscription _local_pos_sub{ORB_ID(vehicle_local_position)}; // sensor subscription
uORB::Subscription _manual_control_sp_sub{ORB_ID(manual_control_setpoint)}; //manual control setpoint subscription uORB::Subscription _manual_control_sp_sub{ORB_ID(manual_control_setpoint)}; //manual control setpoint subscription
uORB::Subscription _mc_virtual_att_sp_sub{ORB_ID(mc_virtual_attitude_setpoint)}; uORB::Subscription _mc_virtual_att_sp_sub{ORB_ID(mc_virtual_attitude_setpoint)};
uORB::Subscription _params_sub{ORB_ID(parameter_update)}; //parameter updates subscription uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)}; // local position setpoint subscription uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)}; // local position setpoint subscription
uORB::Subscription _tecs_status_sub{ORB_ID(tecs_status)}; uORB::Subscription _tecs_status_sub{ORB_ID(tecs_status)};
uORB::Subscription _v_att_sub{ORB_ID(vehicle_attitude)}; //vehicle attitude subscription uORB::Subscription _v_att_sub{ORB_ID(vehicle_attitude)}; //vehicle attitude subscription
+9 -15
View File
@@ -145,8 +145,7 @@ void Module::run()
fds[0].events = POLLIN; fds[0].events = POLLIN;
// initialize parameters // initialize parameters
int parameter_update_sub = orb_subscribe(ORB_ID(parameter_update)); parameters_update(true);
parameters_update(parameter_update_sub, true);
while (!should_exit()) { while (!should_exit()) {
@@ -170,26 +169,21 @@ void Module::run()
} }
parameters_update();
parameters_update(parameter_update_sub);
} }
orb_unsubscribe(sensor_combined_sub); 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; // check for parameter updates
struct parameter_update_s param_upd; if (_parameter_update_sub.updated() || force) {
// clear update
parameter_update_s update;
_parameter_update_sub.copy(&update);
orb_check(parameter_update_sub, &updated); // update parameters from storage
if (updated) {
orb_copy(ORB_ID(parameter_update), parameter_update_sub, &param_upd);
}
if (force || updated) {
updateParams(); updateParams();
} }
} }
+7 -1
View File
@@ -35,6 +35,8 @@
#include <px4_module.h> #include <px4_module.h>
#include <px4_module_params.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[]); 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 parameter_update_sub uorb subscription to parameter_update
* @param force for a 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( DEFINE_PARAMETERS(
(ParamInt<px4::params::SYS_AUTOSTART>) _param_sys_autostart, /**< example parameter */ (ParamInt<px4::params::SYS_AUTOSTART>) _param_sys_autostart, /**< example parameter */
(ParamInt<px4::params::SYS_AUTOCONFIG>) _param_sys_autoconfig /**< another parameter */ (ParamInt<px4::params::SYS_AUTOCONFIG>) _param_sys_autoconfig /**< another parameter */
) )
// Subscriptions
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
}; };