mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-29 19:57:12 +08:00
uORB: SubscriptionCallback cleanup naming
This commit is contained in:
@@ -139,7 +139,7 @@ bool MixingOutput::updateSubscriptions(bool allow_wq_switch)
|
|||||||
if (_groups_required & (1 << i)) {
|
if (_groups_required & (1 << i)) {
|
||||||
PX4_DEBUG("subscribe to actuator_controls_%d", i);
|
PX4_DEBUG("subscribe to actuator_controls_%d", i);
|
||||||
|
|
||||||
if (!_control_subs[i].register_callback()) {
|
if (!_control_subs[i].registerCallback()) {
|
||||||
PX4_ERR("actuator_controls_%d register callback failed!", i);
|
PX4_ERR("actuator_controls_%d register callback failed!", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ void MixingOutput::setAllDisarmedValues(uint16_t value)
|
|||||||
void MixingOutput::unregister()
|
void MixingOutput::unregister()
|
||||||
{
|
{
|
||||||
for (auto &control_sub : _control_subs) {
|
for (auto &control_sub : _control_subs) {
|
||||||
control_sub.unregister_callback();
|
control_sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ FixedwingAttitudeControl::~FixedwingAttitudeControl()
|
|||||||
bool
|
bool
|
||||||
FixedwingAttitudeControl::init()
|
FixedwingAttitudeControl::init()
|
||||||
{
|
{
|
||||||
if (!_att_sub.register_callback()) {
|
if (!_att_sub.registerCallback()) {
|
||||||
PX4_ERR("vehicle attitude callback registration failed!");
|
PX4_ERR("vehicle attitude callback registration failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -444,7 +444,7 @@ float FixedwingAttitudeControl::get_airspeed_and_update_scaling()
|
|||||||
void FixedwingAttitudeControl::Run()
|
void FixedwingAttitudeControl::Run()
|
||||||
{
|
{
|
||||||
if (should_exit()) {
|
if (should_exit()) {
|
||||||
_att_sub.unregister_callback();
|
_att_sub.unregisterCallback();
|
||||||
exit_and_cleanup();
|
exit_and_cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ FixedwingPositionControl::~FixedwingPositionControl()
|
|||||||
bool
|
bool
|
||||||
FixedwingPositionControl::init()
|
FixedwingPositionControl::init()
|
||||||
{
|
{
|
||||||
if (!_global_pos_sub.register_callback()) {
|
if (!_global_pos_sub.registerCallback()) {
|
||||||
PX4_ERR("vehicle global position callback registration failed!");
|
PX4_ERR("vehicle global position callback registration failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1651,7 +1651,7 @@ void
|
|||||||
FixedwingPositionControl::Run()
|
FixedwingPositionControl::Run()
|
||||||
{
|
{
|
||||||
if (should_exit()) {
|
if (should_exit()) {
|
||||||
_global_pos_sub.unregister_callback();
|
_global_pos_sub.unregisterCallback();
|
||||||
exit_and_cleanup();
|
exit_and_cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ MulticopterAttitudeControl::~MulticopterAttitudeControl()
|
|||||||
bool
|
bool
|
||||||
MulticopterAttitudeControl::init()
|
MulticopterAttitudeControl::init()
|
||||||
{
|
{
|
||||||
if (!_vehicle_angular_velocity_sub.register_callback()) {
|
if (!_vehicle_angular_velocity_sub.registerCallback()) {
|
||||||
PX4_ERR("vehicle_angular_velocity callback registration failed!");
|
PX4_ERR("vehicle_angular_velocity callback registration failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -520,7 +520,7 @@ void
|
|||||||
MulticopterAttitudeControl::Run()
|
MulticopterAttitudeControl::Run()
|
||||||
{
|
{
|
||||||
if (should_exit()) {
|
if (should_exit()) {
|
||||||
_vehicle_angular_velocity_sub.unregister_callback();
|
_vehicle_angular_velocity_sub.unregisterCallback();
|
||||||
exit_and_cleanup();
|
exit_and_cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ VehicleAcceleration::Start()
|
|||||||
SensorBiasUpdate(true);
|
SensorBiasUpdate(true);
|
||||||
|
|
||||||
// needed to change the active sensor if the primary stops updating
|
// needed to change the active sensor if the primary stops updating
|
||||||
_sensor_selection_sub.register_callback();
|
_sensor_selection_sub.registerCallback();
|
||||||
|
|
||||||
return SensorCorrectionsUpdate(true);
|
return SensorCorrectionsUpdate(true);
|
||||||
}
|
}
|
||||||
@@ -81,10 +81,10 @@ VehicleAcceleration::Stop()
|
|||||||
|
|
||||||
// clear all registered callbacks
|
// clear all registered callbacks
|
||||||
for (auto &sub : _sensor_sub) {
|
for (auto &sub : _sensor_sub) {
|
||||||
sub.unregister_callback();
|
sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
_sensor_selection_sub.unregister_callback();
|
_sensor_selection_sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -132,12 +132,12 @@ VehicleAcceleration::SensorCorrectionsUpdate(bool force)
|
|||||||
if (corrections.selected_accel_instance < MAX_SENSOR_COUNT) {
|
if (corrections.selected_accel_instance < MAX_SENSOR_COUNT) {
|
||||||
// clear all registered callbacks
|
// clear all registered callbacks
|
||||||
for (auto &sub : _sensor_sub) {
|
for (auto &sub : _sensor_sub) {
|
||||||
sub.unregister_callback();
|
sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int sensor_new = corrections.selected_accel_instance;
|
const int sensor_new = corrections.selected_accel_instance;
|
||||||
|
|
||||||
if (_sensor_sub[sensor_new].register_callback()) {
|
if (_sensor_sub[sensor_new].registerCallback()) {
|
||||||
PX4_DEBUG("selected sensor changed %d -> %d", _selected_sensor, sensor_new);
|
PX4_DEBUG("selected sensor changed %d -> %d", _selected_sensor, sensor_new);
|
||||||
_selected_sensor = sensor_new;
|
_selected_sensor = sensor_new;
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ VehicleAngularVelocity::Start()
|
|||||||
SensorBiasUpdate(true);
|
SensorBiasUpdate(true);
|
||||||
|
|
||||||
// needed to change the active sensor if the primary stops updating
|
// needed to change the active sensor if the primary stops updating
|
||||||
_sensor_selection_sub.register_callback();
|
_sensor_selection_sub.registerCallback();
|
||||||
|
|
||||||
return SensorCorrectionsUpdate(true);
|
return SensorCorrectionsUpdate(true);
|
||||||
}
|
}
|
||||||
@@ -81,10 +81,10 @@ VehicleAngularVelocity::Stop()
|
|||||||
|
|
||||||
// clear all registered callbacks
|
// clear all registered callbacks
|
||||||
for (auto &sub : _sensor_sub) {
|
for (auto &sub : _sensor_sub) {
|
||||||
sub.unregister_callback();
|
sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
_sensor_selection_sub.unregister_callback();
|
_sensor_selection_sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -143,11 +143,11 @@ VehicleAngularVelocity::SensorCorrectionsUpdate(bool force)
|
|||||||
if (corrections.selected_gyro_instance < MAX_SENSOR_COUNT) {
|
if (corrections.selected_gyro_instance < MAX_SENSOR_COUNT) {
|
||||||
// clear all registered callbacks
|
// clear all registered callbacks
|
||||||
for (auto &sub : _sensor_control_sub) {
|
for (auto &sub : _sensor_control_sub) {
|
||||||
sub.unregister_callback();
|
sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &sub : _sensor_sub) {
|
for (auto &sub : _sensor_sub) {
|
||||||
sub.unregister_callback();
|
sub.unregisterCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int sensor_new = corrections.selected_gyro_instance;
|
const int sensor_new = corrections.selected_gyro_instance;
|
||||||
@@ -159,7 +159,7 @@ VehicleAngularVelocity::SensorCorrectionsUpdate(bool force)
|
|||||||
_sensor_control_sub[i].copy(&report);
|
_sensor_control_sub[i].copy(&report);
|
||||||
|
|
||||||
if ((report.device_id != 0) && (report.device_id == _selected_sensor_device_id)) {
|
if ((report.device_id != 0) && (report.device_id == _selected_sensor_device_id)) {
|
||||||
if (_sensor_control_sub[i].register_callback()) {
|
if (_sensor_control_sub[i].registerCallback()) {
|
||||||
PX4_DEBUG("selected sensor (control) changed %d -> %d", _selected_sensor, i);
|
PX4_DEBUG("selected sensor (control) changed %d -> %d", _selected_sensor, i);
|
||||||
_selected_sensor_control = i;
|
_selected_sensor_control = i;
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ VehicleAngularVelocity::SensorCorrectionsUpdate(bool force)
|
|||||||
// otherwise fallback to using sensor_gyro (legacy that will be removed)
|
// otherwise fallback to using sensor_gyro (legacy that will be removed)
|
||||||
_sensor_control_available = false;
|
_sensor_control_available = false;
|
||||||
|
|
||||||
if (_sensor_sub[sensor_new].register_callback()) {
|
if (_sensor_sub[sensor_new].registerCallback()) {
|
||||||
PX4_DEBUG("selected sensor changed %d -> %d", _selected_sensor, sensor_new);
|
PX4_DEBUG("selected sensor changed %d -> %d", _selected_sensor, sensor_new);
|
||||||
_selected_sensor = sensor_new;
|
_selected_sensor = sensor_new;
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param meta The uORB metadata (usually from the ORB_ID() macro) for the topic.
|
* @param meta The uORB metadata (usually from the ORB_ID() macro) for the topic.
|
||||||
|
* @param interval_ms The requested maximum update interval in milliseconds.
|
||||||
* @param instance The instance for multi sub.
|
* @param instance The instance for multi sub.
|
||||||
*/
|
*/
|
||||||
SubscriptionCallback(const orb_metadata *meta, uint8_t interval_ms = 0, uint8_t instance = 0) :
|
SubscriptionCallback(const orb_metadata *meta, uint8_t interval_ms = 0, uint8_t instance = 0) :
|
||||||
@@ -62,10 +63,10 @@ public:
|
|||||||
|
|
||||||
virtual ~SubscriptionCallback()
|
virtual ~SubscriptionCallback()
|
||||||
{
|
{
|
||||||
unregister_callback();
|
unregisterCallback();
|
||||||
};
|
};
|
||||||
|
|
||||||
bool register_callback()
|
bool registerCallback()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_callback()
|
void unregisterCallback()
|
||||||
{
|
{
|
||||||
if (_subscription.get_node()) {
|
if (_subscription.get_node()) {
|
||||||
_subscription.get_node()->unregister_callback(this);
|
_subscription.get_node()->unregister_callback(this);
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ protected:
|
|||||||
|
|
||||||
Subscription _subscription;
|
Subscription _subscription;
|
||||||
uint64_t _last_update{0}; // last update in microseconds
|
uint64_t _last_update{0}; // last update in microseconds
|
||||||
uint32_t _interval_us{0}; // maximum update interval in microseconds
|
uint32_t _interval_us{0}; // maximum update interval in microseconds
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -114,12 +114,12 @@ VtolAttitudeControl::~VtolAttitudeControl()
|
|||||||
bool
|
bool
|
||||||
VtolAttitudeControl::init()
|
VtolAttitudeControl::init()
|
||||||
{
|
{
|
||||||
if (!_actuator_inputs_mc.register_callback()) {
|
if (!_actuator_inputs_mc.registerCallback()) {
|
||||||
PX4_ERR("MC actuator controls callback registration failed!");
|
PX4_ERR("MC actuator controls callback registration failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_actuator_inputs_fw.register_callback()) {
|
if (!_actuator_inputs_fw.registerCallback()) {
|
||||||
PX4_ERR("FW actuator controls callback registration failed!");
|
PX4_ERR("FW actuator controls callback registration failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -290,8 +290,8 @@ void
|
|||||||
VtolAttitudeControl::Run()
|
VtolAttitudeControl::Run()
|
||||||
{
|
{
|
||||||
if (should_exit()) {
|
if (should_exit()) {
|
||||||
_actuator_inputs_fw.unregister_callback();
|
_actuator_inputs_fw.unregisterCallback();
|
||||||
_actuator_inputs_mc.unregister_callback();
|
_actuator_inputs_mc.unregisterCallback();
|
||||||
exit_and_cleanup();
|
exit_and_cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user