Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 1 | #ifndef FRC971_CONSTANTS_H_ |
| 2 | #define FRC971_CONSTANTS_H_ |
Brian Silverman | 2c590c3 | 2013-11-04 18:08:54 -0800 | [diff] [blame] | 3 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 4 | #include <cstddef> |
| 5 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | namespace frc971 { |
| 7 | namespace constants { |
| 8 | |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 9 | struct 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 Chatow | f8f0311 | 2017-02-05 14:31:34 -0800 | [diff] [blame] | 24 | struct PotAndIndexPulseZeroingConstants { |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame] | 25 | // The number of samples in the moving average filter. |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 26 | size_t average_filter_size; |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame] | 27 | // 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 Schrader | 3f5b618 | 2017-03-25 22:36:37 +0000 | [diff] [blame] | 31 | // Value between 0 and .5 which determines a fraction of the index_diff |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame] | 32 | // you want to use. |
| 33 | double allowable_encoder_error; |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Tyler Chatow | 61f7797 | 2017-02-04 17:41:14 -0800 | [diff] [blame] | 36 | struct EncoderPlusIndexZeroingConstants { |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 37 | // 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 Schrader | 3f5b618 | 2017-03-25 22:36:37 +0000 | [diff] [blame] | 46 | // 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 Chatow | 61f7797 | 2017-02-04 17:41:14 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct PotAndAbsoluteEncoderZeroingConstants { |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 53 | // The number of samples in the moving average filter. |
| 54 | size_t average_filter_size; |
Tyler Chatow | 61f7797 | 2017-02-04 17:41:14 -0800 | [diff] [blame] | 55 | // The distance that the absolute encoder needs to complete a full rotation. |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 56 | double one_revolution_distance; |
| 57 | // Measured absolute position of the encoder when at zero. |
| 58 | double measured_absolute_position; |
| 59 | |
Brian Silverman | a10d20a | 2017-02-19 14:28:53 -0800 | [diff] [blame] | 60 | // 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 Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 62 | double zeroing_threshold; |
Diana Vandenberg | 8fea6ea | 2017-02-18 17:24:45 -0800 | [diff] [blame] | 63 | // Buffer size for deciding if we are moving. |
| 64 | size_t moving_buffer_size; |
Brian Silverman | a10d20a | 2017-02-19 14:28:53 -0800 | [diff] [blame] | 65 | |
| 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 Chatow | 61f7797 | 2017-02-04 17:41:14 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 71 | struct RelativeEncoderZeroingConstants {}; |
| 72 | |
James Kuszmaul | bdc6a79 | 2023-08-12 16:29:38 -0700 | [diff] [blame^] | 73 | struct ContinuousAbsoluteEncoderZeroingConstants { |
| 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 | // It is presumed that this will always be 2 * pi for any subsystem using this |
| 78 | // class, unless you have a continuous system that for some reason doesn't |
| 79 | // have a logical period of 1 revolution in radians. |
| 80 | double one_revolution_distance; |
| 81 | // Measured absolute position of the encoder when at zero. |
| 82 | double measured_absolute_position; |
| 83 | |
| 84 | // Threshold for deciding if we are moving. moving_buffer_size samples need to |
| 85 | // be within this distance of each other before we use the middle one to zero. |
| 86 | double zeroing_threshold; |
| 87 | // Buffer size for deciding if we are moving. |
| 88 | size_t moving_buffer_size; |
| 89 | |
| 90 | // Value between 0 and 1 indicating what fraction of a revolution |
| 91 | // it is acceptable for the offset to move. |
| 92 | double allowable_encoder_error; |
| 93 | }; |
| 94 | |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 95 | struct AbsoluteEncoderZeroingConstants { |
| 96 | // The number of samples in the moving average filter. |
| 97 | size_t average_filter_size; |
| 98 | // The distance that the absolute encoder needs to complete a full rotation. |
| 99 | double one_revolution_distance; |
| 100 | // Measured absolute position of the encoder when at zero. |
| 101 | double measured_absolute_position; |
| 102 | // Position of the middle of the range of motion in output coordinates. |
| 103 | double middle_position; |
| 104 | |
| 105 | // Threshold for deciding if we are moving. moving_buffer_size samples need to |
| 106 | // be within this distance of each other before we use the middle one to zero. |
| 107 | double zeroing_threshold; |
| 108 | // Buffer size for deciding if we are moving. |
| 109 | size_t moving_buffer_size; |
| 110 | |
| 111 | // Value between 0 and 1 indicating what fraction of one_revolution_distance |
| 112 | // it is acceptable for the offset to move. |
| 113 | double allowable_encoder_error; |
| 114 | }; |
| 115 | |
Ravago Jones | ea6464c | 2020-10-10 15:40:46 -0700 | [diff] [blame] | 116 | struct AbsoluteAndAbsoluteEncoderZeroingConstants { |
| 117 | // The number of samples in the moving average filter. |
| 118 | size_t average_filter_size; |
| 119 | // The distance that the absolute encoder needs to complete a full rotation. |
| 120 | double one_revolution_distance; |
| 121 | // Measured absolute position of the encoder when at zero. |
| 122 | double measured_absolute_position; |
| 123 | |
| 124 | // The distance that the single turn absolute encoder needs to complete a full |
| 125 | // rotation. |
| 126 | double single_turn_one_revolution_distance; |
| 127 | // Measured absolute position of the single turn encoder when at zero. |
| 128 | double single_turn_measured_absolute_position; |
| 129 | // Position of the middle of the range of motion in output coordinates. |
| 130 | double single_turn_middle_position; |
| 131 | |
| 132 | // Threshold for deciding if we are moving. moving_buffer_size samples need to |
| 133 | // be within this distance of each other before we use the middle one to zero. |
| 134 | double zeroing_threshold; |
| 135 | // Buffer size for deciding if we are moving. |
| 136 | size_t moving_buffer_size; |
| 137 | |
| 138 | // Value between 0 and 1 indicating what fraction of one_revolution_distance |
| 139 | // it is acceptable for the offset to move. |
| 140 | double allowable_encoder_error; |
| 141 | }; |
| 142 | |
Brian Silverman | ebca77a | 2016-02-14 22:14:00 -0500 | [diff] [blame] | 143 | // Defines a range of motion for a subsystem. |
| 144 | // These are all absolute positions in scaled units. |
| 145 | struct Range { |
| 146 | double lower_hard; |
| 147 | double upper_hard; |
| 148 | double lower; |
| 149 | double upper; |
Austin Schuh | 2d64acd | 2019-02-15 22:55:07 -0800 | [diff] [blame] | 150 | |
James Kuszmaul | b83d6e1 | 2020-02-22 20:44:48 -0800 | [diff] [blame] | 151 | constexpr double middle() const { return (lower_hard + upper_hard) / 2.0; } |
James Kuszmaul | 2a59cf0 | 2022-03-17 11:02:02 -0700 | [diff] [blame] | 152 | constexpr double middle_soft() const { return (lower + upper) / 2.0; } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 153 | |
James Kuszmaul | b83d6e1 | 2020-02-22 20:44:48 -0800 | [diff] [blame] | 154 | constexpr double range() const { return upper_hard - lower_hard; } |
Brian Silverman | ebca77a | 2016-02-14 22:14:00 -0500 | [diff] [blame] | 155 | }; |
| 156 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 157 | } // namespace constants |
| 158 | } // namespace frc971 |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 159 | |
| 160 | #endif // FRC971_CONSTANTS_H_ |