Use ErrorList in estimators
Support it in both the abs + abs, and pot + abs and just abs.
Change-Id: I1c11d5d1fdc3d644f9d391bde7c06b6c6e8ec57d
Signed-off-by: Ravago Jones <ravagojones@gmail.com>
diff --git a/frc971/zeroing/pot_and_absolute_encoder.cc b/frc971/zeroing/pot_and_absolute_encoder.cc
index 200f399..32c4f60 100644
--- a/frc971/zeroing/pot_and_absolute_encoder.cc
+++ b/frc971/zeroing/pot_and_absolute_encoder.cc
@@ -3,9 +3,9 @@
#include <cmath>
#include <numeric>
-#include "glog/logging.h"
-
+#include "aos/containers/error_list.h"
#include "frc971/zeroing/wrap.h"
+#include "glog/logging.h"
namespace frc971 {
namespace zeroing {
@@ -57,11 +57,13 @@
if (::std::isnan(info.absolute_encoder())) {
if (zeroed_) {
VLOG(1) << "NAN on absolute encoder.";
+ errors_.Set(ZeroingError::LOST_ABSOLUTE_ENCODER);
error_ = true;
} else {
++nan_samples_;
- VLOG(1) << "NAN on absolute encoder while zeroing" << nan_samples_;
+ VLOG(1) << "NAN on absolute encoder while zeroing " << nan_samples_;
if (nan_samples_ >= constants_.average_filter_size) {
+ errors_.Set(ZeroingError::LOST_ABSOLUTE_ENCODER);
error_ = true;
zeroed_ = true;
}
@@ -168,6 +170,7 @@
<< ", current " << offset_ << ", allowable change: "
<< constants_.allowable_encoder_error *
constants_.one_revolution_distance;
+ errors_.Set(ZeroingError::OFFSET_MOVED_TOO_FAR);
error_ = true;
}
@@ -183,12 +186,16 @@
flatbuffers::Offset<PotAndAbsoluteEncoderZeroingEstimator::State>
PotAndAbsoluteEncoderZeroingEstimator::GetEstimatorState(
flatbuffers::FlatBufferBuilder *fbb) const {
+ flatbuffers::Offset<flatbuffers::Vector<ZeroingError>> errors_offset =
+ errors_.ToFlatbuffer(fbb);
+
State::Builder builder(*fbb);
builder.add_error(error_);
builder.add_zeroed(zeroed_);
builder.add_position(position_);
builder.add_pot_position(filtered_position_);
builder.add_absolute_position(filtered_absolute_encoder_);
+ builder.add_errors(errors_offset);
return builder.Finish();
}