Skip to content

Commit 2d65174

Browse files
authored
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
1 parent 4d9a7ec commit 2d65174

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

components/as5600/include/as5600.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ class As5600 : public BasePeripheral<> {
9595
*/
9696
void initialize(std::error_code &ec) { init(ec); }
9797

98-
99-
10098
/**
10199
* @brief Return whether the sensor has found absolute 0 yet.
102100
* @note The AS5600 (using I2C/SPI) does not need to search for absolute 0
@@ -176,8 +174,6 @@ class As5600 : public BasePeripheral<> {
176174
return (int)((angle_h << 6) | angle_l);
177175
}
178176

179-
180-
181177
void update(std::error_code &ec) {
182178
logger_.info("update");
183179
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
@@ -237,6 +233,7 @@ class As5600 : public BasePeripheral<> {
237233
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
238234
// initialize the accumulator to have the current angle
239235
auto count = read_count(ec);
236+
prev_count_ = count;
240237
if (ec) {
241238
return;
242239
}

0 commit comments

Comments
 (0)