blob: 44eb26270d1ccb8b95d539da0aee8a0aa64bb5f0 [file] [log] [blame]
Brian Silvermane0a95462014-02-17 00:41:09 -08001package frc971;
2
Philipp Schraderfd6335e2017-02-04 01:26:40 +00003// Represents all of the data for a single indexed encoder. In other words,
4// just a relative encoder with an index pulse.
5// The units on all of the positions are the same.
6// All encoder values are relative to where the encoder was at some arbitrary
7// point in time. All potentiometer values are relative to some arbitrary 0
8// position which varies with each robot.
9struct IndexPosition {
10 // Current position read from the encoder.
11 double encoder;
12 // Position from the encoder latched at the last index pulse.
13 double latched_encoder;
14 // How many index pulses we've seen since startup. Starts at 0.
15 uint32_t index_pulses;
16};
17
Brian Silverman0a7f6062015-01-24 17:41:33 -050018// Represents all of the data for a single potentiometer and indexed encoder
19// pair.
20// The units on all of the positions are the same.
21// All encoder values are relative to where the encoder was at some arbitrary
22// point in time. All potentiometer values are relative to some arbitrary 0
23// position which varies with each robot.
24struct PotAndIndexPosition {
25 // Current position read from the encoder.
26 double encoder;
27 // Current position read from the potentiometer.
28 double pot;
29
30 // Position from the encoder latched at the last index pulse.
31 double latched_encoder;
32 // Position from the potentiometer latched at the last index pulse.
33 double latched_pot;
34
35 // How many index pulses we've seen since startup. Starts at 0.
36 uint32_t index_pulses;
Brian Silvermane0a95462014-02-17 00:41:09 -080037};
Brian Silverman5b433df2014-02-17 11:57:37 -080038
Diana Vandenbergabb3d192017-01-28 16:19:43 -080039// Represents all of the data for a single potentiometer with an absolute and
40// relative encoder pair.
41// The units on all of the positions are the same.
42// The relative encoder values are relative to where the encoder was at some
43// arbitrary point in time. All potentiometer values are relative to some
44// arbitrary 0 position which varies with each robot.
45struct PotAndAbsolutePosition {
46 // Current position read from each encoder.
Austin Schuh5f01f152017-02-11 21:34:08 -080047 double encoder;
Diana Vandenbergabb3d192017-01-28 16:19:43 -080048 double absolute_encoder;
49
50 // Current position read from the potentiometer.
51 double pot;
52};
53
Austin Schuhd82068e2019-01-26 20:05:42 -080054// Represents all of the data for an absolute and relative encoder pair.
55// The units on all of the positions are the same.
56// The relative encoder values are relative to where the encoder was at some
57// arbitrary point in time.
58struct AbsolutePosition {
59 // Current position read from each encoder.
60 double encoder;
61 double absolute_encoder;
62};
63
Daniel Pettiab274232015-02-16 19:15:34 -080064// The internal state of a zeroing estimator.
65struct EstimatorState {
66 // If true, there has been a fatal error for the estimator.
67 bool error;
68 // If the joint has seen an index pulse and is zeroed.
69 bool zeroed;
70 // The estimated position of the joint.
71 double position;
Austin Schuhbe133ed2016-03-11 21:23:34 -080072
73 // The estimated position not using the index pulse.
74 double pot_position;
Daniel Pettiab274232015-02-16 19:15:34 -080075};
76
Austin Schuh5f01f152017-02-11 21:34:08 -080077// The internal state of a zeroing estimator.
Austin Schuh72db9a12019-01-21 18:02:51 -080078struct PotAndAbsoluteEncoderEstimatorState {
Austin Schuh5f01f152017-02-11 21:34:08 -080079 // If true, there has been a fatal error for the estimator.
80 bool error;
81 // If the joint has seen an index pulse and is zeroed.
82 bool zeroed;
83 // The estimated position of the joint.
84 double position;
85
86 // The estimated position not using the index pulse.
87 double pot_position;
Austin Schuh0e1c2c62017-02-21 02:03:25 -080088
89 // The estimated absolute position of the encoder. This is filtered, so it
90 // can be easily used when zeroing.
91 double absolute_position;
Austin Schuh5f01f152017-02-11 21:34:08 -080092};
93
Brian Silvermanf37839c2017-02-19 18:07:15 -080094// The internal state of a zeroing estimator.
Austin Schuhd82068e2019-01-26 20:05:42 -080095struct AbsoluteEncoderEstimatorState {
96 // If true, there has been a fatal error for the estimator.
97 bool error;
98 // If the joint has seen an index pulse and is zeroed.
99 bool zeroed;
100 // The estimated position of the joint.
101 double position;
102
103 // The estimated absolute position of the encoder. This is filtered, so it
104 // can be easily used when zeroing.
105 double absolute_position;
106};
107
108// The internal state of a zeroing estimator.
Brian Silvermanf37839c2017-02-19 18:07:15 -0800109struct IndexEstimatorState {
110 // If true, there has been a fatal error for the estimator.
111 bool error;
112 // If the joint has seen an index pulse and is zeroed.
113 bool zeroed;
114 // The estimated position of the joint. This is just the position relative to
115 // where we started if we're not zeroed yet.
116 double position;
117
118 // The positions of the extreme index pulses we've seen.
119 double min_index_position;
120 double max_index_position;
121 // The number of index pulses we've seen.
122 int32_t index_pulses_seen;
123};
124
Austin Schuh55934032017-03-11 12:45:27 -0800125struct HallEffectAndPositionEstimatorState {
126 // If error.
127 bool error;
128 // If we've found a positive edge while moving backwards and is zeroed.
129 bool zeroed;
130 // Encoder angle relative to where we started.
131 double encoder;
132 // The positions of the extreme posedges we've seen.
133 // If we've gotten enough samples where the hall effect is high before can be
134 // certain it is not a false positive.
135 bool high_long_enough;
136 double offset;
137};
138
Brian Silverman0a7f6062015-01-24 17:41:33 -0500139// A left/right pair of PotAndIndexPositions.
140struct PotAndIndexPair {
141 PotAndIndexPosition left;
142 PotAndIndexPosition right;
Austin Schuh60c56662014-02-17 14:37:19 -0800143};
Brian Silverman17f503e2015-08-02 18:17:18 -0700144
145// Records edges captured on a single hall effect sensor.
146struct HallEffectStruct {
147 bool current;
148 int32_t posedge_count;
149 int32_t negedge_count;
Brian Silvermand3efb182015-05-13 23:04:29 -0400150 double posedge_value;
151 double negedge_value;
Brian Silverman17f503e2015-08-02 18:17:18 -0700152};
153
Austin Schuhf380a3f2017-03-04 22:31:47 -0800154// Records the hall effect sensor and encoder values.
155struct HallEffectAndPosition {
156 // The current hall effect state.
157 bool current;
158 // The current encoder position.
Lee Mracek598a2452019-01-07 00:50:44 -0800159 double encoder;
Austin Schuhf380a3f2017-03-04 22:31:47 -0800160 // The number of positive and negative edges we've seen on the hall effect
161 // sensor.
162 int32_t posedge_count;
163 int32_t negedge_count;
164 // The values corresponding to the last hall effect sensor reading.
165 double posedge_value;
166 double negedge_value;
167};
168
Brian Silverman17f503e2015-08-02 18:17:18 -0700169// Records the positions for a mechanism with edge-capturing sensors on it.
170struct HallEffectPositions {
171 double current;
172 double posedge;
173 double negedge;
174};
175
176// Records edges captured on a single hall effect sensor.
177struct PosedgeOnlyCountedHallEffectStruct {
178 bool current;
179 int32_t posedge_count;
180 int32_t negedge_count;
181 double posedge_value;
182};
Austin Schuhedbb64f2016-03-19 01:18:09 -0700183
184// Parameters for the motion profiles.
185struct ProfileParameters {
186 // Maximum velocity for the profile.
187 float max_velocity;
188 // Maximum acceleration for the profile.
189 float max_acceleration;
190};