Skip to content

Commit f371740

Browse files
committed
feat(motorgo): Update to allow encoder accumulator to be reset
* Update MT6701 to allow accumulator to be reset * Update MotorGo Mini to wrap this function for ease of use This is helpful when switching regimes between velocity control and angle control for instance. * Build and run as part of the `esp-motorgo-mini-gesture-control` project.
1 parent 44ff49b commit f371740

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

components/motorgo-mini/include/motorgo-mini.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ class MotorGoMini : public BaseComponent {
195195
/// \return A reference to the encoder 2
196196
Encoder &encoder2();
197197

198+
/// Reset the encoder 1 accumulator
199+
/// \details This function resets the encoder 1 accumulator to 0.
200+
/// This will reset the encoder's position to be within the range
201+
/// of 0 to 2*pi.
202+
void reset_encoder1_accumulator();
203+
204+
/// Reset the encoder 2 accumulator
205+
/// \details This function resets the encoder 2 accumulator to 0.
206+
/// This will reset the encoder's position to be within the range
207+
/// of 0 to 2*pi.
208+
void reset_encoder2_accumulator();
209+
198210
/////////////////////////////////////////////////////////////////////////////
199211
// Motor Current Sense
200212
/////////////////////////////////////////////////////////////////////////////

components/motorgo-mini/src/motorgo-mini.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ MotorGoMini::Encoder &MotorGoMini::encoder1() { return encoder1_; }
6666

6767
MotorGoMini::Encoder &MotorGoMini::encoder2() { return encoder2_; }
6868

69+
void MotorGoMini::reset_encoder1_accumulator() { encoder1_.reset_accumulator(); }
70+
71+
void MotorGoMini::reset_encoder2_accumulator() { encoder2_.reset_accumulator(); }
72+
6973
espp::BldcDriver &MotorGoMini::motor1_driver() { return motor1_driver_; }
7074

7175
espp::BldcDriver &MotorGoMini::motor2_driver() { return motor2_driver_; }

components/mt6701/include/mt6701.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ class Mt6701 : public BasePeripheral<uint8_t, Interface == Mt6701Interface::I2C>
183183
*/
184184
int get_accumulator() const { return accumulator_.load(); }
185185

186+
/**
187+
* @brief Reset the accumulator to zero.
188+
*/
189+
void reset_accumulator() { accumulator_ = 0; }
190+
186191
/**
187192
* @brief Return the mechanical / shaft angle of the encoder, in radians,
188193
* within the range [0, 2pi].

0 commit comments

Comments
 (0)