Renamed ZeroingEstimator to PotAndIndexPulseZeroingEstimator
Renamed to allow for creating a new interface named ZeroingEstimator
in the future.
Change-Id: I374808cdc39dd4141ea67c81de69bbac98326648
diff --git a/frc971/constants.h b/frc971/constants.h
index 0da9c96..fbf7b1c 100644
--- a/frc971/constants.h
+++ b/frc971/constants.h
@@ -4,7 +4,7 @@
namespace frc971 {
namespace constants {
-struct ZeroingConstants {
+struct PotAndIndexPulseZeroingConstants {
// The number of samples in the moving average filter.
int average_filter_size;
// The difference in scaled units between two index pulses.
diff --git a/frc971/control_loops/profiled_subsystem.cc b/frc971/control_loops/profiled_subsystem.cc
index 1f1a76b..5a5d79d 100644
--- a/frc971/control_loops/profiled_subsystem.cc
+++ b/frc971/control_loops/profiled_subsystem.cc
@@ -15,7 +15,8 @@
SingleDOFProfiledSubsystem::SingleDOFProfiledSubsystem(
::std::unique_ptr<SimpleCappedStateFeedbackLoop<3, 1, 1>> loop,
- const ::frc971::constants::ZeroingConstants &zeroing_constants,
+ const ::frc971::constants::PotAndIndexPulseZeroingConstants &
+ zeroing_constants,
const ::frc971::constants::Range &range, double default_velocity,
double default_acceleration)
: ProfiledSubsystem(::std::move(loop), {{zeroing_constants}}),
diff --git a/frc971/control_loops/profiled_subsystem.h b/frc971/control_loops/profiled_subsystem.h
index 342fb83..5e443dc 100644
--- a/frc971/control_loops/profiled_subsystem.h
+++ b/frc971/control_loops/profiled_subsystem.h
@@ -21,10 +21,9 @@
public:
ProfiledSubsystem(
::std::unique_ptr<::frc971::control_loops::SimpleCappedStateFeedbackLoop<
- number_of_states, number_of_axes, number_of_axes>>
- loop,
- ::std::array<::frc971::zeroing::ZeroingEstimator, number_of_axes>
- &&estimators)
+ number_of_states, number_of_axes, number_of_axes>> loop,
+ ::std::array<::frc971::zeroing::PotAndIndexPulseZeroingEstimator,
+ number_of_axes> &&estimators)
: loop_(::std::move(loop)), estimators_(::std::move(estimators)) {
zeroed_.fill(false);
unprofiled_goal_.setZero();
@@ -48,8 +47,8 @@
}
// Returns the controller.
- const StateFeedbackLoop<number_of_states, number_of_axes, number_of_axes>
- &controller() const {
+ const StateFeedbackLoop<number_of_states, number_of_axes, number_of_axes> &
+ controller() const {
return *loop_;
}
@@ -111,15 +110,15 @@
// TODO(austin): It's a bold assumption to assume that we will have the same
// number of sensors as axes. So far, that's been fine.
::std::unique_ptr<::frc971::control_loops::SimpleCappedStateFeedbackLoop<
- number_of_states, number_of_axes, number_of_axes>>
- loop_;
+ number_of_states, number_of_axes, number_of_axes>> loop_;
// The goal that the profile tries to reach.
Eigen::Matrix<double, number_of_states, 1> unprofiled_goal_;
bool initialized_ = false;
- ::std::array<::frc971::zeroing::ZeroingEstimator, number_of_axes> estimators_;
+ ::std::array<::frc971::zeroing::PotAndIndexPulseZeroingEstimator,
+ number_of_axes> estimators_;
private:
::std::array<bool, number_of_axes> zeroed_;
@@ -130,7 +129,7 @@
public:
SingleDOFProfiledSubsystem(
::std::unique_ptr<SimpleCappedStateFeedbackLoop<3, 1, 1>> loop,
- const ::frc971::constants::ZeroingConstants &estimator,
+ const ::frc971::constants::PotAndIndexPulseZeroingConstants &estimator,
const ::frc971::constants::Range &range, double default_angular_velocity,
double default_angular_acceleration);
diff --git a/frc971/zeroing/zeroing.cc b/frc971/zeroing/zeroing.cc
index 4ff6391..69c4de6 100644
--- a/frc971/zeroing/zeroing.cc
+++ b/frc971/zeroing/zeroing.cc
@@ -6,16 +6,17 @@
namespace frc971 {
namespace zeroing {
-void PopulateEstimatorState(const zeroing::ZeroingEstimator& estimator,
- EstimatorState* state) {
+void PopulateEstimatorState(
+ const zeroing::PotAndIndexPulseZeroingEstimator &estimator,
+ EstimatorState *state) {
state->error = estimator.error();
state->zeroed = estimator.zeroed();
state->position = estimator.position();
state->pot_position = estimator.filtered_position();
}
-ZeroingEstimator::ZeroingEstimator(
- const constants::ZeroingConstants& constants) {
+PotAndIndexPulseZeroingEstimator::PotAndIndexPulseZeroingEstimator(
+ const constants::PotAndIndexPulseZeroingConstants &constants) {
index_diff_ = constants.index_difference;
max_sample_count_ = constants.average_filter_size;
known_index_pos_ = constants.measured_index_position;
@@ -24,7 +25,7 @@
Reset();
}
-void ZeroingEstimator::Reset() {
+void PotAndIndexPulseZeroingEstimator::Reset() {
samples_idx_ = 0;
start_pos_ = 0;
start_pos_samples_.clear();
@@ -35,15 +36,15 @@
error_ = false;
}
-void ZeroingEstimator::TriggerError() {
+void PotAndIndexPulseZeroingEstimator::TriggerError() {
if (!error_) {
LOG(ERROR, "Manually triggered zeroing error.\n");
error_ = true;
}
}
-double ZeroingEstimator::CalculateStartPosition(double start_average,
- double latched_encoder) const {
+double PotAndIndexPulseZeroingEstimator::CalculateStartPosition(
+ double start_average, double latched_encoder) const {
// We calculate an aproximation of the value of the last index position.
// Also account for index pulses not lining up with integer multiples of the
// index_diff.
@@ -54,7 +55,8 @@
return accurate_index_pos - latched_encoder + known_index_pos_;
}
-void ZeroingEstimator::UpdateEstimate(const PotAndIndexPosition& info) {
+void PotAndIndexPulseZeroingEstimator::UpdateEstimate(
+ const PotAndIndexPosition &info) {
// We want to make sure that we encounter at least one index pulse while
// zeroing. So we take the index pulse count from the first sample after
// reset and wait for that count to change before we consider ourselves
diff --git a/frc971/zeroing/zeroing.h b/frc971/zeroing/zeroing.h
index b5e2c14..c86ca01 100644
--- a/frc971/zeroing/zeroing.h
+++ b/frc971/zeroing/zeroing.h
@@ -21,9 +21,10 @@
// Estimates the position with encoder,
// the pot and the indices.
-class ZeroingEstimator {
+class PotAndIndexPulseZeroingEstimator {
public:
- ZeroingEstimator(const constants::ZeroingConstants &constants);
+ PotAndIndexPulseZeroingEstimator(
+ const constants::PotAndIndexPulseZeroingConstants &constants);
// Update the internal logic with the next sensor values.
void UpdateEstimate(const PotAndIndexPosition &info);
@@ -123,7 +124,7 @@
// Populates an EstimatorState struct with information from the zeroing
// estimator.
-void PopulateEstimatorState(const ZeroingEstimator &estimator,
+void PopulateEstimatorState(const PotAndIndexPulseZeroingEstimator &estimator,
EstimatorState *state);
} // namespace zeroing
diff --git a/frc971/zeroing/zeroing_test.cc b/frc971/zeroing/zeroing_test.cc
index 1134259..2f562aa 100644
--- a/frc971/zeroing/zeroing_test.cc
+++ b/frc971/zeroing/zeroing_test.cc
@@ -16,7 +16,7 @@
namespace zeroing {
using control_loops::PositionSensorSimulator;
-using constants::ZeroingConstants;
+using constants::PotAndIndexPulseZeroingConstants;
static const size_t kSampleSize = 30;
static const double kAcceptableUnzeroedError = 0.2;
@@ -26,7 +26,8 @@
protected:
void SetUp() override { aos::SetDieTestMode(true); }
- void MoveTo(PositionSensorSimulator* simulator, ZeroingEstimator* estimator,
+ void MoveTo(PositionSensorSimulator *simulator,
+ PotAndIndexPulseZeroingEstimator *estimator,
double new_position) {
PotAndIndexPosition sensor_values_;
simulator->MoveTo(new_position);
@@ -41,7 +42,7 @@
const double index_diff = 1.0;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.6 * index_diff, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// The zeroing code is supposed to perform some filtering on the difference
@@ -65,7 +66,7 @@
double position = 3.6 * index_diff;
PositionSensorSimulator sim(index_diff);
sim.Initialize(position, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// Make sure that the zeroing code does not consider itself zeroed until we
@@ -84,7 +85,7 @@
double index_diff = 1.0;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.6, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// The zeroing code is supposed to perform some filtering on the difference
@@ -117,7 +118,7 @@
double index_diff = 0.89;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.5 * index_diff, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// The zeroing code is supposed to perform some filtering on the difference
@@ -151,7 +152,7 @@
double index_diff = 0.89;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.5 * index_diff, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
for (unsigned int i = 0; i < kSampleSize / 2; i++) {
@@ -171,7 +172,7 @@
double index_diff = 0.89;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.1 * index_diff, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
MoveTo(&sim, &estimator, 3.1 * index_diff);
@@ -187,7 +188,7 @@
double index_diff = 0.6;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.1 * index_diff, index_diff / 3.0);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// Make sure to fill up the averaging filter with samples.
@@ -222,7 +223,7 @@
const double known_index_pos = 3.5 * index_diff;
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.3 * index_diff, index_diff / 3.0, known_index_pos);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, known_index_pos, kIndexErrorFraction});
// Make sure to fill up the averaging filter with samples.
@@ -247,7 +248,7 @@
TEST_F(ZeroingTest, BasicErrorAPITest) {
const double index_diff = 1.0;
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
kSampleSize, index_diff, 0.0, kIndexErrorFraction});
PositionSensorSimulator sim(index_diff);
sim.Initialize(1.5 * index_diff, index_diff / 3.0, 0.0);
@@ -283,7 +284,7 @@
int sample_size = 30;
PositionSensorSimulator sim(index_diff);
sim.Initialize(10 * index_diff, index_diff / 3.0, known_index_pos);
- ZeroingEstimator estimator(ZeroingConstants{
+ PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
sample_size, index_diff, known_index_pos, kIndexErrorFraction});
for (int i = 0; i < sample_size; i++) {
diff --git a/y2014/constants.h b/y2014/constants.h
index 4ad06bc..7fb2507 100644
--- a/y2014/constants.h
+++ b/y2014/constants.h
@@ -43,7 +43,7 @@
double drivetrain_max_speed;
- struct ZeroingConstants {
+ struct PotAndIndexPulseZeroingConstants {
// The number of samples in the moving average filter.
int average_filter_size;
// The difference in scaled units between two index pulses.
@@ -126,7 +126,7 @@
// should be larger than claw_shooting_separation so that we can shoot
// promptly.
double claw_separation_goal;
- };
+ };
ShooterAction shooter_action;
};
diff --git a/y2015/constants.h b/y2015/constants.h
index 8cefe7e..d60efac 100644
--- a/y2015/constants.h
+++ b/y2015/constants.h
@@ -69,7 +69,7 @@
struct Claw {
Range wrist;
- ::frc971::constants::ZeroingConstants zeroing;
+ ::frc971::constants::PotAndIndexPulseZeroingConstants zeroing;
// The value to add to potentiometer readings after they have been converted
// to radians so that the resulting value is 0 when the claw is at absolute
// 0 (horizontal straight out the front).
@@ -87,10 +87,10 @@
Range elevator;
Range arm;
- ::frc971::constants::ZeroingConstants left_elev_zeroing;
- ::frc971::constants::ZeroingConstants right_elev_zeroing;
- ::frc971::constants::ZeroingConstants left_arm_zeroing;
- ::frc971::constants::ZeroingConstants right_arm_zeroing;
+ ::frc971::constants::PotAndIndexPulseZeroingConstants left_elev_zeroing;
+ ::frc971::constants::PotAndIndexPulseZeroingConstants right_elev_zeroing;
+ ::frc971::constants::PotAndIndexPulseZeroingConstants left_arm_zeroing;
+ ::frc971::constants::PotAndIndexPulseZeroingConstants right_arm_zeroing;
// Values to add to scaled potentiometer readings so 0 lines up with the
// physical absolute 0.
diff --git a/y2015/control_loops/claw/claw.h b/y2015/control_loops/claw/claw.h
index 324f9f3..e7523eb 100644
--- a/y2015/control_loops/claw/claw.h
+++ b/y2015/control_loops/claw/claw.h
@@ -95,7 +95,7 @@
// Latest position from queue.
control_loops::ClawQueue::Position current_position_;
// Zeroing estimator for claw.
- ::frc971::zeroing::ZeroingEstimator claw_estimator_;
+ ::frc971::zeroing::PotAndIndexPulseZeroingEstimator claw_estimator_;
// The goal for the claw.
double claw_goal_ = 0.0;
diff --git a/y2015/control_loops/fridge/fridge.h b/y2015/control_loops/fridge/fridge.h
index ee64554..6152caf 100644
--- a/y2015/control_loops/fridge/fridge.h
+++ b/y2015/control_loops/fridge/fridge.h
@@ -22,7 +22,7 @@
class FridgeTest_SafeArmZeroing_Test;
} // namespace testing
-template<int S>
+template <int S>
class CappedStateFeedbackLoop : public StateFeedbackLoop<S, 2, 2> {
public:
CappedStateFeedbackLoop(StateFeedbackLoop<S, 2, 2> &&loop)
@@ -42,8 +42,7 @@
double max_voltage_;
};
-class Fridge
- : public aos::controls::ControlLoop<FridgeQueue> {
+class Fridge : public aos::controls::ControlLoop<FridgeQueue> {
public:
explicit Fridge(FridgeQueue *fridge_queue =
&::y2015::control_loops::fridge::fridge_queue);
@@ -128,10 +127,10 @@
::std::unique_ptr<CappedStateFeedbackLoop<5>> arm_loop_;
::std::unique_ptr<CappedStateFeedbackLoop<4>> elevator_loop_;
- ::frc971::zeroing::ZeroingEstimator left_arm_estimator_;
- ::frc971::zeroing::ZeroingEstimator right_arm_estimator_;
- ::frc971::zeroing::ZeroingEstimator left_elevator_estimator_;
- ::frc971::zeroing::ZeroingEstimator right_elevator_estimator_;
+ ::frc971::zeroing::PotAndIndexPulseZeroingEstimator left_arm_estimator_;
+ ::frc971::zeroing::PotAndIndexPulseZeroingEstimator right_arm_estimator_;
+ ::frc971::zeroing::PotAndIndexPulseZeroingEstimator left_elevator_estimator_;
+ ::frc971::zeroing::PotAndIndexPulseZeroingEstimator right_elevator_estimator_;
// Offsets from the encoder position to the absolute position. Add these to
// the encoder position to get the absolute position.
@@ -170,5 +169,4 @@
} // namespace control_loops
} // namespace y2015
-#endif // Y2015_CONTROL_LOOPS_FRIDGE_H_
-
+#endif // Y2015_CONTROL_LOOPS_FRIDGE_H_
diff --git a/y2016/constants.h b/y2016/constants.h
index a83456c..3cbb895 100644
--- a/y2016/constants.h
+++ b/y2016/constants.h
@@ -11,7 +11,7 @@
namespace constants {
using ::frc971::constants::ShifterHallEffect;
-using ::frc971::constants::ZeroingConstants;
+using ::frc971::constants::PotAndIndexPulseZeroingConstants;
// Has all of the numbers that change for both robots and makes it easy to
// retrieve the values for the current one.
@@ -83,19 +83,19 @@
struct Intake {
double pot_offset;
- ZeroingConstants zeroing;
+ PotAndIndexPulseZeroingConstants zeroing;
};
Intake intake;
struct Shoulder {
double pot_offset;
- ZeroingConstants zeroing;
+ PotAndIndexPulseZeroingConstants zeroing;
};
Shoulder shoulder;
struct Wrist {
double pot_offset;
- ZeroingConstants zeroing;
+ PotAndIndexPulseZeroingConstants zeroing;
};
Wrist wrist;
diff --git a/y2016_bot3/control_loops/intake/intake.cc b/y2016_bot3/control_loops/intake/intake.cc
index b50ccca..6fee1d2 100644
--- a/y2016_bot3/control_loops/intake/intake.cc
+++ b/y2016_bot3/control_loops/intake/intake.cc
@@ -11,7 +11,8 @@
namespace y2016_bot3 {
namespace constants {
constexpr double IntakeZero::pot_offset;
-constexpr ::frc971::constants::ZeroingConstants IntakeZero::zeroing;
+constexpr ::frc971::constants::PotAndIndexPulseZeroingConstants
+ IntakeZero::zeroing;
} // namespace constants
namespace control_loops {
diff --git a/y2016_bot3/control_loops/intake/intake.h b/y2016_bot3/control_loops/intake/intake.h
index fdde74b..c654591 100644
--- a/y2016_bot3/control_loops/intake/intake.h
+++ b/y2016_bot3/control_loops/intake/intake.h
@@ -39,9 +39,9 @@
struct IntakeZero {
static constexpr double pot_offset = 5.462409 + 0.333162;
- static constexpr ::frc971::constants::ZeroingConstants zeroing{
- kZeroingSampleSize, kIntakeEncoderIndexDifference, 0.148604 - 0.291240,
- 0.3};
+ static constexpr ::frc971::constants::PotAndIndexPulseZeroingConstants
+ zeroing{kZeroingSampleSize, kIntakeEncoderIndexDifference,
+ 0.148604 - 0.291240, 0.3};
};
} // namespace constants
namespace control_loops {
diff --git a/y2016_bot3/control_loops/intake/intake_controls.h b/y2016_bot3/control_loops/intake/intake_controls.h
index 0b2daa0..320d803 100644
--- a/y2016_bot3/control_loops/intake/intake_controls.h
+++ b/y2016_bot3/control_loops/intake/intake_controls.h
@@ -90,7 +90,7 @@
::std::unique_ptr<
::frc971::control_loops::SimpleCappedStateFeedbackLoop<3, 1, 1>> loop_;
- ::frc971::zeroing::ZeroingEstimator estimator_;
+ ::frc971::zeroing::PotAndIndexPulseZeroingEstimator estimator_;
aos::util::TrapezoidProfile profile_;
// Current measurement.