mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 22:40:27 +08:00
* fix(dataman_client): keep request topic advertised on client teardown * fix(uorb): keep shared topics advertised on publisher teardown Single-instance publications share one advertised flag, so destroying one publisher must not hide updates from the others. Keep automatic unadvertising in PublicationMultiBase and remove the DatamanClient workaround. Cover surviving publishers and instance reuse, and reset retained input samples between test cases. Tested: make tests (215/215), make format. Signed-off-by: jonas <jonas.perolini@rigi.tech> Assisted-by: Codex * docs(uorb): correct unadvertise comments and document teardown The unadvertise comment claimed it has no effect on single-instance topics, which is how one publisher's teardown came to hide the others. State what clearing the shared flag does, and document that only PublicationMulti releases its instance on destruction. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: jonas <jonas.perolini@rigi.tech> * test(uorb): keep test cases independent of retained samples A destroyed single-instance publication now leaves its last sample visible, so ManualControlTest, test_prec_takeoff and mixer_module_tests passed only in declaration order and failed under --gtest_shuffle. Reset with an inert sample where one exists, otherwise unadvertise the test's own publications, and drop module outputs left over from a previous case. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: jonas <jonas.perolini@rigi.tech> * fix(boards): drop the PublicationBase destructor from the ITCM lists The destructor is now trivial and no longer emitted, so itcm_check.py fails on the missing section. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> --------- Signed-off-by: jonas <jonas.perolini@rigi.tech> Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> Co-authored-by: jonas <jonas.perolini@rigi.tech> Co-authored-by: Jacob Dahl <dahl.jakejacob@gmail.com> (cherry picked from commite146fe4cc6) Backport adaptation: release/1.18 has no PublicationMultiBase (main's4791b70c15out-lined PublicationMulti), so the destructor that frees the instance goes into PublicationMulti<T> and Publication.cpp is unchanged. The ITCM entries for agam/ark fmu-v6xrt and the navigator tests test_mission_route_cache.cpp / test_prec_takeoff.cpp are dropped: those files are not on release/1.18. TEST_VTEPosition.cpp uses release/1.18's _uav_gps_pub (main renamed it _uav_gnss_pub). Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jonas Perolini <74473718+JonasPerolini@users.noreply.github.com>
This commit is contained in:
1 parent
0b9fcb5fcb
commit
5b22d9ed66
13 files changed
+84
-24
No files matched your search
@@ -701,7 +701,6 @@
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text._Z20px4_spi_bus_externalRK13px4_spi_bus_t)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -701,7 +701,6 @@
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text._Z20px4_spi_bus_externalRK13px4_spi_bus_t)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -715,7 +715,6 @@
|
||||
*(.text._ZN22MavlinkStreamESCStatus8get_sizeEv)
|
||||
*(.text._Z20px4_spi_bus_externalRK13px4_spi_bus_t)
|
||||
*(.text.read)
|
||||
*(.text._ZN4uORB15PublicationBaseD1Ev)
|
||||
*(.text._ZN22MavlinkStreamDebugVect8get_sizeEv)
|
||||
*(.text._ZN7Mission11on_inactiveEv)
|
||||
*(.text._ZN7sensors19VehicleMagnetometer20UpdateMagCalibrationEv)
|
||||
|
||||
@@ -187,6 +187,9 @@ A subscriber will then have to choose to which instance to subscribe to using `o
|
||||
|
||||
Make sure not to mix `orb_advertise_multi` and `orb_advertise` for the same topic!
|
||||
|
||||
Destroying a `uORB::PublicationMulti` frees its instance for the next publisher.
|
||||
Destroying a `uORB::Publication` leaves the topic advertised with its last sample, because other publishers may share it.
|
||||
|
||||
The full API is documented in [platforms/common/uORB/uORBManager.hpp](https://github.com/PX4/PX4-Autopilot/blob/main/platforms/common/uORB/uORBManager.hpp).
|
||||
|
||||
## Listing Topics and Listening in
|
||||
|
||||
@@ -64,15 +64,8 @@ protected:
|
||||
|
||||
PublicationBase(ORB_ID id) : _orb_id(id) {}
|
||||
|
||||
~PublicationBase()
|
||||
{
|
||||
if (_handle != nullptr) {
|
||||
// don't automatically unadvertise queued publications (eg vehicle_command)
|
||||
if (Manager::orb_get_queue_size(_handle) == 1) {
|
||||
unadvertise();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Single-instance publishers share the node, so destruction must not unadvertise it.
|
||||
~PublicationBase() = default;
|
||||
|
||||
// type-independent publish; data points to a message of the topic's type
|
||||
bool publish(const void *data);
|
||||
|
||||
@@ -69,6 +69,16 @@ public:
|
||||
PublicationBase(static_cast<ORB_ID>(meta->o_id))
|
||||
{}
|
||||
|
||||
~PublicationMulti()
|
||||
{
|
||||
if (_handle != nullptr) {
|
||||
// free the instance for the next advertiser, but keep queued publications advertised
|
||||
if (Manager::orb_get_queue_size(_handle) == 1) {
|
||||
unadvertise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool advertise()
|
||||
{
|
||||
if (!advertised()) {
|
||||
|
||||
@@ -304,15 +304,9 @@ int uORB::DeviceNode::unadvertise(orb_advert_t handle)
|
||||
uORB::DeviceNode *devnode = (uORB::DeviceNode *)handle;
|
||||
|
||||
/*
|
||||
* We are cheating a bit here. First, with the current implementation, we can only
|
||||
* have multiple publishers for instance 0. In this case the caller will have
|
||||
* instance=nullptr and _published has no effect at all. Thus no unadvertise is
|
||||
* necessary.
|
||||
* In case of multiple instances, we have at most 1 publisher per instance and
|
||||
* we can signal an instance as 'free' by setting _published to false.
|
||||
* We never really free the DeviceNode, for this we would need reference counting
|
||||
* of subscribers and publishers. But we also do not have a leak since future
|
||||
* publishers reuse the same DeviceNode object.
|
||||
* Frees a multi-instance node for the next advertiser and hides it from all subscribers.
|
||||
* Publishers of a single-instance topic share this flag, so unadvertising hides all of them.
|
||||
* The DeviceNode is never freed; later publishers reuse it.
|
||||
*/
|
||||
devnode->_advertised.store(false);
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ private:
|
||||
List<uORB::SubscriptionCallback *> _callbacks;
|
||||
|
||||
const uint8_t _instance; /**< orb multi instance identifier */
|
||||
px4::atomic_bool _advertised{false}; /**< has ever been advertised (not necessarily published data yet) */
|
||||
px4::atomic_bool _advertised{false}; /**< set on advertise, cleared on unadvertise; subscribers only read while set */
|
||||
|
||||
int8_t _subscriber_count{0};
|
||||
|
||||
|
||||
@@ -258,6 +258,7 @@ public:
|
||||
|
||||
/**
|
||||
* Unadvertise a topic.
|
||||
* This hides the topic instance from all subscribers, including data from other publishers of a single-instance topic.
|
||||
*
|
||||
* @param handle handle returned by orb_advertise or orb_advertise_multi.
|
||||
* @return 0 on success
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/SubscriptionMultiArray.hpp>
|
||||
|
||||
uORBTest::UnitTest &uORBTest::UnitTest::instance()
|
||||
@@ -324,6 +326,32 @@ int uORBTest::UnitTest::test_single()
|
||||
return test_fail("orb_unadvertise failed: %i", ret);
|
||||
}
|
||||
|
||||
uORB::Publication<orb_test_s> surviving_pub{ORB_ID::orb_test};
|
||||
uORB::Subscription sub{ORB_ID::orb_test};
|
||||
t.val = 3;
|
||||
|
||||
if (!surviving_pub.publish(t) || !sub.update(&u) || u.val != t.val) {
|
||||
return test_fail("initial publication failed");
|
||||
}
|
||||
|
||||
{
|
||||
uORB::Publication<orb_test_s> temporary_pub{ORB_ID::orb_test};
|
||||
t.val = 4;
|
||||
|
||||
if (!temporary_pub.publish(t) || !sub.update(&u) || u.val != t.val) {
|
||||
return test_fail("second publication failed");
|
||||
}
|
||||
}
|
||||
|
||||
t.val = 5;
|
||||
|
||||
if (!surviving_pub.publish(t) || !sub.update(&u) || u.val != t.val) {
|
||||
return test_fail("publication lost after another publisher was destroyed");
|
||||
}
|
||||
|
||||
// Leave the topic unadvertised for the multi-instance tests.
|
||||
surviving_pub.unadvertise();
|
||||
|
||||
return test_note("PASS single-topic test");
|
||||
}
|
||||
|
||||
@@ -332,6 +360,14 @@ int uORBTest::UnitTest::test_multi()
|
||||
/* this routine tests the multi-topic support */
|
||||
test_note("try multi-topic support");
|
||||
|
||||
{
|
||||
uORB::PublicationMulti<orb_test_s> temporary_pub{ORB_ID::orb_multitest};
|
||||
|
||||
if (!temporary_pub.advertise() || temporary_pub.get_instance() != 0) {
|
||||
return test_fail("multi-instance advertisement failed");
|
||||
}
|
||||
} // Destruction must release instance 0 for reuse below.
|
||||
|
||||
orb_test_s t{};
|
||||
orb_test_s u{};
|
||||
|
||||
|
||||
@@ -82,6 +82,14 @@ class OutputModuleTest : public OutputModuleInterface
|
||||
public:
|
||||
OutputModuleTest() : OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default) {};
|
||||
|
||||
~OutputModuleTest() override
|
||||
{
|
||||
// Hide this test's commands from the next test: a zero actuator command is not inert
|
||||
_actuator_motors_pub.unadvertise();
|
||||
_actuator_servos_pub.unadvertise();
|
||||
_actuator_armed_pub.unadvertise();
|
||||
}
|
||||
|
||||
void Run() override
|
||||
{
|
||||
was_scheduled = true;
|
||||
|
||||
@@ -83,10 +83,24 @@ public:
|
||||
param_set(param_find("COM_FLTMODE5"), &mode);
|
||||
mode = NAVIGATION_STATE_AUTO_MISSION;
|
||||
param_set(param_find("COM_FLTMODE6"), &mode);
|
||||
|
||||
// Drop outputs left over from a previous test
|
||||
while (_manual_control_setpoint_sub.update()) {}
|
||||
|
||||
while (_action_request_sub.update()) {}
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
// Hide this test's inputs from the next test: empty switch or status samples are not inert
|
||||
_manual_control_switches_pub.unadvertise();
|
||||
_manual_control_input_pub.unadvertise();
|
||||
_vehicle_status_pub.unadvertise();
|
||||
}
|
||||
|
||||
uORB::Publication<manual_control_switches_s> _manual_control_switches_pub{ORB_ID(manual_control_switches)};
|
||||
uORB::Publication<manual_control_setpoint_s> _manual_control_input_pub{ORB_ID(manual_control_input)};
|
||||
uORB::Publication<vehicle_status_s> _vehicle_status_pub{ORB_ID(vehicle_status)};
|
||||
uORB::SubscriptionData<manual_control_setpoint_s> _manual_control_setpoint_sub{ORB_ID(manual_control_setpoint)};
|
||||
uORB::SubscriptionData<action_request_s> _action_request_sub{ORB_ID(action_request)};
|
||||
|
||||
@@ -309,8 +323,7 @@ TEST_F(SwitchTest, ModeSwitchInitialization)
|
||||
TEST_F(SwitchTest, ModeSwitchInitializationArmed)
|
||||
{
|
||||
// GIVEN: vehicle is armed
|
||||
uORB::Publication<vehicle_status_s> vehicle_status_pub{ORB_ID(vehicle_status)};
|
||||
vehicle_status_pub.publish({.arming_state = vehicle_status_s::ARMING_STATE_ARMED});
|
||||
_vehicle_status_pub.publish({.arming_state = vehicle_status_s::ARMING_STATE_ARMED});
|
||||
|
||||
// GIVEN: valid stick input from RC
|
||||
_manual_control_input_pub.publish({.timestamp_sample = _timestamp, .valid = true, .data_source = manual_control_setpoint_s::SOURCE_RC});
|
||||
|
||||
@@ -143,6 +143,11 @@ protected:
|
||||
_uav_gps_pub = std::make_unique<uORB::Publication<sensor_gps_s>>(ORB_ID(vehicle_gps_position));
|
||||
_target_gps_pub = std::make_unique<uORB::Publication<target_gnss_s>>(ORB_ID(target_gnss));
|
||||
|
||||
// Discard input samples retained from the previous test.
|
||||
_vision_pub->publish({});
|
||||
_uav_gps_pub->publish({});
|
||||
_target_gps_pub->publish({});
|
||||
|
||||
_aid_fiducial_sub = std::make_unique<uORB::SubscriptionData<vte_aid_source3d_s>>(ORB_ID(vte_aid_fiducial_marker));
|
||||
_aid_gps_mission_sub = std::make_unique<uORB::SubscriptionData<vte_aid_source3d_s>>(ORB_ID(vte_aid_gps_pos_mission));
|
||||
_aid_gps_target_sub = std::make_unique<uORB::SubscriptionData<vte_aid_source3d_s>>(ORB_ID(vte_aid_gps_pos_target));
|
||||
|
||||
Reference in new issue
Block a user