Commit c74c3d0
authored
fix(AS5600): convert static variables to instance members (#571)
* fix: convert static variables to instance members to enable supporting sampling multiple sensors
Replace static variables `prev_count` and `prev_time` with instance
member variables to support multiple AS5600 sensor instances running
simultaneously. Previously, all instances would share the same static
variables, causing incorrect position and velocity calculations in
multi-sensor configurations.
- Add `prev_count_` and `prev_time_` as class member variables
- Initialize `prev_count_` to 0 and `prev_time_` to current time
- Remove static keyword from variables in `update()` method
- Ensures each sensor instance maintains independent state
* fix(as5600): initialize prev_count_ to prevent incorrect first diff
Initialize prev_count_ to the first sensor reading in init() to avoid
calculating an incorrect diff on the first update() call. Previously,
prev_count_ defaulted to 0 while count_ was set to the actual sensor
reading, causing a large erroneous jump in the accumulator on startup.
- Set prev_count_ = count after reading initial angle
- Ensures diff calculation is correct from the first update
- Prevents accumulator corruption on initialization
* refactor(as5600): align implementation with MT6701 encoder
- Replace std::chrono::high_resolution_clock with esp_timer_get_time()
- Convert prev_time_ to uint64_t prev_time_us_ for microsecond precision
- Store prev_count as local variable instead of class member
* Fix (AS5600): Used read_counts() instead of non-existant read() method and cleaned the code.
- Used read_counts() method instead of the wrongly used non-existed read() method
- Removed unnecessary trailing white spaces1 parent c7e68b2 commit c74c3d0
1 file changed
+20
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
186 | | - | |
187 | 193 | | |
188 | 194 | | |
189 | | - | |
190 | | - | |
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
| |||
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 207 | + | |
209 | 208 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | | - | |
| 238 | + | |
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
241 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
242 | 245 | | |
243 | 246 | | |
244 | 247 | | |
| |||
298 | 301 | | |
299 | 302 | | |
300 | 303 | | |
| 304 | + | |
301 | 305 | | |
302 | 306 | | |
0 commit comments