Skip to content

Commit

Permalink
AP_RPM: Improve rpm logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKear committed Jul 2, 2024
1 parent 5fa2fcf commit 9590e55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
31 changes: 17 additions & 14 deletions libraries/AP_RPM/AP_RPM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ void AP_RPM::update(void)
}

#if HAL_LOGGING_ENABLED
if (enabled(0) || enabled(1)) {
Log_RPM();
}
Log_RPM();
#endif
}

Expand Down Expand Up @@ -295,18 +293,23 @@ bool AP_RPM::arming_checks(size_t buflen, char *buffer) const
#if HAL_LOGGING_ENABLED
void AP_RPM::Log_RPM() const
{
float rpm1 = -1, rpm2 = -1;

get_rpm(0, rpm1);
get_rpm(1, rpm2);
// update logging for each instance
for (uint8_t i=0; i<num_instances; i++) {
if (drivers[i] == nullptr || enabled(i)) {
// don't log unused instances
continue;
}

const struct log_RPM pkt{
LOG_PACKET_HEADER_INIT(LOG_RPM_MSG),
time_us : AP_HAL::micros64(),
rpm1 : rpm1,
rpm2 : rpm2
};
AP::logger().WriteBlock(&pkt, sizeof(pkt));
const struct log_RPM pkt{
LOG_PACKET_HEADER_INIT(LOG_RPM_MSG),
time_us : AP_HAL::micros64(),
inst : i,
rpm : state[i].rate_rpm,
quality : get_signal_quality(i),
health : uint8_t(healthy(i))
};
AP::logger().WriteBlock(&pkt, sizeof(pkt));
}
}
#endif

Expand Down
14 changes: 9 additions & 5 deletions libraries/AP_RPM/LogStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
// @LoggerMessage: RPM
// @Description: Data from RPM sensors
// @Field: TimeUS: Time since system startup
// @Field: rpm1: First sensor's data
// @Field: rpm2: Second sensor's data
// @Field: I: Instance
// @Field: RPM: Sensor's rpm measurement
// @Field: Qual: Signal quality
// @Field: H: Sensor Health (Bool)
struct PACKED log_RPM {
LOG_PACKET_HEADER;
uint64_t time_us;
float rpm1;
float rpm2;
uint8_t inst;
float rpm;
float quality;
uint8_t health;
};

#define LOG_STRUCTURE_FROM_RPM \
{ LOG_RPM_MSG, sizeof(log_RPM), \
"RPM", "Qff", "TimeUS,rpm1,rpm2", "sqq", "F00" , true },
"RPM", "QBffB", "TimeUS,I,RPM,Qual,H", "s#q--", "F-000" , true },

0 comments on commit 9590e55

Please sign in to comment.