blob: 6188f016e856c6c6fb6aaddf730041ee61b67cff [file] [log] [blame]
Brian Silverman431500a2013-10-28 19:50:15 -07001#ifndef FRC971_CONSTANTS_H_
2#define FRC971_CONSTANTS_H_
Brian Silverman2c590c32013-11-04 18:08:54 -08003
Austin Schuh5f01f152017-02-11 21:34:08 -08004#include <cstddef>
5
brians343bc112013-02-10 01:53:46 +00006namespace frc971 {
7namespace constants {
8
Austin Schuh55934032017-03-11 12:45:27 -08009struct HallEffectZeroingConstants {
10 // The absolute position of the lower edge of the hall effect sensor.
11 double lower_hall_position;
12 // The absolute position of the upper edge of the hall effect sensor.
13 double upper_hall_position;
14 // The difference in scaled units between two hall effect edges. This is the
15 // number of units/cycle.
16 double index_difference;
17 // Number of cycles we need to see the hall effect high.
18 size_t hall_trigger_zeroing_length;
19 // Direction the system must be moving in order to zero. True is positive,
20 // False is negative direction.
21 bool zeroing_move_direction;
22};
23
Tyler Chatowf8f03112017-02-05 14:31:34 -080024struct PotAndIndexPulseZeroingConstants {
Brian Silvermanb691f5e2015-08-02 11:37:55 -070025 // The number of samples in the moving average filter.
Austin Schuh5f01f152017-02-11 21:34:08 -080026 size_t average_filter_size;
Brian Silvermanb691f5e2015-08-02 11:37:55 -070027 // The difference in scaled units between two index pulses.
28 double index_difference;
29 // The absolute position in scaled units of one of the index pulses.
30 double measured_index_position;
Philipp Schrader3f5b6182017-03-25 22:36:37 +000031 // Value between 0 and .5 which determines a fraction of the index_diff
Brian Silvermanb691f5e2015-08-02 11:37:55 -070032 // you want to use.
33 double allowable_encoder_error;
Brian Silverman431500a2013-10-28 19:50:15 -070034};
35
Tyler Chatow61f77972017-02-04 17:41:14 -080036struct EncoderPlusIndexZeroingConstants {
Isaac Wilcove0851ffd2017-02-16 04:13:14 +000037 // The amount of index pulses in the joint's range of motion.
38 int index_pulse_count;
39 // The difference in scaled units between two index pulses.
40 double index_difference;
41 // The absolute position in scaled units of one of the index pulses.
42 double measured_index_position;
43 // The index pulse that is known, going from lowest in the range of motion to
44 // highest (Starting at 0).
45 int known_index_pulse;
Philipp Schrader3f5b6182017-03-25 22:36:37 +000046 // Value between 0 and 0.5 which determines a fraction of the index_diff
47 // you want to use. If an index pulse deviates by more than this amount from
48 // where we expect to see one then we flag an error.
49 double allowable_encoder_error;
Tyler Chatow61f77972017-02-04 17:41:14 -080050};
51
52struct PotAndAbsoluteEncoderZeroingConstants {
Austin Schuh5f01f152017-02-11 21:34:08 -080053 // The number of samples in the moving average filter.
54 size_t average_filter_size;
Tyler Chatow61f77972017-02-04 17:41:14 -080055 // The distance that the absolute encoder needs to complete a full rotation.
Austin Schuh5f01f152017-02-11 21:34:08 -080056 double one_revolution_distance;
57 // Measured absolute position of the encoder when at zero.
58 double measured_absolute_position;
59
Brian Silvermana10d20a2017-02-19 14:28:53 -080060 // Treshold for deciding if we are moving. moving_buffer_size samples need to
61 // be within this distance of each other before we use the middle one to zero.
Austin Schuh5f01f152017-02-11 21:34:08 -080062 double zeroing_threshold;
Diana Vandenberg8fea6ea2017-02-18 17:24:45 -080063 // Buffer size for deciding if we are moving.
64 size_t moving_buffer_size;
Brian Silvermana10d20a2017-02-19 14:28:53 -080065
66 // Value between 0 and 1 indicating what fraction of one_revolution_distance
67 // it is acceptable for the offset to move.
68 double allowable_encoder_error;
Tyler Chatow61f77972017-02-04 17:41:14 -080069};
70
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080071struct RelativeEncoderZeroingConstants {};
72
Austin Schuhd82068e2019-01-26 20:05:42 -080073struct AbsoluteEncoderZeroingConstants {
74 // The number of samples in the moving average filter.
75 size_t average_filter_size;
76 // The distance that the absolute encoder needs to complete a full rotation.
77 double one_revolution_distance;
78 // Measured absolute position of the encoder when at zero.
79 double measured_absolute_position;
80 // Position of the middle of the range of motion in output coordinates.
81 double middle_position;
82
83 // Threshold for deciding if we are moving. moving_buffer_size samples need to
84 // be within this distance of each other before we use the middle one to zero.
85 double zeroing_threshold;
86 // Buffer size for deciding if we are moving.
87 size_t moving_buffer_size;
88
89 // Value between 0 and 1 indicating what fraction of one_revolution_distance
90 // it is acceptable for the offset to move.
91 double allowable_encoder_error;
92};
93
Ravago Jonesea6464c2020-10-10 15:40:46 -070094struct AbsoluteAndAbsoluteEncoderZeroingConstants {
95 // The number of samples in the moving average filter.
96 size_t average_filter_size;
97 // The distance that the absolute encoder needs to complete a full rotation.
98 double one_revolution_distance;
99 // Measured absolute position of the encoder when at zero.
100 double measured_absolute_position;
101
102 // The distance that the single turn absolute encoder needs to complete a full
103 // rotation.
104 double single_turn_one_revolution_distance;
105 // Measured absolute position of the single turn encoder when at zero.
106 double single_turn_measured_absolute_position;
107 // Position of the middle of the range of motion in output coordinates.
108 double single_turn_middle_position;
109
110 // Threshold for deciding if we are moving. moving_buffer_size samples need to
111 // be within this distance of each other before we use the middle one to zero.
112 double zeroing_threshold;
113 // Buffer size for deciding if we are moving.
114 size_t moving_buffer_size;
115
116 // Value between 0 and 1 indicating what fraction of one_revolution_distance
117 // it is acceptable for the offset to move.
118 double allowable_encoder_error;
119};
120
Brian Silvermanebca77a2016-02-14 22:14:00 -0500121// Defines a range of motion for a subsystem.
122// These are all absolute positions in scaled units.
123struct Range {
124 double lower_hard;
125 double upper_hard;
126 double lower;
127 double upper;
Austin Schuh2d64acd2019-02-15 22:55:07 -0800128
James Kuszmaulb83d6e12020-02-22 20:44:48 -0800129 constexpr double middle() const { return (lower_hard + upper_hard) / 2.0; }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800130
James Kuszmaulb83d6e12020-02-22 20:44:48 -0800131 constexpr double range() const { return upper_hard - lower_hard; }
Brian Silvermanebca77a2016-02-14 22:14:00 -0500132};
133
brians343bc112013-02-10 01:53:46 +0000134} // namespace constants
135} // namespace frc971
Brian Silverman431500a2013-10-28 19:50:15 -0700136
137#endif // FRC971_CONSTANTS_H_