mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
fix(logger): use selected device_id to choose sensor in fifo logging (#29751)
* fix(logger): use selected device_id to choose sensor in fifo logging * fix(logger): keep logger_topics.txt fifo instances and skip profile fifo without a matching selected imu * docs(logger): describe fifo logging of the selected imu
This commit is contained in:
1 parent
3d743529c5
commit
5db5c623a1
6 files changed
+110
-6
No files matched your search
@@ -220,8 +220,9 @@ Example plot:
|
||||

|
||||
|
||||
::: info
|
||||
Data of the first IMU is logged, which is not necessarily the same as the one used for flying.
|
||||
This is mostly only important in cases where IMU's are mounted differently (e.g. hard-mounted vs. soft-mounted).
|
||||
Data of the IMU that is the primary one when the log starts is logged, not necessarily instance 0.
|
||||
This instance is kept for the whole log and is not changed after an in-flight primary IMU switch.
|
||||
No high-rate data is logged if no IMU is selected when the log starts or if the selected IMU does not publish FIFO data.
|
||||
:::
|
||||
|
||||
::: info
|
||||
|
||||
@@ -147,6 +147,12 @@ public:
|
||||
*/
|
||||
bool copy(void *dst);
|
||||
|
||||
/**
|
||||
* Change subscription instance
|
||||
* @param instance The new multi-subscription instance
|
||||
*/
|
||||
bool ChangeInstance(uint8_t instance) { return _subscription.ChangeInstance(instance); }
|
||||
|
||||
bool valid() const { return _subscription.valid(); }
|
||||
|
||||
uint8_t get_instance() const { return _subscription.get_instance(); }
|
||||
|
||||
@@ -399,12 +399,20 @@ void LoggedTopics::add_vision_and_avoidance_topics()
|
||||
|
||||
void LoggedTopics::add_raw_imu_gyro_fifo()
|
||||
{
|
||||
add_topic("sensor_gyro_fifo");
|
||||
const int count = _subscriptions.count;
|
||||
|
||||
if (add_topic("sensor_gyro_fifo") && (_subscriptions.count == count + 1)) {
|
||||
_subscriptions.sub[count].use_selected_imu_instance = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LoggedTopics::add_raw_imu_accel_fifo()
|
||||
{
|
||||
add_topic("sensor_accel_fifo");
|
||||
const int count = _subscriptions.count;
|
||||
|
||||
if (add_topic("sensor_accel_fifo") && (_subscriptions.count == count + 1)) {
|
||||
_subscriptions.sub[count].use_selected_imu_instance = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LoggedTopics::add_system_identification_topics()
|
||||
@@ -547,8 +555,9 @@ bool LoggedTopics::add_topic(const char *name, uint16_t interval_ms, uint8_t ins
|
||||
|
||||
// check if already added: if so, only update the interval
|
||||
for (int j = 0; j < _subscriptions.count; ++j) {
|
||||
// a subscription that must use the selected IMU instance stays separate from an explicitly requested instance
|
||||
if (_subscriptions.sub[j].id == static_cast<ORB_ID>(topics[i]->o_id) &&
|
||||
_subscriptions.sub[j].instance == instance) {
|
||||
_subscriptions.sub[j].instance == instance && !_subscriptions.sub[j].use_selected_imu_instance) {
|
||||
|
||||
PX4_DEBUG("logging topic %s(%" PRIu8 "), interval: %" PRIu16 ", already added, only setting interval",
|
||||
topics[i]->o_name, instance, interval_ms);
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
uint16_t interval_ms;
|
||||
uint8_t instance;
|
||||
ORB_ID id{ORB_ID::INVALID};
|
||||
bool use_selected_imu_instance{false}; ///< ignore instance: at log start, use the instance of the selected IMU (set by the FIFO logging profile)
|
||||
};
|
||||
struct RequestedSubscriptionArray {
|
||||
RequestedSubscription sub[MAX_TOPICS_NUM];
|
||||
|
||||
@@ -52,6 +52,9 @@
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
#include <uORB/topics/vehicle_command_ack.h>
|
||||
#include <uORB/topics/battery_status.h>
|
||||
#include <uORB/topics/sensor_accel_fifo.h>
|
||||
#include <uORB/topics/sensor_gyro_fifo.h>
|
||||
#include <uORB/topics/sensor_selection.h>
|
||||
|
||||
#include <containers/Bitset.hpp>
|
||||
#include <drivers/drv_hrt.h>
|
||||
@@ -456,6 +459,10 @@ bool Logger::copy_if_updated(int sub_idx, void *buffer, bool try_to_subscribe)
|
||||
{
|
||||
LoggerSubscription &sub = _subscriptions[sub_idx];
|
||||
|
||||
if (!sub.enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool updated = false;
|
||||
|
||||
if (sub.valid()) {
|
||||
@@ -555,6 +562,8 @@ bool Logger::initialize_topics()
|
||||
|
||||
delete[](_subscriptions);
|
||||
_subscriptions = nullptr;
|
||||
_gyro_fifo_sub_idx = -1;
|
||||
_accel_fifo_sub_idx = -1;
|
||||
|
||||
if (logged_topics.subscriptions().count > 0) {
|
||||
_subscriptions = new LoggerSubscription[logged_topics.subscriptions().count];
|
||||
@@ -568,6 +577,15 @@ bool Logger::initialize_topics()
|
||||
const LoggedTopics::RequestedSubscription &sub = logged_topics.subscriptions().sub[i];
|
||||
_subscriptions[i] = LoggerSubscription(sub.id, sub.interval_ms, sub.instance);
|
||||
_subscriptions[i].subscribe();
|
||||
|
||||
if (sub.use_selected_imu_instance) {
|
||||
if (sub.id == ORB_ID::sensor_gyro_fifo) {
|
||||
_gyro_fifo_sub_idx = i;
|
||||
|
||||
} else if (sub.id == ORB_ID::sensor_accel_fifo) {
|
||||
_accel_fifo_sub_idx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1476,12 +1494,68 @@ void Logger::setReplayFile(const char *file_name)
|
||||
_replay_file_name = strdup(file_name);
|
||||
}
|
||||
|
||||
void Logger::select_imu_fifo_instances()
|
||||
{
|
||||
if (_writer.is_started(LogType::Full) || _writer.is_started(LogType::Mission)) {
|
||||
// keep the instance for the duration of a log
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_selection_s sensor_selection{};
|
||||
uORB::Subscription{ORB_ID(sensor_selection)}.copy(&sensor_selection);
|
||||
|
||||
select_fifo_instance<sensor_gyro_fifo_s>(_gyro_fifo_sub_idx, sensor_selection.gyro_device_id);
|
||||
select_fifo_instance<sensor_accel_fifo_s>(_accel_fifo_sub_idx, sensor_selection.accel_device_id);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Logger::select_fifo_instance(int sub_idx, uint32_t device_id)
|
||||
{
|
||||
if (sub_idx < 0) {
|
||||
// not enabled in the logging profile
|
||||
return;
|
||||
}
|
||||
|
||||
LoggerSubscription &fifo_sub = _subscriptions[sub_idx];
|
||||
const orb_metadata *topic = fifo_sub.get_topic();
|
||||
|
||||
bool found = false;
|
||||
|
||||
// without a selection (device_id 0) there is nothing to match
|
||||
for (uint8_t instance = 0; (device_id != 0) && (instance < ORB_MULTI_MAX_INSTANCES); ++instance) {
|
||||
T fifo;
|
||||
|
||||
if (uORB::Subscription{topic, instance}.copy(&fifo) && (fifo.device_id == device_id)) {
|
||||
found = fifo_sub.ChangeInstance(instance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
// log nothing if no IMU is selected yet or it does not publish FIFO data
|
||||
fifo_sub.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// do not log an instance twice if it is also requested through logger_topics.txt
|
||||
fifo_sub.enabled = true;
|
||||
|
||||
for (int i = 0; i < _num_subscriptions; ++i) {
|
||||
if (i != sub_idx && _subscriptions[i].get_topic() == topic
|
||||
&& _subscriptions[i].get_instance() == fifo_sub.get_instance()) {
|
||||
fifo_sub.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::start_log_file(LogType type)
|
||||
{
|
||||
if (_writer.is_started(type, LogWriter::BackendFile) || (_writer.backend() & LogWriter::BackendFile) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
select_imu_fifo_instances();
|
||||
|
||||
if (type == LogType::Full) {
|
||||
int32_t max_size_mib = _param_sdlog_max_size.get();
|
||||
|
||||
@@ -1586,6 +1660,8 @@ void Logger::start_log_mavlink()
|
||||
return;
|
||||
}
|
||||
|
||||
select_imu_fifo_instances();
|
||||
|
||||
// mavlink log does not work in combination with lockstep, it leads to dead-locks
|
||||
px4_lockstep_unregister_component(_lockstep_component);
|
||||
_lockstep_component = -1;
|
||||
@@ -1939,7 +2015,7 @@ void Logger::write_all_add_logged_msg(LogType type)
|
||||
for (int i = 0; i < sub_count; ++i) {
|
||||
LoggerSubscription &sub = _subscriptions[i];
|
||||
|
||||
if (sub.valid()) {
|
||||
if (sub.valid() && sub.enabled) {
|
||||
write_add_logged_msg(type, sub);
|
||||
added_subscriptions = true;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ struct LoggerSubscription : public uORB::SubscriptionInterval {
|
||||
{}
|
||||
|
||||
uint8_t msg_id{MSG_ID_INVALID};
|
||||
bool enabled{true}; ///< if false, the topic is not written to the log
|
||||
};
|
||||
|
||||
class Logger : public ModuleBase, public ModuleParams
|
||||
@@ -226,6 +227,14 @@ private:
|
||||
*/
|
||||
int get_log_file_name(LogType type, char *file_name, size_t file_name_size, bool notify);
|
||||
|
||||
/**
|
||||
* Point the sensor_gyro_fifo/sensor_accel_fifo subscriptions to the instance of the currently selected IMU
|
||||
*/
|
||||
void select_imu_fifo_instances();
|
||||
|
||||
template<typename T>
|
||||
void select_fifo_instance(int sub_idx, uint32_t device_id);
|
||||
|
||||
void start_log_file(LogType type);
|
||||
|
||||
void stop_log_file(LogType type);
|
||||
@@ -371,6 +380,8 @@ private:
|
||||
|
||||
LoggerSubscription *_subscriptions{nullptr}; ///< all subscriptions for full & mission log (in front)
|
||||
int _num_subscriptions{0};
|
||||
int _gyro_fifo_sub_idx{-1}; ///< sensor_gyro_fifo subscription added by the logging profile
|
||||
int _accel_fifo_sub_idx{-1}; ///< sensor_accel_fifo subscription added by the logging profile
|
||||
MissionSubscription _mission_subscriptions[MAX_MISSION_TOPICS_NUM] {}; ///< additional data for mission subscriptions
|
||||
int _num_mission_subs{0};
|
||||
LoggerSubscription _event_subscription; ///< Subscription for the event topic (handled separately)
|
||||
|
||||
Reference in new issue
Block a user