summaryrefslogtreecommitdiff
path: root/firmware/os/algos/calibration/nano_calibration/nano_calibration.cc
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/os/algos/calibration/nano_calibration/nano_calibration.cc')
-rw-r--r--firmware/os/algos/calibration/nano_calibration/nano_calibration.cc62
1 files changed, 45 insertions, 17 deletions
diff --git a/firmware/os/algos/calibration/nano_calibration/nano_calibration.cc b/firmware/os/algos/calibration/nano_calibration/nano_calibration.cc
index a8daaeb8..122af489 100644
--- a/firmware/os/algos/calibration/nano_calibration/nano_calibration.cc
+++ b/firmware/os/algos/calibration/nano_calibration/nano_calibration.cc
@@ -19,7 +19,7 @@
#include <cstdint>
#include <cstring>
-#include "chre/util/nanoapp/log.h"
+#include "common/techeng_log_util.h"
namespace nano_calibration {
namespace {
@@ -35,16 +35,15 @@ constexpr char kMagTag[] = {"[NanoSensorCal:MAG_UT]"};
// messages will be produced at a rate determined by
// 'slow_message_interval_min'.
struct LogMessageRegimen {
- uint8_t rapid_message_interval_sec; // Assists device verification.
- uint8_t slow_message_interval_min; // Avoids long-term log spam.
+ uint8_t rapid_message_interval_sec; // Assists device verification.
+ uint8_t slow_message_interval_min; // Avoids long-term log spam.
uint8_t duration_of_rapid_messages_min;
};
constexpr LogMessageRegimen kGyroscopeMessagePlan = {
/*rapid_message_interval_sec*/ 20,
/*slow_message_interval_min*/ 5,
- /*duration_of_rapid_messages_min*/ 3
-};
+ /*duration_of_rapid_messages_min*/ 3};
using ::online_calibration::CalibrationDataThreeAxis;
using ::online_calibration::CalibrationTypeFlags;
@@ -58,18 +57,22 @@ using ::online_calibration::SensorType;
#endif
#ifdef NANO_SENSOR_CAL_DBG_ENABLED
-#define NANO_CAL_LOGD(tag, format, ...) LOGD("%s " format, tag, ##__VA_ARGS__)
-#define NANO_CAL_LOGW(tag, format, ...) LOGW("%s " format, tag, ##__VA_ARGS__)
-#define NANO_CAL_LOGE(tag, format, ...) LOGE("%s " format, tag, ##__VA_ARGS__)
+#define NANO_CAL_LOGD(tag, format, ...) \
+ TECHENG_LOGD("%s " format, tag, ##__VA_ARGS__)
+#define NANO_CAL_LOGW(tag, format, ...) \
+ TECHENG_LOGW("%s " format, tag, ##__VA_ARGS__)
+#define NANO_CAL_LOGE(tag, format, ...) \
+ TECHENG_LOGE("%s " format, tag, ##__VA_ARGS__)
#else
-#define NANO_CAL_LOGD(tag, format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
-#define NANO_CAL_LOGW(tag, format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
-#define NANO_CAL_LOGE(tag, format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
+#define NANO_CAL_LOGD(tag, format, ...) techeng_log_null(format, ##__VA_ARGS__)
+#define NANO_CAL_LOGW(tag, format, ...) techeng_log_null(format, ##__VA_ARGS__)
+#define NANO_CAL_LOGE(tag, format, ...) techeng_log_null(format, ##__VA_ARGS__)
#endif // NANO_SENSOR_CAL_DBG_ENABLED
// NOTE: LOGI is defined to ensure calibration updates are always logged for
// field diagnosis and verification.
-#define NANO_CAL_LOGI(tag, format, ...) LOGI("%s " format, tag, ##__VA_ARGS__)
+#define NANO_CAL_LOGI(tag, format, ...) \
+ TECHENG_LOGI("%s " format, tag, ##__VA_ARGS__)
} // namespace
@@ -199,6 +202,12 @@ void NanoSensorCal::ProcessSample(const SensorData &sample) {
accel_cal_update_flags_, kAccelTag);
PrintCalibration(accel_cal_->GetSensorCalibration(),
accel_cal_update_flags_, kAccelTag);
+
+ if (result_callback_ != nullptr) {
+ result_callback_->SetCalibrationEvent(sample.timestamp_nanos,
+ SensorType::kAccelerometerMps2,
+ accel_cal_update_flags_);
+ }
}
}
@@ -210,7 +219,19 @@ void NanoSensorCal::ProcessSample(const SensorData &sample) {
if (NotifyAshCalibration(CHRE_SENSOR_TYPE_GYROSCOPE,
gyro_cal_->GetSensorCalibration(),
gyro_cal_update_flags_, kGyroTag)) {
- HandleGyroLogMessage(sample.timestamp_nanos);
+ const bool print_gyro_log =
+ HandleGyroLogMessage(sample.timestamp_nanos);
+
+ if (result_callback_ != nullptr &&
+ (print_gyro_log ||
+ gyro_cal_update_flags_ != CalibrationTypeFlags::BIAS)) {
+ // Rate-limits OTC gyro telemetry updates since they can happen
+ // frequently with temperature change. However, all GyroCal stillness
+ // and OTC model parameter updates will be recorded.
+ result_callback_->SetCalibrationEvent(sample.timestamp_nanos,
+ SensorType::kGyroscopeRps,
+ gyro_cal_update_flags_);
+ }
}
}
}
@@ -224,6 +245,12 @@ void NanoSensorCal::ProcessSample(const SensorData &sample) {
mag_cal_update_flags_, kMagTag);
PrintCalibration(mag_cal_->GetSensorCalibration(), mag_cal_update_flags_,
kMagTag);
+
+ if (result_callback_ != nullptr) {
+ result_callback_->SetCalibrationEvent(sample.timestamp_nanos,
+ SensorType::kMagnetometerUt,
+ mag_cal_update_flags_);
+ }
}
}
}
@@ -294,7 +321,7 @@ bool NanoSensorCal::NotifyAshCalibration(
bool NanoSensorCal::LoadAshCalibration(uint8_t chreSensorType,
OnlineCalibrationThreeAxis *online_cal,
- CalibrationTypeFlags* flags,
+ CalibrationTypeFlags *flags,
const char *sensor_tag) {
ashCalParams recalled_ash_cal_parameters;
if (ashLoadCalibrationParams(chreSensorType, ASH_CAL_STORAGE_ASH,
@@ -443,7 +470,7 @@ void NanoSensorCal::PrintCalibration(const CalibrationDataThreeAxis &cal_data,
}
}
-void NanoSensorCal::HandleGyroLogMessage(uint64_t timestamp_nanos) {
+bool NanoSensorCal::HandleGyroLogMessage(uint64_t timestamp_nanos) {
// Limits the log messaging update rate for the gyro calibrations since
// these can occur frequently with rapid temperature changes.
const int64_t next_log_interval_nanos =
@@ -454,14 +481,15 @@ void NanoSensorCal::HandleGyroLogMessage(uint64_t timestamp_nanos) {
: SEC_TO_NANOS(kGyroscopeMessagePlan.rapid_message_interval_sec);
const bool print_gyro_log = NANO_TIMER_CHECK_T1_GEQUAL_T2_PLUS_DELTA(
- timestamp_nanos, gyro_notification_time_nanos_,
- next_log_interval_nanos);
+ timestamp_nanos, gyro_notification_time_nanos_, next_log_interval_nanos);
if (print_gyro_log) {
gyro_notification_time_nanos_ = timestamp_nanos;
PrintCalibration(gyro_cal_->GetSensorCalibration(), gyro_cal_update_flags_,
kGyroTag);
}
+
+ return print_gyro_log;
}
} // namespace nano_calibration