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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user