Make zeroing constants structs flatbuffers
This defines all the zeroing structs as flatbuffers and then converts
everything to use the FlatbufferT types.
This is in service of moving zeroing constants into flatbuffers.
Change-Id: Ied7ac78cfcba0f66b4b684fd9e49a49276e55169
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/frc971/BUILD b/frc971/BUILD
index a861316..dd1b367 100644
--- a/frc971/BUILD
+++ b/frc971/BUILD
@@ -17,6 +17,10 @@
"constants.h",
],
target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ "//frc971/control_loops:control_loops_fbs",
+ "//frc971/zeroing:constants_fbs",
+ ],
)
py_library(
diff --git a/frc971/constants.h b/frc971/constants.h
index cf53287..0367937 100644
--- a/frc971/constants.h
+++ b/frc971/constants.h
@@ -3,142 +3,34 @@
#include <cstddef>
+#include "frc971/control_loops/control_loops_generated.h"
+#include "frc971/zeroing/constants_generated.h"
+
namespace frc971 {
namespace constants {
-struct HallEffectZeroingConstants {
- // The absolute position of the lower edge of the hall effect sensor.
- double lower_hall_position;
- // The absolute position of the upper edge of the hall effect sensor.
- double upper_hall_position;
- // The difference in scaled units between two hall effect edges. This is the
- // number of units/cycle.
- double index_difference;
- // Number of cycles we need to see the hall effect high.
- size_t hall_trigger_zeroing_length;
- // Direction the system must be moving in order to zero. True is positive,
- // False is negative direction.
- bool zeroing_move_direction;
-};
+typedef frc971::zeroing::HallEffectZeroingConstantsT HallEffectZeroingConstants;
-struct PotAndIndexPulseZeroingConstants {
- // The number of samples in the moving average filter.
- size_t average_filter_size;
- // The difference in scaled units between two index pulses.
- double index_difference;
- // The absolute position in scaled units of one of the index pulses.
- double measured_index_position;
- // Value between 0 and .5 which determines a fraction of the index_diff
- // you want to use.
- double allowable_encoder_error;
-};
+typedef frc971::zeroing::PotAndIndexPulseZeroingConstantsT
+ PotAndIndexPulseZeroingConstants;
-struct EncoderPlusIndexZeroingConstants {
- // The amount of index pulses in the joint's range of motion.
- int index_pulse_count;
- // The difference in scaled units between two index pulses.
- double index_difference;
- // The absolute position in scaled units of one of the index pulses.
- double measured_index_position;
- // The index pulse that is known, going from lowest in the range of motion to
- // highest (Starting at 0).
- int known_index_pulse;
- // Value between 0 and 0.5 which determines a fraction of the index_diff
- // you want to use. If an index pulse deviates by more than this amount from
- // where we expect to see one then we flag an error.
- double allowable_encoder_error;
-};
+typedef frc971::zeroing::EncoderPlusIndexZeroingConstantsT
+ EncoderPlusIndexZeroingConstants;
-struct PotAndAbsoluteEncoderZeroingConstants {
- // The number of samples in the moving average filter.
- size_t average_filter_size;
- // The distance that the absolute encoder needs to complete a full rotation.
- double one_revolution_distance;
- // Measured absolute position of the encoder when at zero.
- double measured_absolute_position;
+typedef frc971::zeroing::PotAndAbsoluteEncoderZeroingConstantsT
+ PotAndAbsoluteEncoderZeroingConstants;
- // Treshold for deciding if we are moving. moving_buffer_size samples need to
- // be within this distance of each other before we use the middle one to zero.
- double zeroing_threshold;
- // Buffer size for deciding if we are moving.
- size_t moving_buffer_size;
+typedef frc971::zeroing::RelativeEncoderZeroingConstantsT
+ RelativeEncoderZeroingConstants;
- // Value between 0 and 1 indicating what fraction of one_revolution_distance
- // it is acceptable for the offset to move.
- double allowable_encoder_error;
-};
+typedef frc971::zeroing::ContinuousAbsoluteEncoderZeroingConstantsT
+ ContinuousAbsoluteEncoderZeroingConstants;
-struct RelativeEncoderZeroingConstants {};
+typedef frc971::zeroing::AbsoluteEncoderZeroingConstantsT
+ AbsoluteEncoderZeroingConstants;
-struct ContinuousAbsoluteEncoderZeroingConstants {
- // The number of samples in the moving average filter.
- size_t average_filter_size;
- // The distance that the absolute encoder needs to complete a full rotation.
- // It is presumed that this will always be 2 * pi for any subsystem using this
- // class, unless you have a continuous system that for some reason doesn't
- // have a logical period of 1 revolution in radians.
- double one_revolution_distance;
- // Measured absolute position of the encoder when at zero.
- double measured_absolute_position;
-
- // Threshold for deciding if we are moving. moving_buffer_size samples need to
- // be within this distance of each other before we use the middle one to zero.
- double zeroing_threshold;
- // Buffer size for deciding if we are moving.
- size_t moving_buffer_size;
-
- // Value between 0 and 1 indicating what fraction of a revolution
- // it is acceptable for the offset to move.
- double allowable_encoder_error;
-};
-
-struct AbsoluteEncoderZeroingConstants {
- // The number of samples in the moving average filter.
- size_t average_filter_size;
- // The distance that the absolute encoder needs to complete a full rotation.
- double one_revolution_distance;
- // Measured absolute position of the encoder when at zero.
- double measured_absolute_position;
- // Position of the middle of the range of motion in output coordinates.
- double middle_position;
-
- // Threshold for deciding if we are moving. moving_buffer_size samples need to
- // be within this distance of each other before we use the middle one to zero.
- double zeroing_threshold;
- // Buffer size for deciding if we are moving.
- size_t moving_buffer_size;
-
- // Value between 0 and 1 indicating what fraction of one_revolution_distance
- // it is acceptable for the offset to move.
- double allowable_encoder_error;
-};
-
-struct AbsoluteAndAbsoluteEncoderZeroingConstants {
- // The number of samples in the moving average filter.
- size_t average_filter_size;
- // The distance that the absolute encoder needs to complete a full rotation.
- double one_revolution_distance;
- // Measured absolute position of the encoder when at zero.
- double measured_absolute_position;
-
- // The distance that the single turn absolute encoder needs to complete a full
- // rotation.
- double single_turn_one_revolution_distance;
- // Measured absolute position of the single turn encoder when at zero.
- double single_turn_measured_absolute_position;
- // Position of the middle of the range of motion in output coordinates.
- double single_turn_middle_position;
-
- // Threshold for deciding if we are moving. moving_buffer_size samples need to
- // be within this distance of each other before we use the middle one to zero.
- double zeroing_threshold;
- // Buffer size for deciding if we are moving.
- size_t moving_buffer_size;
-
- // Value between 0 and 1 indicating what fraction of one_revolution_distance
- // it is acceptable for the offset to move.
- double allowable_encoder_error;
-};
+typedef frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingConstantsT
+ AbsoluteAndAbsoluteEncoderZeroingConstants;
// Defines a range of motion for a subsystem.
// These are all absolute positions in scaled units.
@@ -152,6 +44,13 @@
constexpr double middle_soft() const { return (lower + upper) / 2.0; }
constexpr double range() const { return upper_hard - lower_hard; }
+
+ static Range FromFlatbuffer(const frc971::Range *range) {
+ return {.lower_hard = range->lower_hard(),
+ .upper_hard = range->upper_hard(),
+ .lower = range->lower(),
+ .upper = range->upper()};
+ }
};
} // namespace constants
diff --git a/frc971/control_loops/control_loops.fbs b/frc971/control_loops/control_loops.fbs
index da2dc05..db2695e 100644
--- a/frc971/control_loops/control_loops.fbs
+++ b/frc971/control_loops/control_loops.fbs
@@ -256,6 +256,13 @@
max_acceleration:float (id: 1);
}
+table Range {
+ lower_hard:double (id: 0);
+ upper_hard:double (id: 1);
+ lower:double (id: 2);
+ upper:double (id: 3);
+}
+
enum ConstraintType : byte {
CONSTRAINT_TYPE_UNDEFINED,
LONGITUDINAL_ACCELERATION,
diff --git a/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc b/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc
index ace528e..f9dfd8d 100644
--- a/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc
+++ b/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc
@@ -83,13 +83,14 @@
const frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator::ZeroingConstants
TestIntakeSystemValues<
frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>::kZeroing{
- kZeroingSampleSize, kEncoderIndexDifference, 0, 0.0005, 20, 1.9};
+ {}, kZeroingSampleSize, kEncoderIndexDifference, 0, 0.0005, 20, 1.9};
template <>
const frc971::zeroing::AbsoluteEncoderZeroingEstimator::ZeroingConstants
TestIntakeSystemValues<
frc971::zeroing::AbsoluteEncoderZeroingEstimator>::kZeroing{
- kZeroingSampleSize, kEncoderIndexDifference, 0.0, 0.2, 0.0005, 20, 1.9};
+ {}, kZeroingSampleSize, kEncoderIndexDifference, 0.0, 0.2, 0.0005, 20,
+ 1.9};
template <typename ZeroingEstimator>
const StaticZeroingSingleDOFProfiledSubsystemParams<ZeroingEstimator>
diff --git a/frc971/zeroing/BUILD b/frc971/zeroing/BUILD
index 8ca7f67..81ed998 100644
--- a/frc971/zeroing/BUILD
+++ b/frc971/zeroing/BUILD
@@ -1,5 +1,12 @@
+load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
+
package(default_visibility = ["//visibility:public"])
+static_flatbuffer(
+ name = "constants_fbs",
+ srcs = ["constants.fbs"],
+)
+
cc_library(
name = "averager",
hdrs = [
diff --git a/frc971/zeroing/absolute_and_absolute_encoder_test.cc b/frc971/zeroing/absolute_and_absolute_encoder_test.cc
index b28f637..5dac38b 100644
--- a/frc971/zeroing/absolute_and_absolute_encoder_test.cc
+++ b/frc971/zeroing/absolute_and_absolute_encoder_test.cc
@@ -42,6 +42,7 @@
0.4 * single_turn_distance_per_revolution;
AbsoluteAndAbsoluteEncoderZeroingConstants constants{
+ {},
kSampleSize,
distance_per_revolution,
measured_absolute_position,
@@ -89,6 +90,7 @@
0.4 * single_turn_distance_per_revolution;
AbsoluteAndAbsoluteEncoderZeroingConstants constants{
+ {},
kSampleSize,
distance_per_revolution,
measured_absolute_position,
@@ -144,6 +146,7 @@
0.4 * single_turn_distance_per_revolution;
AbsoluteAndAbsoluteEncoderZeroingConstants constants{
+ {},
kSampleSize,
distance_per_revolution,
measured_absolute_position,
@@ -175,9 +178,16 @@
// Makes sure we detect an error if the ZeroingEstimator gets sent a NaN.
TEST_F(AbsoluteAndAbsoluteEncoderZeroingTest,
TestAbsoluteAndAbsoluteEncoderZeroingWithNaN) {
- AbsoluteAndAbsoluteEncoderZeroingConstants constants{
- kSampleSize, 1, 0.3, 1, 0.3, 2.5, 0.1, kMovingBufferSize,
- kIndexErrorFraction};
+ AbsoluteAndAbsoluteEncoderZeroingConstants constants{{},
+ kSampleSize,
+ 1,
+ 0.3,
+ 1,
+ 0.3,
+ 2.5,
+ 0.1,
+ kMovingBufferSize,
+ kIndexErrorFraction};
AbsoluteAndAbsoluteEncoderZeroingEstimator estimator(constants);
@@ -215,6 +225,7 @@
0.4 * single_turn_distance_per_revolution;
AbsoluteAndAbsoluteEncoderZeroingConstants constants{
+ {},
kSampleSize,
distance_per_revolution,
measured_absolute_position,
@@ -276,6 +287,7 @@
0.4 * single_turn_distance_per_revolution;
AbsoluteAndAbsoluteEncoderZeroingConstants constants{
+ {},
kSampleSize,
distance_per_revolution,
measured_absolute_position,
diff --git a/frc971/zeroing/absolute_encoder_test.cc b/frc971/zeroing/absolute_encoder_test.cc
index fdc1fa0..6e78faa 100644
--- a/frc971/zeroing/absolute_encoder_test.cc
+++ b/frc971/zeroing/absolute_encoder_test.cc
@@ -31,10 +31,14 @@
const double start_pos = 2.1;
double measured_absolute_position = 0.3 * index_diff;
- AbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- kMiddlePosition, 0.1, kMovingBufferSize,
- kIndexErrorFraction};
+ AbsoluteEncoderZeroingConstants constants{{},
+ kSampleSize,
+ index_diff,
+ measured_absolute_position,
+ kMiddlePosition,
+ 0.1,
+ kMovingBufferSize,
+ kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -61,10 +65,14 @@
double measured_absolute_position = 0.3 * index_diff;
const double kMiddlePosition = 2.5;
- AbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- kMiddlePosition, 0.1, kMovingBufferSize,
- kIndexErrorFraction};
+ AbsoluteEncoderZeroingConstants constants{{},
+ kSampleSize,
+ index_diff,
+ measured_absolute_position,
+ kMiddlePosition,
+ 0.1,
+ kMovingBufferSize,
+ kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -100,10 +108,14 @@
double measured_absolute_position = 0.3 * index_diff;
const double kMiddlePosition = 2.5;
- AbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- kMiddlePosition, 0.1, kMovingBufferSize,
- kIndexErrorFraction};
+ AbsoluteEncoderZeroingConstants constants{{},
+ kSampleSize,
+ index_diff,
+ measured_absolute_position,
+ kMiddlePosition,
+ 0.1,
+ kMovingBufferSize,
+ kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -122,8 +134,14 @@
// Makes sure we detect an error if the ZeroingEstimator gets sent a NaN.
TEST_F(AbsoluteEncoderZeroingTest, TestAbsoluteEncoderZeroingWithNaN) {
- AbsoluteEncoderZeroingConstants constants{
- kSampleSize, 1, 0.3, 1.0, 0.1, kMovingBufferSize, kIndexErrorFraction};
+ AbsoluteEncoderZeroingConstants constants{{},
+ kSampleSize,
+ 1,
+ 0.3,
+ 1.0,
+ 0.1,
+ kMovingBufferSize,
+ kIndexErrorFraction};
AbsoluteEncoderZeroingEstimator estimator(constants);
diff --git a/frc971/zeroing/constants.fbs b/frc971/zeroing/constants.fbs
new file mode 100644
index 0000000..63e9136
--- /dev/null
+++ b/frc971/zeroing/constants.fbs
@@ -0,0 +1,135 @@
+namespace frc971.zeroing;
+
+table HallEffectZeroingConstants {
+ // The absolute position of the lower edge of the hall effect sensor.
+ lower_hall_position:double (id: 0);
+ // The absolute position of the upper edge of the hall effect sensor.
+ upper_hall_position:double (id: 1);
+ // The difference in scaled units between two hall effect edges. This is the
+ // number of units/cycle.
+ index_difference:double (id: 2);
+ // Number of cycles we need to see the hall effect high.
+ hall_trigger_zeroing_length:uint64 (id: 3);
+ // Direction the system must be moving in order to zero. True is positive,
+ // False is negative direction.
+ zeroing_move_direction:bool (id: 4);
+}
+
+table PotAndIndexPulseZeroingConstants {
+ // The number of samples in the moving average filter.
+ average_filter_size:uint64 (id: 0);
+ // The difference in scaled units between two index pulses.
+ index_difference:double (id: 1);
+ // The absolute position in scaled units of one of the index pulses.
+ measured_index_position:double (id: 2);
+ // Value between 0 and .5 which determines a fraction of the index_diff
+ // you want to use.
+ allowable_encoder_error:double (id: 3);
+}
+
+table EncoderPlusIndexZeroingConstants {
+ // The amount of index pulses in the joint's range of motion.
+ index_pulse_count:int (id: 0);
+ // The difference in scaled units between two index pulses.
+ index_difference:double (id: 1);
+ // The absolute position in scaled units of one of the index pulses.
+ measured_index_position:double (id: 2);
+ // The index pulse that is known, going from lowest in the range of motion to
+ // highest (Starting at 0).
+ known_index_pulse:int (id: 3);
+ // Value between 0 and 0.5 which determines a fraction of the index_diff
+ // you want to use. If an index pulse deviates by more than this amount from
+ // where we expect to see one then we flag an error.
+ allowable_encoder_error:double (id: 4);
+}
+
+table PotAndAbsoluteEncoderZeroingConstants {
+ // The number of samples in the moving average filter.
+ average_filter_size:uint64 (id: 0);
+ // The distance that the absolute encoder needs to complete a full rotation.
+ one_revolution_distance:double (id: 1);
+ // Measured absolute position of the encoder when at zero.
+ measured_absolute_position:double (id: 2);
+
+ // Treshold for deciding if we are moving. moving_buffer_size samples need to
+ // be within this distance of each other before we use the middle one to zero.
+ zeroing_threshold:double (id: 3);
+ // Buffer size for deciding if we are moving.
+ moving_buffer_size:uint64 (id: 4);
+
+ // Value between 0 and 1 indicating what fraction of one_revolution_distance
+ // it is acceptable for the offset to move.
+ allowable_encoder_error:double (id: 5);
+}
+
+table RelativeEncoderZeroingConstants {}
+
+table ContinuousAbsoluteEncoderZeroingConstants {
+ // The number of samples in the moving average filter.
+ average_filter_size:uint64 (id: 0);
+ // The distance that the absolute encoder needs to complete a full rotation.
+ // It is presumed that this will always be 2 * pi for any subsystem using this
+ // class, unless you have a continuous system that for some reason doesn't
+ // have a logical period of 1 revolution in radians.
+ one_revolution_distance:double (id: 1);
+ // Measured absolute position of the encoder when at zero.
+ measured_absolute_position:double (id: 2);
+
+ // Threshold for deciding if we are moving. moving_buffer_size samples need to
+ // be within this distance of each other before we use the middle one to zero.
+ zeroing_threshold:double (id: 3);
+ // Buffer size for deciding if we are moving.
+ moving_buffer_size:uint64 (id: 4);
+
+ // Value between 0 and 1 indicating what fraction of a revolution
+ // it is acceptable for the offset to move.
+ allowable_encoder_error:double (id: 5);
+}
+
+table AbsoluteEncoderZeroingConstants {
+ // The number of samples in the moving average filter.
+ average_filter_size:uint64 (id: 0);
+ // The distance that the absolute encoder needs to complete a full rotation.
+ one_revolution_distance:double (id: 1);
+ // Measured absolute position of the encoder when at zero.
+ measured_absolute_position:double (id: 2);
+ // Position of the middle of the range of motion in output coordinates.
+ middle_position:double (id: 3);
+
+ // Threshold for deciding if we are moving. moving_buffer_size samples need to
+ // be within this distance of each other before we use the middle one to zero.
+ zeroing_threshold:double (id: 4);
+ // Buffer size for deciding if we are moving.
+ moving_buffer_size:uint64 (id: 5);
+
+ // Value between 0 and 1 indicating what fraction of one_revolution_distance
+ // it is acceptable for the offset to move.
+ allowable_encoder_error:double (id: 6);
+}
+
+table AbsoluteAndAbsoluteEncoderZeroingConstants {
+ // The number of samples in the moving average filter.
+ average_filter_size:uint64 (id: 0);
+ // The distance that the absolute encoder needs to complete a full rotation.
+ one_revolution_distance:double (id: 1);
+ // Measured absolute position of the encoder when at zero.
+ measured_absolute_position:double (id: 2);
+
+ // The distance that the single turn absolute encoder needs to complete a full
+ // rotation.
+ single_turn_one_revolution_distance:double (id: 3);
+ // Measured absolute position of the single turn encoder when at zero.
+ single_turn_measured_absolute_position:double (id: 4);
+ // Position of the middle of the range of motion in output coordinates.
+ single_turn_middle_position:double (id: 5);
+
+ // Threshold for deciding if we are moving. moving_buffer_size samples need to
+ // be within this distance of each other before we use the middle one to zero.
+ zeroing_threshold:double (id: 6);
+ // Buffer size for deciding if we are moving.
+ moving_buffer_size:uint64 (id: 7);
+
+ // Value between 0 and 1 indicating what fraction of one_revolution_distance
+ // it is acceptable for the offset to move.
+ allowable_encoder_error:double (id: 8);
+}
diff --git a/frc971/zeroing/continuous_absolute_encoder_test.cc b/frc971/zeroing/continuous_absolute_encoder_test.cc
index 3869393..75d6de0 100644
--- a/frc971/zeroing/continuous_absolute_encoder_test.cc
+++ b/frc971/zeroing/continuous_absolute_encoder_test.cc
@@ -34,8 +34,8 @@
double measured_absolute_position = 0.3 * index_diff;
ContinuousAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -65,8 +65,8 @@
double measured_absolute_position = 0.3 * index_diff;
ContinuousAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -103,8 +103,8 @@
double measured_absolute_position = 0.3 * index_diff;
ContinuousAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -143,8 +143,8 @@
double measured_absolute_position = 0.3 * index_diff;
ContinuousAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -165,7 +165,7 @@
TEST_F(ContinuousAbsoluteEncoderZeroingTest,
TestContinuousAbsoluteEncoderZeroingWithNaN) {
ContinuousAbsoluteEncoderZeroingConstants constants{
- kSampleSize, 1, 0.3, 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, 1, 0.3, 0.1, kMovingBufferSize, kIndexErrorFraction};
ContinuousAbsoluteEncoderZeroingEstimator estimator(constants);
diff --git a/frc971/zeroing/pot_and_absolute_encoder_test.cc b/frc971/zeroing/pot_and_absolute_encoder_test.cc
index 5c05cc1..4cd3821 100644
--- a/frc971/zeroing/pot_and_absolute_encoder_test.cc
+++ b/frc971/zeroing/pot_and_absolute_encoder_test.cc
@@ -33,8 +33,8 @@
double measured_absolute_position = 0.3 * index_diff;
PotAndAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -62,8 +62,8 @@
double measured_absolute_position = 0.3 * index_diff;
PotAndAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -99,8 +99,8 @@
double measured_absolute_position = 0.3 * index_diff;
PotAndAbsoluteEncoderZeroingConstants constants{
- kSampleSize, index_diff, measured_absolute_position,
- 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, index_diff, measured_absolute_position,
+ 0.1, kMovingBufferSize, kIndexErrorFraction};
sim.Initialize(start_pos, index_diff / 3.0, 0.0,
constants.measured_absolute_position);
@@ -121,7 +121,7 @@
TEST_F(PotAndAbsoluteEncoderZeroingTest,
TestPotAndAbsoluteEncoderZeroingWithNaN) {
PotAndAbsoluteEncoderZeroingConstants constants{
- kSampleSize, 1, 0.3, 0.1, kMovingBufferSize, kIndexErrorFraction};
+ {}, kSampleSize, 1, 0.3, 0.1, kMovingBufferSize, kIndexErrorFraction};
PotAndAbsoluteEncoderZeroingEstimator estimator(constants);
diff --git a/frc971/zeroing/pot_and_index_test.cc b/frc971/zeroing/pot_and_index_test.cc
index b2b00ce..f2e464f 100644
--- a/frc971/zeroing/pot_and_index_test.cc
+++ b/frc971/zeroing/pot_and_index_test.cc
@@ -27,7 +27,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.6 * index_diff, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// The zeroing code is supposed to perform some filtering on the difference
// between the potentiometer value and the encoder value. We assume that 300
@@ -51,7 +51,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(position, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// Make sure that the zeroing code does not consider itself zeroed until we
// collect a good amount of samples. In this case we're waiting until the
@@ -70,7 +70,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.6, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// The zeroing code is supposed to perform some filtering on the difference
// between the potentiometer value and the encoder value. We assume that 300
@@ -104,7 +104,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.5 * index_diff, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// The zeroing code is supposed to perform some filtering on the difference
// between the potentiometer value and the encoder value. We assume that 300
@@ -138,7 +138,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.5 * index_diff, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
for (unsigned int i = 0; i < kSampleSize / 2; i++) {
MoveTo(&sim, &estimator, 3.5 * index_diff);
@@ -158,7 +158,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.1 * index_diff, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
MoveTo(&sim, &estimator, 3.1 * index_diff);
@@ -174,7 +174,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.1 * index_diff, index_diff / 3.0);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
// Make sure to fill up the averaging filter with samples.
for (unsigned int i = 0; i < kSampleSize; i++) {
@@ -209,7 +209,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(3.3 * index_diff, index_diff / 3.0, known_index_pos);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, known_index_pos, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, known_index_pos, kIndexErrorFraction});
// Make sure to fill up the averaging filter with samples.
for (unsigned int i = 0; i < kSampleSize; i++) {
@@ -234,7 +234,7 @@
TEST_F(PotAndIndexZeroingTest, BasicErrorAPITest) {
const double index_diff = 1.0;
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- kSampleSize, index_diff, 0.0, kIndexErrorFraction});
+ {}, kSampleSize, index_diff, 0.0, kIndexErrorFraction});
PositionSensorSimulator sim(index_diff);
sim.Initialize(1.5 * index_diff, index_diff / 3.0, 0.0);
@@ -262,7 +262,7 @@
PositionSensorSimulator sim(index_diff);
sim.Initialize(10 * index_diff, index_diff / 3.0, known_index_pos);
PotAndIndexPulseZeroingEstimator estimator(PotAndIndexPulseZeroingConstants{
- sample_size, index_diff, known_index_pos, kIndexErrorFraction});
+ {}, sample_size, index_diff, known_index_pos, kIndexErrorFraction});
for (size_t i = 0; i < sample_size; i++) {
MoveTo(&sim, &estimator, 13 * index_diff);
diff --git a/y2016/constants.cc b/y2016/constants.cc
index 9284bea..707fa9c 100644
--- a/y2016/constants.cc
+++ b/y2016/constants.cc
@@ -52,22 +52,31 @@
// Intake
{
0.0,
- {Values::kZeroingSampleSize,
- Values::kIntakeEncoderIndexDifference, 0.0, 0.3},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kIntakeEncoderIndexDifference,
+ 0.0,
+ 0.3},
},
// Shoulder
{
0.0,
- {Values::kZeroingSampleSize,
- Values::kShoulderEncoderIndexDifference, 0.0, 0.3},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kShoulderEncoderIndexDifference,
+ 0.0,
+ 0.3},
},
// Wrist
{
0.0,
- {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
- 0.0, 0.3},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kWristEncoderIndexDifference,
+ 0.0,
+ 0.3},
},
0.0,
@@ -84,18 +93,23 @@
// Value to add to the pot reading for the intake.
-4.550531 + 150.40906362 * M_PI / 180.0 + 0.5098 - 0.0178 -
0.0725,
- {Values::kZeroingSampleSize,
+ {{},
+ Values::kZeroingSampleSize,
Values::kIntakeEncoderIndexDifference,
// Location of an index pulse.
- 0.018008, 2.5},
+ 0.018008,
+ 2.5},
},
// Shoulder
{
// Value to add to the pot reading for the shoulder.
-2.86275657117,
- {Values::kZeroingSampleSize,
- Values::kShoulderEncoderIndexDifference, 0.097312, 2.5},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kShoulderEncoderIndexDifference,
+ 0.097312,
+ 2.5},
},
// Wrist
@@ -104,8 +118,11 @@
3.2390714288298668 + -0.06138835 * M_PI / 180.0 + 0.0078 -
0.0548 - 0.0167 + 0.002 - 0.0026 - 0.1040 - 0.0035 - 0.0012 +
0.0166 - 0.017 + 0.148 + 0.004 + 0.024701 - 0.0741,
- {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
- 0.000820, 2.5},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kWristEncoderIndexDifference,
+ 0.000820,
+ 2.5},
},
0.0,
@@ -121,16 +138,22 @@
// Hard stop is 160.0185751389329 degrees.
-4.2193 + (160.0185751389329 * M_PI / 180.0 + 0.02 - 0.0235) +
0.0549 - 0.104 + 0.019 - 0.938 + 0.660 - 0.002 - 0.2081,
- {Values::kZeroingSampleSize,
- Values::kIntakeEncoderIndexDifference, 0.332370, 1.3},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kIntakeEncoderIndexDifference,
+ 0.332370,
+ 1.3},
},
// Shoulder (Now calibrated at 0)
{
-1.0016 - 0.0841 + 0.06138835 * M_PI / 180.0 + 1.07838 - 1.0441 +
0.0034 + 0.0065 - 0.0505,
- {Values::kZeroingSampleSize,
- Values::kShoulderEncoderIndexDifference, 0.027180, 1.3},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kShoulderEncoderIndexDifference,
+ 0.027180,
+ 1.3},
},
// Wrist
@@ -138,8 +161,11 @@
3.326328571170133 - 0.06138835 * M_PI / 180.0 - 0.177 + 0.0323 -
0.023 + 0.0488 + 0.0120 - 0.0005 - 0.0784 - 0.0010 - 0.080 +
0.1245,
- {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
- -0.263227, 1.3},
+ {{},
+ Values::kZeroingSampleSize,
+ Values::kWristEncoderIndexDifference,
+ -0.263227,
+ 1.3},
},
0.011,