From 4c30610af0b57a0ce22eb5f0870d720adc59f644 Mon Sep 17 00:00:00 2001 From: devdesk Date: Fri, 6 Feb 2026 15:21:19 +0200 Subject: [PATCH] Stop printing current when motor is stopped - Remove idle/dot printing logic from MotorController::update() - Only print current readings when direction != 0 (motor running) - Simplifies logging by completely silencing output when stopped --- src/motor.cpp | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/src/motor.cpp b/src/motor.cpp index 1fffff3..75c8965 100644 --- a/src/motor.cpp +++ b/src/motor.cpp @@ -86,50 +86,17 @@ void MotorController::stop() { void MotorController::update() { #if CURRENT_SENSING_ENABLED static unsigned long lastPrintTime = 0; - static bool lastWasIdle = false; - static int idleDotCount = 0; - const int dotsPerLine = 50; // Print newline after this many dots - const int dotInterval = 5; // Print dot every N idle readings // Read current sensors _currentRight = readCurrentSense(_pins.r_is); _currentLeft = readCurrentSense(_pins.l_is); - // Log current readings frequently for data collection + // Log current readings only when motor is running (direction != 0) unsigned long now = millis(); - if (now - lastPrintTime >= CURRENT_LOG_INTERVAL_MS) { + if (_direction != 0 && now - lastPrintTime >= CURRENT_LOG_INTERVAL_MS) { lastPrintTime = now; - - // Check if this is an idle reading (all zeros) - bool isIdle = (_currentRight < 0.01f && _currentLeft < 0.01f && _direction == 0); - - if (isIdle) { - if (!lastWasIdle) { - // First idle after non-idle: print full line once - Serial.printf("%s CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d\n", - _name, _currentRight, _currentLeft, _direction, _speed); - idleDotCount = 0; - } else { - // Subsequent idle: print dot every N readings - idleDotCount++; - if (idleDotCount % dotInterval == 0) { - Serial.print("."); - if ((idleDotCount / dotInterval) % dotsPerLine == 0) { - Serial.println(); // Newline after dotsPerLine dots - } - } - } - lastWasIdle = true; - } else { - // Non-idle reading: always print full line - if (lastWasIdle && idleDotCount > 0) { - Serial.println(); // Newline after dots before full reading - } - Serial.printf("%s CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d\n", - _name, _currentRight, _currentLeft, _direction, _speed); - lastWasIdle = false; - idleDotCount = 0; - } + Serial.printf("%s CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d\n", + _name, _currentRight, _currentLeft, _direction, _speed); } // Check for stall condition