mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-07-27 00:48:23 +08:00
feat(logger): append topics defined in logger_topics.txt instead of replacing all (#27462)
* feat(logger): append topics defined in logger_topics.txt instead of replacing logging profile * docs(logger): Explain how logger_topics.txt topics are being used * refactor(logger): squash initialize functions into a single one * docs(docs): Subedit --------- Co-authored-by: Hamish Willee <hamishwillee@gmail.com> Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
This commit is contained in:
@@ -52,21 +52,27 @@ This allows, for example, logging of your own uORB topics.
|
||||
|
||||
### SD Card Configuration
|
||||
|
||||
Separately, the list of logged topics can also be customized with a file on the SD card.
|
||||
Create a file `etc/logging/logger_topics.txt` on the card with a list of topics (For SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`):
|
||||
The list of logged topics can also be customized with a file on the SD card: `etc/logging/logger_topics.txt` (for SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`).
|
||||
|
||||
Each topic to be logged is listed on a separate line, with the following format:
|
||||
|
||||
```plain
|
||||
<topic_name> <interval> <instance>
|
||||
```
|
||||
|
||||
The `<interval>` is optional, and if specified, defines the minimum interval in ms between two logged messages of this topic.
|
||||
If not specified, the topic is logged at full rate.
|
||||
Where:
|
||||
- `<interval>` (optional).
|
||||
Defines the minimum interval in ms between two logged messages of this topic.
|
||||
If not specified or `0`, the topic is logged at full rate.
|
||||
- `<instance>` (optional).
|
||||
Defines the instance to log.
|
||||
NOte that `<interval>` must be specified in order to set `instance`
|
||||
|
||||
The `<instance>` is optional, and if specified, defines the instance to log.
|
||||
If not specified, all instances of the topic are logged.
|
||||
To specify `<instance>`, `<interval>` must be specified. It can be set to 0 to log at full rate
|
||||
If not specified, all instances of the topic are logged.
|
||||
|
||||
The topics in this file replace all of the default logged topics.
|
||||
The topics in this file will be added on top of the already selected topics.
|
||||
To just log the topics defined in this file, set [SDLOG_PROFILE=0](../advanced_config/parameter_reference.md#SDLOG_PROFILE).
|
||||
If a topic is already included, it will update it's rate.
|
||||
|
||||
Example :
|
||||
|
||||
@@ -77,7 +83,7 @@ sensor_gyro 200
|
||||
sensor_mag 200 1
|
||||
```
|
||||
|
||||
This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz, all sensor_gyro instances at 5Hz and sensor_mag 1 at 5Hz.
|
||||
This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz, all `sensor_gyro` instances at 5Hz and `sensor_mag` 1 at 5Hz.
|
||||
|
||||
## Scripts
|
||||
|
||||
|
||||
@@ -558,20 +558,6 @@ bool LoggedTopics::add_topic_multi(const char *name, uint16_t interval_ms, uint8
|
||||
}
|
||||
|
||||
bool LoggedTopics::initialize_logged_topics(SDLogProfileMask profile)
|
||||
{
|
||||
int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt");
|
||||
|
||||
if (ntopics > 0) {
|
||||
PX4_INFO("logging %d topics from logger_topics.txt", ntopics);
|
||||
|
||||
} else {
|
||||
initialize_configured_topics(profile);
|
||||
}
|
||||
|
||||
return _subscriptions.count > 0;
|
||||
}
|
||||
|
||||
void LoggedTopics::initialize_configured_topics(SDLogProfileMask profile)
|
||||
{
|
||||
// load appropriate topics for profile
|
||||
// the order matters: if several profiles add the same topic, the logging rate of the last one will be used
|
||||
@@ -622,4 +608,16 @@ void LoggedTopics::initialize_configured_topics(SDLogProfileMask profile)
|
||||
if (profile & SDLogProfileMask::HIGH_RATE_SENSORS) {
|
||||
add_high_rate_sensors_topics();
|
||||
}
|
||||
|
||||
int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt");
|
||||
|
||||
if (ntopics > 0) {
|
||||
PX4_INFO("logging %d topics from logger_topics.txt", ntopics);
|
||||
|
||||
} else if ((int32_t)profile == 0) {
|
||||
PX4_WARN("No logging topics added. Using default set");
|
||||
add_default_topics();
|
||||
}
|
||||
|
||||
return _subscriptions.count > 0;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,9 @@ public:
|
||||
*/
|
||||
void initialize_mission_topics(MissionLogType mission_log_type);
|
||||
|
||||
/**
|
||||
* Add topic subscriptions based on the profile configuration and additional topics from SD card
|
||||
*/
|
||||
bool initialize_logged_topics(SDLogProfileMask profile);
|
||||
|
||||
const RequestedSubscriptionArray &subscriptions() const { return _subscriptions; }
|
||||
@@ -160,11 +163,6 @@ private:
|
||||
*/
|
||||
void add_mission_topic(const char *name, uint16_t interval_ms = 0);
|
||||
|
||||
/**
|
||||
* Add topic subscriptions based on the profile configuration
|
||||
*/
|
||||
void initialize_configured_topics(SDLogProfileMask profile);
|
||||
|
||||
void add_default_topics();
|
||||
void add_estimator_replay_topics();
|
||||
void add_thermal_calibration_topics();
|
||||
|
||||
@@ -507,11 +507,6 @@ bool Logger::initialize_topics()
|
||||
// get the logging profile
|
||||
SDLogProfileMask sdlog_profile = (SDLogProfileMask)_param_sdlog_profile.get();
|
||||
|
||||
if ((int32_t)sdlog_profile == 0) {
|
||||
PX4_WARN("No logging profile selected. Using default set");
|
||||
sdlog_profile = SDLogProfileMask::DEFAULT;
|
||||
}
|
||||
|
||||
LoggedTopics logged_topics;
|
||||
logged_topics.set_rate_factor(_rate_factor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user