From 2b685bdaff4a2584bab8cc8ff00407a84f601147 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 6 Feb 2025 23:11:03 -0800 Subject: [PATCH 1/8] WIP - Updates Serial handling was blocking until timeout (1s), which made sub 1s guiding near impossible (!). --- src/MeadeCommandProcessor.cpp | 5 ++-- src/Mount.cpp | 53 ++++++++++++++++++++++++++--------- src/Mount.hpp | 2 ++ src/b_setup.hpp | 22 +++++++-------- src/f_serial.hpp | 44 ++++++++++++++++++++--------- 5 files changed, 86 insertions(+), 40 deletions(-) diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 2198fb77..56b1bf5a 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -622,7 +622,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Information: // This stops all motors, including tracking. Note that deceleration curves are still followed. // Returns: -// "1" when all motors have stopped +// nothing // // :Qd# // Description: @@ -1517,6 +1517,7 @@ String MeadeCommandProcessor::handleMeadeSetInfo(String inCmd) ///////////////////////////// String MeadeCommandProcessor::handleMeadeMovement(String inCmd) { + LOG(DEBUG_MEADE, "[MEADE]: Process Move command: [%s]", inCmd.c_str()); if (inCmd[0] == 'S') // :MS# { _mount->startSlewingToTarget(); @@ -2199,7 +2200,7 @@ String MeadeCommandProcessor::processCommand(String inCmd) { if (inCmd[0] == ':') { - LOG(DEBUG_MEADE, "[MEADE]: Received command '%s'", inCmd.c_str()); + LOG(DEBUG_MEADE, "[MEADE]: Received command '%s'", inCmd.c_str()); // Apparently some LX200 implementations put spaces in their commands..... remove them with impunity. int spacePos; diff --git a/src/Mount.cpp b/src/Mount.cpp index f498c018..ae36149a 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -357,7 +357,7 @@ void Mount::configureAZStepper(byte pin1, byte pin2, int maxSpeed, int maxAccele #ifdef NEW_STEPPER_LIB _stepperAZ = new StepperAzSlew(AccelStepper::DRIVER, pin1, pin2); #else - _stepperAZ = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); + _stepperAZ = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); #endif _stepperAZ->setMaxSpeed(maxSpeed); _stepperAZ->setAcceleration(maxAcceleration); @@ -375,7 +375,7 @@ void Mount::configureALTStepper(byte pin1, byte pin2, int maxSpeed, int maxAccel #ifdef NEW_STEPPER_LIB _stepperALT = new StepperAltSlew(AccelStepper::DRIVER, pin1, pin2); #else - _stepperALT = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); + _stepperALT = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); #endif _stepperALT->setMaxSpeed(maxSpeed); _stepperALT->setAcceleration(maxAcceleration); @@ -733,7 +733,7 @@ void Mount::configureALTdriver(uint16_t ALT_SW_RX, uint16_t ALT_SW_TX, float rse _driverALT->pdn_disable(true); #if UART_CONNECTION_TEST_TXRX == 1 bool UART_Rx_connected = false; - UART_Rx_connected = connectToDriver(_driverALT, "ALT"); + UART_Rx_connected = connectToDriver(_driverALT, "ALT"); if (!UART_Rx_connected) { digitalWrite(ALT_EN_PIN, @@ -824,7 +824,7 @@ void Mount::configureFocusDriver( _driverFocus->pdn_disable(true); #if UART_CONNECTION_TEST_TXRX == 1 bool UART_Rx_connected = false; - UART_Rx_connected = connectToDriver(_driverFocus, "Focus"); + UART_Rx_connected = connectToDriver(_driverFocus, "Focus"); if (!UART_Rx_connected) { digitalWrite(FOCUS_EN_PIN, @@ -1541,11 +1541,28 @@ void Mount::stopGuiding(bool ra, bool dec) // Stop RA guide first, since it's just a speed change back to tracking speed if (ra && (_mountStatus & STATUS_GUIDE_PULSE_RA)) { - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, - "[GUIDE]: stopGuide: RA set speed : %f (at %l)", - _trackingSpeed, - _stepperTRK->currentPosition()); + long raStepsDuringGuide = _stepperTRK->currentPosition() - _stepperTrkPosAtGuideStart; + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: TRK stop guide at : %l", _stepperTRK->currentPosition()); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: TRK steps moved : %l", raStepsDuringGuide); + long extraSteps = 0; + if (_stepperTRK->speed() < _trackingSpeed) + { + // EAST (1.5x), faster so we need 1/3 of the steps + extraSteps = -((1.0 / (2.0 - RA_PULSE_MULTIPLIER)) - 1.0) * raStepsDuringGuide; + } + else + { + // WEST (0.5) + extraSteps = (1.0 - (1.0 / RA_PULSE_MULTIPLIER)) * raStepsDuringGuide; + } _stepperTRK->setSpeed(_trackingSpeed); + + // Calculate the extra steps moved during guiding on top of tracking and convert from TRK stepper to RA stepper + extraSteps *= RA_SLEW_MICROSTEPPING / RA_TRACKING_MICROSTEPPING; + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: RA extra steps : %l", extraSteps); + // Adjust RA coordinate by the amount of steps moved during guiding + _stepperRA->setCurrentPosition(_stepperRA->currentPosition() + extraSteps); + _mountStatus &= ~STATUS_GUIDE_PULSE_RA; } @@ -1561,8 +1578,12 @@ void Mount::stopGuiding(bool ra, bool dec) _stepperGUIDE->run(); _stepperTRK->runSpeed(); } + long decStepsDuringGuide = _stepperGUIDE->currentPosition() - _stepperGuidePosAtGuideStart; - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: DEC stopped at : %l", _stepperGUIDE->currentPosition()); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: DEC steps moved : %l", decStepsDuringGuide); + // Adjust DEC coordinate by the amount of steps moved during guiding + _stepperDEC->setCurrentPosition(_stepperDEC->currentPosition() + + decStepsDuringGuide * DEC_SLEW_MICROSTEPPING / DEC_GUIDE_MICROSTEPPING); _mountStatus &= ~STATUS_GUIDE_PULSE_DEC; } @@ -1611,8 +1632,9 @@ void Mount::guidePulse(byte direction, int duration) // Also compensate for microstepping mode change between slew & guiding/tracking float decGuidingSpeed = _stepsPerDECDegree * (DEC_GUIDE_MICROSTEPPING / DEC_SLEW_MICROSTEPPING) * siderealDegreesInHour / 3600.0f; // u-steps/deg * deg/hr / sec/hr = u-steps/sec - float raGuidingSpeed = _stepsPerRADegree * (RA_TRACKING_MICROSTEPPING / RA_SLEW_MICROSTEPPING) * siderealDegreesInHour - / 3600.0f; // u-steps/deg * deg/hr / sec/hr = u-steps/sec + + // We recalculate tracking speed here... + float raGuidingSpeed = _stepsPerRADegree * (RA_TRACKING_MICROSTEPPING / RA_SLEW_MICROSTEPPING) * 360.0f / SIDEREAL_SECONDS_PER_DAY; // TODO: Do we need to track how many steps the steppers took and add them to the GoHome calculation? // If so, we need to remember where we were when we started the guide pulse. Then at the end, @@ -1625,6 +1647,7 @@ void Mount::guidePulse(byte direction, int duration) LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC base speed : %f", decGuidingSpeed); LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC guide speed : %f", DEC_PULSE_MULTIPLIER * decGuidingSpeed); _stepperGUIDE->setSpeed(DEC_PULSE_MULTIPLIER * decGuidingSpeed); + _stepperGuidePosAtGuideStart = _stepperGUIDE->currentPosition(); _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC; _guideDecEndTime = millis() + duration; break; @@ -1633,6 +1656,7 @@ void Mount::guidePulse(byte direction, int duration) LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC base speed : %f", decGuidingSpeed); LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC guide speed : %f", -DEC_PULSE_MULTIPLIER * decGuidingSpeed); _stepperGUIDE->setSpeed(-DEC_PULSE_MULTIPLIER * decGuidingSpeed); + _stepperGuidePosAtGuideStart = _stepperGUIDE->currentPosition(); _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC; _guideDecEndTime = millis() + duration; break; @@ -1647,6 +1671,7 @@ void Mount::guidePulse(byte direction, int duration) "[GUIDE]: guidePulse: RA guide speed : %f (%f x adjusted speed)", (RA_PULSE_MULTIPLIER * raGuidingSpeed), RA_PULSE_MULTIPLIER); + _stepperTrkPosAtGuideStart = _stepperTRK->currentPosition(); _stepperTRK->setSpeed(RA_PULSE_MULTIPLIER * raGuidingSpeed); // Faster than siderael _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA; _guideRaEndTime = millis() + duration; @@ -1660,8 +1685,9 @@ void Mount::guidePulse(byte direction, int duration) LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA adjusted speed : %f", raGuidingSpeed); LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA guide speed : %f (%f x adjusted speed)", - (2.0 - RA_PULSE_MULTIPLIER * raGuidingSpeed), + (2.0 - RA_PULSE_MULTIPLIER) * raGuidingSpeed, (2.0 - RA_PULSE_MULTIPLIER)); + _stepperTrkPosAtGuideStart = _stepperTRK->currentPosition(); _stepperTRK->setSpeed(raGuidingSpeed * (2.0f - RA_PULSE_MULTIPLIER)); // Slower than siderael _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA; _guideRaEndTime = millis() + duration; @@ -1836,7 +1862,7 @@ void Mount::getAZALTPositions(long &azPos, long &altPos) #if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) azPos = _stepperAZ->currentPosition(); #else - azPos = 0; + azPos = 0; #endif #if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE) altPos = _stepperALT->currentPosition(); @@ -2957,6 +2983,7 @@ void Mount::loop() bool stopDecGuiding = (now > _guideDecEndTime) && (_mountStatus & STATUS_GUIDE_PULSE_DEC); if (stopRaGuiding || stopDecGuiding) { + LOG(DEBUG_GUIDE, "[MOUNT]: Loop: StopGuiding. Now: %l, RA End: %l, DEC End: %l", now, _guideRaEndTime, _guideDecEndTime); stopGuiding(stopRaGuiding, stopDecGuiding); } else diff --git a/src/Mount.hpp b/src/Mount.hpp index 8a2d63ec..173d3186 100644 --- a/src/Mount.hpp +++ b/src/Mount.hpp @@ -655,6 +655,8 @@ class Mount unsigned long _guideRaEndTime; unsigned long _guideDecEndTime; + long _stepperGuidePosAtGuideStart; + long _stepperTrkPosAtGuideStart; unsigned long _lastMountPrint = 0; float _trackingSpeed; // RA u-steps/sec when in tracking mode float _trackingSpeedCalibration; // Dimensionless, very close to 1.0 diff --git a/src/b_setup.hpp b/src/b_setup.hpp index 310716d2..d9c8ed45 100644 --- a/src/b_setup.hpp +++ b/src/b_setup.hpp @@ -339,7 +339,6 @@ void setup() // Set the stepper motor parameters #if (RA_STEPPER_TYPE != STEPPER_TYPE_NONE) LOG(DEBUG_ANY, "[STEPPERS]: Configure RA stepper NEMA."); - LOG(DEBUG_ANY, "[STEPPERS]: Stepper SPR : %d", RA_STEPPER_SPR); LOG(DEBUG_ANY, "[STEPPERS]: Slew Microsteps : %d", RA_SLEW_MICROSTEPPING); LOG(DEBUG_ANY, "[STEPPERS]: Trk Microsteps : %d", RA_TRACKING_MICROSTEPPING); LOG(DEBUG_ANY, "[STEPPERS]: Stepper SPR : %d", RA_STEPPER_SPR); @@ -363,17 +362,18 @@ void setup() #if (DEC_STEPPER_TYPE != STEPPER_TYPE_NONE) LOG(DEBUG_ANY, "[STEPPERS]: Configure DEC stepper NEMA."); - LOG(DEBUG_ANY, "[STEPPERS]: Slew Microsteps : %d", DEC_SLEW_MICROSTEPPING); - LOG(DEBUG_ANY, "[STEPPERS]: Stepper SPR : %d", DEC_STEPPER_SPR); - LOG(DEBUG_ANY, "[STEPPERS]: Transmission : %f", DEC_TRANSMISSION); + LOG(DEBUG_ANY, "[STEPPERS]: Slew Microsteps : %d", DEC_SLEW_MICROSTEPPING); + LOG(DEBUG_ANY, "[STEPPERS]: Guide Microsteps : %d", DEC_GUIDE_MICROSTEPPING); + LOG(DEBUG_ANY, "[STEPPERS]: Stepper SPR : %d", DEC_STEPPER_SPR); + LOG(DEBUG_ANY, "[STEPPERS]: Transmission : %f", DEC_TRANSMISSION); #ifdef NEW_STEPPER_LIB - LOG(DEBUG_ANY, "[STEPPERS]: Driver Slew SPR : %l", config::Dec::DRIVER_SPR_SLEW); - LOG(DEBUG_ANY, "[STEPPERS]: Driver Trk SPR : %l", config::Dec::DRIVER_SPR_TRK); - LOG(DEBUG_ANY, "[STEPPERS]: SPR Slew : %f", config::Dec::SPR_SLEW); - LOG(DEBUG_ANY, "[STEPPERS]: SPR Trk : %f", config::Dec::SPR_TRK); - LOG(DEBUG_ANY, "[STEPPERS]: Speed Slew : %f", config::Dec::SPEED_SLEW); - LOG(DEBUG_ANY, "[STEPPERS]: Accel Slew : %f", config::Dec::ACCEL_SLEW); - LOG(DEBUG_ANY, "[STEPPERS]: Speed Trk : %f", config::Dec::SPEED_TRK); + LOG(DEBUG_ANY, "[STEPPERS]: Driver Slew SPR : %l", config::Dec::DRIVER_SPR_SLEW); + LOG(DEBUG_ANY, "[STEPPERS]: Driver Trk SPR : %l", config::Dec::DRIVER_SPR_TRK); + LOG(DEBUG_ANY, "[STEPPERS]: SPR Slew : %f", config::Dec::SPR_SLEW); + LOG(DEBUG_ANY, "[STEPPERS]: SPR Trk : %f", config::Dec::SPR_TRK); + LOG(DEBUG_ANY, "[STEPPERS]: Speed Slew : %f", config::Dec::SPEED_SLEW); + LOG(DEBUG_ANY, "[STEPPERS]: Accel Slew : %f", config::Dec::ACCEL_SLEW); + LOG(DEBUG_ANY, "[STEPPERS]: Speed Trk : %f", config::Dec::SPEED_TRK); LOG(DEBUG_ANY, "[STEPPERS]: Configure DEC stepper NEMA..."); mount.configureDECStepper(DECmotorPin1, DECmotorPin2, config::Dec::SPEED_SLEW, config::Dec::ACCEL_SLEW); #else diff --git a/src/f_serial.hpp b/src/f_serial.hpp index 9d6e8dd4..42a7c2a5 100644 --- a/src/f_serial.hpp +++ b/src/f_serial.hpp @@ -11,6 +11,7 @@ void processSerialData(); // The main loop when under serial control void serialLoop() { + //Serial.print('.'); mount.loop(); mount.displayStepperPositionThrottled(); @@ -21,6 +22,7 @@ void serialLoop() #if (WIFI_ENABLED == 1) wifiControl.loop(); #endif + //Serial.println('x'); } ////////////////////////////////////////////////// @@ -35,12 +37,13 @@ void serialEvent() // ESP needs to call this in a loop :_( void processSerialData() { - char buffer[2]; + static char buffer[20]; + static unsigned int index = 0; while (Serial.available() > 0) { - if (Serial.readBytes(buffer, 1) == 1) + if (Serial.readBytes((buffer + index), 1) == 1) { - if (buffer[0] == 0x06) + if (buffer[index] == 0x06) { LOG(DEBUG_SERIAL, "[SERIAL]: Received: ACK request, replying P"); // When not debugging, print the result to the serial port . @@ -48,25 +51,38 @@ void processSerialData() #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1) Serial.print('P'); #endif + index = 0; } else { - String inCmd = String(buffer[0]) + Serial.readStringUntil('#'); - LOG(DEBUG_SERIAL, "[SERIAL]: ReceivedCommand(%d chars): [%s]", inCmd.length(), inCmd.c_str()); - - String retVal = MeadeCommandProcessor::instance()->processCommand(inCmd); - if (retVal != "") + if (buffer[index] == '#') { - LOG(DEBUG_SERIAL, "[SERIAL]: RepliedWith: [%s]", retVal.c_str()); - // When not debugging, print the result to the serial port . - // When debugging, only print the result to Serial if we're on seperate ports. + // Ignoring trailing hash + buffer[index] = 0; + String inCmd = String(buffer); + LOG(DEBUG_SERIAL, "[SERIAL]: ReceivedCommand(%d chars): [%s]", inCmd.length(), inCmd.c_str()); + + String retVal = MeadeCommandProcessor::instance()->processCommand(inCmd); + if (retVal != "") + { + LOG(DEBUG_SERIAL, "[SERIAL]: RepliedWith: [%s]", retVal.c_str()); + // When not debugging, print the result to the serial port . + // When debugging, only print the result to Serial if we're on seperate ports. #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1) - Serial.print(retVal); + Serial.print(retVal); #endif + } + // Wait for next command + index = 0; } - else + else if (buffer[index] > 31) { - LOG(DEBUG_SERIAL, "[SERIAL]: NoReply"); + index++; + if (index >= sizeof(buffer)) + { + LOG(DEBUG_SERIAL, "[SERIAL]: Command buffer overflow! Ignoring received data."); + index = 0; + } } } } From 672790fb8e98309a48150dccc9ba73472a548ee3 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 21 Feb 2025 09:08:42 -0800 Subject: [PATCH 2/8] Ignore guide pulse at tracking limits --- src/Mount.cpp | 156 ++++++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 75 deletions(-) diff --git a/src/Mount.cpp b/src/Mount.cpp index ae36149a..69ce666d 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -733,7 +733,7 @@ void Mount::configureALTdriver(uint16_t ALT_SW_RX, uint16_t ALT_SW_TX, float rse _driverALT->pdn_disable(true); #if UART_CONNECTION_TEST_TXRX == 1 bool UART_Rx_connected = false; - UART_Rx_connected = connectToDriver(_driverALT, "ALT"); + UART_Rx_connected = connectToDriver("ALT"); if (!UART_Rx_connected) { digitalWrite(ALT_EN_PIN, @@ -824,7 +824,7 @@ void Mount::configureFocusDriver( _driverFocus->pdn_disable(true); #if UART_CONNECTION_TEST_TXRX == 1 bool UART_Rx_connected = false; - UART_Rx_connected = connectToDriver(_driverFocus, "Focus"); + UART_Rx_connected = connectToDriver("FOC"); if (!UART_Rx_connected) { digitalWrite(FOCUS_EN_PIN, @@ -1609,89 +1609,95 @@ void Mount::guidePulse(byte direction, int duration) #if (DEBUG_LEVEL != DEBUG_NONE) const char *directionName = "-NE-S---W"; #endif - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: > Guide Pulse %c for %dms", directionName[direction], duration); - if ((direction == NORTH) || (direction == SOUTH)) + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: > Guide Pulse %c for %dms requested", directionName[direction], duration); + if (!isSlewingTRK()) { - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC current steps : %l", _stepperGUIDE->currentPosition()); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC steps/deg : %f", _stepsPerDECDegree); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, - "[GUIDE]: guidePulse: DEC Microstep ratio : %f", - (DEC_GUIDE_MICROSTEPPING / DEC_SLEW_MICROSTEPPING)); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: Not tracking (at limit?), ignoring guide pulse"); } else { - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA current steps : %l", _stepperTRK->currentPosition()); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA steps/deg : %f", _stepsPerRADegree); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, - "[GUIDE]: guidePulse: RA Microstep ratio : %f", - (RA_TRACKING_MICROSTEPPING / RA_SLEW_MICROSTEPPING)); - } - - // DEC stepper moves at sidereal rate in both directions - // RA stepper moves at either 2.5x sidereal rate or 0.5x sidereal rate. - // Also compensate for microstepping mode change between slew & guiding/tracking - float decGuidingSpeed = _stepsPerDECDegree * (DEC_GUIDE_MICROSTEPPING / DEC_SLEW_MICROSTEPPING) * siderealDegreesInHour - / 3600.0f; // u-steps/deg * deg/hr / sec/hr = u-steps/sec + if ((direction == NORTH) || (direction == SOUTH)) + { + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC current steps : %l", _stepperGUIDE->currentPosition()); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC steps/deg : %f", _stepsPerDECDegree); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, + "[GUIDE]: guidePulse: DEC Microstep ratio : %f", + (1.0 * DEC_GUIDE_MICROSTEPPING / DEC_SLEW_MICROSTEPPING)); + } + else + { + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA current steps : %l", _stepperTRK->currentPosition()); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA steps/deg : %f", _stepsPerRADegree); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, + "[GUIDE]: guidePulse: RA Microstep ratio : %f", + (1.0 * RA_TRACKING_MICROSTEPPING / RA_SLEW_MICROSTEPPING)); + } - // We recalculate tracking speed here... - float raGuidingSpeed = _stepsPerRADegree * (RA_TRACKING_MICROSTEPPING / RA_SLEW_MICROSTEPPING) * 360.0f / SIDEREAL_SECONDS_PER_DAY; + // DEC stepper moves at sidereal rate in both directions + // RA stepper moves at either 2.5x sidereal rate or 0.5x sidereal rate. + // Also compensate for microstepping mode change between slew & guiding/tracking + float decGuidingSpeed = _stepsPerDECDegree * (1.0 * DEC_GUIDE_MICROSTEPPING / DEC_SLEW_MICROSTEPPING) * siderealDegreesInHour + / 3600.0f; // u-steps/deg * deg/hr / sec/hr = u-steps/sec + float raGuidingSpeed = _stepsPerRADegree * (1.0 * RA_TRACKING_MICROSTEPPING / RA_SLEW_MICROSTEPPING) * siderealDegreesInHour + / 3600.0f; // u-steps/deg * deg/hr / sec/hr = u-steps/sec - // TODO: Do we need to track how many steps the steppers took and add them to the GoHome calculation? - // If so, we need to remember where we were when we started the guide pulse. Then at the end, - // we can calculate the difference. Ignore DEC Guide for now. - // TODO: Take guide pulses on DEC into account + // TODO: Do we need to track how many steps the steppers took and add them to the GoHome calculation? + // If so, we need to remember where we were when we started the guide pulse. Then at the end, + // we can calculate the difference. Ignore DEC Guide for now. + // TODO: Take guide pulses on DEC into account - switch (direction) - { - case NORTH: - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC base speed : %f", decGuidingSpeed); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC guide speed : %f", DEC_PULSE_MULTIPLIER * decGuidingSpeed); - _stepperGUIDE->setSpeed(DEC_PULSE_MULTIPLIER * decGuidingSpeed); - _stepperGuidePosAtGuideStart = _stepperGUIDE->currentPosition(); - _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC; - _guideDecEndTime = millis() + duration; - break; + switch (direction) + { + case NORTH: + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC base speed : %f", decGuidingSpeed); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, + "[GUIDE]: guidePulse: DEC guide speed : %f", + DEC_PULSE_MULTIPLIER * decGuidingSpeed); + _stepperGUIDE->setSpeed(DEC_PULSE_MULTIPLIER * decGuidingSpeed); + _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC; + _guideDecEndTime = millis() + duration; + break; - case SOUTH: - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC base speed : %f", decGuidingSpeed); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC guide speed : %f", -DEC_PULSE_MULTIPLIER * decGuidingSpeed); - _stepperGUIDE->setSpeed(-DEC_PULSE_MULTIPLIER * decGuidingSpeed); - _stepperGuidePosAtGuideStart = _stepperGUIDE->currentPosition(); - _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC; - _guideDecEndTime = millis() + duration; - break; + case SOUTH: + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: DEC base speed : %f", decGuidingSpeed); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, + "[GUIDE]: guidePulse: DEC guide speed : %f", + -DEC_PULSE_MULTIPLIER * decGuidingSpeed); + _stepperGUIDE->setSpeed(-DEC_PULSE_MULTIPLIER * decGuidingSpeed); + _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC; + _guideDecEndTime = millis() + duration; + break; - case WEST: - // We were in tracking mode before guiding, so no need to update microstepping mode on RA driver - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA base speed : %f", raGuidingSpeed); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA speed factor : %f", _trackingSpeedCalibration); - raGuidingSpeed *= _trackingSpeedCalibration; - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA adjusted speed : %f", raGuidingSpeed); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, - "[GUIDE]: guidePulse: RA guide speed : %f (%f x adjusted speed)", - (RA_PULSE_MULTIPLIER * raGuidingSpeed), - RA_PULSE_MULTIPLIER); - _stepperTrkPosAtGuideStart = _stepperTRK->currentPosition(); - _stepperTRK->setSpeed(RA_PULSE_MULTIPLIER * raGuidingSpeed); // Faster than siderael - _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA; - _guideRaEndTime = millis() + duration; - break; + case WEST: + // We were in tracking mode before guiding, so no need to update microstepping mode on RA driver + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA base speed : %f", raGuidingSpeed); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA speed factor : %f", _trackingSpeedCalibration); + raGuidingSpeed *= _trackingSpeedCalibration; + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA adjusted speed : %f", raGuidingSpeed); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, + "[GUIDE]: guidePulse: RA guide speed : %f (%f x adjusted speed)", + (RA_PULSE_MULTIPLIER * raGuidingSpeed), + RA_PULSE_MULTIPLIER); + _stepperTRK->setSpeed(RA_PULSE_MULTIPLIER * raGuidingSpeed); // Faster than siderael + _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA; + _guideRaEndTime = millis() + duration; + break; - case EAST: - // We were in tracking mode before guiding, so no need to update microstepping mode on RA driver - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA base speed : %f", raGuidingSpeed); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA speed factor : %f", _trackingSpeedCalibration); - raGuidingSpeed *= _trackingSpeedCalibration; - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA adjusted speed : %f", raGuidingSpeed); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, - "[GUIDE]: guidePulse: RA guide speed : %f (%f x adjusted speed)", - (2.0 - RA_PULSE_MULTIPLIER) * raGuidingSpeed, - (2.0 - RA_PULSE_MULTIPLIER)); - _stepperTrkPosAtGuideStart = _stepperTRK->currentPosition(); - _stepperTRK->setSpeed(raGuidingSpeed * (2.0f - RA_PULSE_MULTIPLIER)); // Slower than siderael - _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA; - _guideRaEndTime = millis() + duration; - break; + case EAST: + // We were in tracking mode before guiding, so no need to update microstepping mode on RA driver + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA base speed : %f", raGuidingSpeed); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA speed factor : %f", _trackingSpeedCalibration); + raGuidingSpeed *= _trackingSpeedCalibration; + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: guidePulse: RA adjusted speed : %f", raGuidingSpeed); + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, + "[GUIDE]: guidePulse: RA guide speed : %f (%f x adjusted speed)", + (2.0 - RA_PULSE_MULTIPLIER * raGuidingSpeed), + (2.0 - RA_PULSE_MULTIPLIER)); + _stepperTRK->setSpeed(raGuidingSpeed * (2.0f - RA_PULSE_MULTIPLIER)); // Slower than siderael + _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA; + _guideRaEndTime = millis() + duration; + break; + } } // Since we will not be updating the display during a guide pulse, update the display here. #if INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE From 9a6e776528c1961995ebfba507106deaed1628a1 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 21 Feb 2025 09:23:06 -0800 Subject: [PATCH 3/8] V1.13.14 - Updates - Improved Serial command handling (made it less 'blocking'), which should improve general performance - Guiding now updates RA/DEC coordinates - Guide pulses are ignored when tracking is disabled (for example, when at the limits) --- Changelog.md | 6 +++++- Version.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6918ccc0..66ff7bdb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +**V1.13.14 - Updates** +- Improved Serial command handling (made it less 'blocking'), which should improve general performance +- Guiding now updates RA/DEC coordinates +- Guide pulses are ignored when tracking is disabled (for example, when at the limits) + **V1.13.13 - Updates** - Improved Meade command documentation - Fixed a bug that was not correctly showing the stepper direction in the :GX# command reply./ @@ -44,7 +49,6 @@ NOTE: Make sure to do a Factory Reset when using this version. - Lowered ESP32 second core priority - Added support for informational display - You must upgrade to OATControl V1.1.2.0 to use with this version (at least if you want to use teh DEC park/unpark feature) - **V1.13.2 - Updates** - Fix for RA steps being incorrectly set on every boot. diff --git a/Version.h b/Version.h index 7d49180c..d7ea4141 100644 --- a/Version.h +++ b/Version.h @@ -3,4 +3,4 @@ // Also, numbers are interpreted as simple numbers. _ __ _ // So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/ -#define VERSION "V1.13.13" +#define VERSION "V1.13.14" From 68e4c5a700d636cd842bb6098c5fc42068349a53 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 21 Feb 2025 09:28:27 -0800 Subject: [PATCH 4/8] Lint fixes --- src/Mount.cpp | 6 +++--- src/f_serial.hpp | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Mount.cpp b/src/Mount.cpp index 00d8a757..5c98229b 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -349,7 +349,7 @@ void Mount::configureAZStepper(byte pin1, byte pin2, int maxSpeed, int maxAccele #ifdef NEW_STEPPER_LIB _stepperAZ = new StepperAzSlew(AccelStepper::DRIVER, pin1, pin2); #else - _stepperAZ = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); + _stepperAZ = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); #endif _stepperAZ->setMaxSpeed(maxSpeed); _stepperAZ->setAcceleration(maxAcceleration); @@ -367,7 +367,7 @@ void Mount::configureALTStepper(byte pin1, byte pin2, int maxSpeed, int maxAccel #ifdef NEW_STEPPER_LIB _stepperALT = new StepperAltSlew(AccelStepper::DRIVER, pin1, pin2); #else - _stepperALT = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); + _stepperALT = new AccelStepper(AccelStepper::DRIVER, pin1, pin2); #endif _stepperALT->setMaxSpeed(maxSpeed); _stepperALT->setAcceleration(maxAcceleration); @@ -1893,7 +1893,7 @@ void Mount::getAZALTPositions(long &azPos, long &altPos) #if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) azPos = _stepperAZ->currentPosition(); #else - azPos = 0; + azPos = 0; #endif #if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE) altPos = _stepperALT->currentPosition(); diff --git a/src/f_serial.hpp b/src/f_serial.hpp index 4e4771b0..2af2b337 100644 --- a/src/f_serial.hpp +++ b/src/f_serial.hpp @@ -123,7 +123,7 @@ void processSerialData() // When debugging, only print the result to Serial if we're on seperate ports. #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1) Serial.print('P'); - #endif + #endif index = 0; } else @@ -132,18 +132,18 @@ void processSerialData() { // Ignoring trailing hash buffer[index] = 0; - String inCmd = String(buffer); + String inCmd = String(buffer); LOG(DEBUG_SERIAL, "[SERIAL]: ReceivedCommand(%d chars): [%s]", inCmd.length(), inCmd.c_str()); String retVal = MeadeCommandProcessor::instance()->processCommand(inCmd); if (retVal != "") { LOG(DEBUG_SERIAL, "[SERIAL]: RepliedWith: [%s]", retVal.c_str()); - // When not debugging, print the result to the serial port . - // When debugging, only print the result to Serial if we're on seperate ports. - #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1) + // When not debugging, print the result to the serial port . + // When debugging, only print the result to Serial if we're on seperate ports. + #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1) Serial.print(retVal); - #endif + #endif } // Wait for next command index = 0; From f4a25be7b72f0fcdbaecdfa96534ee7842dfa1ef Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 4 Mar 2025 15:40:00 -0800 Subject: [PATCH 5/8] Fixed comments and simplified expression --- src/Mount.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mount.cpp b/src/Mount.cpp index 5c98229b..be747058 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -1572,12 +1572,12 @@ void Mount::stopGuiding(bool ra, bool dec) long extraSteps = 0; if (_stepperTRK->speed() < _trackingSpeed) { - // EAST (1.5x), faster so we need 1/3 of the steps - extraSteps = -((1.0 / (2.0 - RA_PULSE_MULTIPLIER)) - 1.0) * raStepsDuringGuide; + // EAST (0.5) - slower so we need all the steps (with a 1.5 multiplier) + extraSteps = (1.0 - (1.0 / (2.0 - RA_PULSE_MULTIPLIER))) * raStepsDuringGuide; } else { - // WEST (0.5) + // WEST (1.5x), faster so we need 1/3 of the steps (with a 1.5 multiplier) extraSteps = (1.0 - (1.0 / RA_PULSE_MULTIPLIER)) * raStepsDuringGuide; } _stepperTRK->setSpeed(_trackingSpeed); From 5d5003810a3ce5a55ff5aff2dc4ffc67af3647d8 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 6 Mar 2025 20:43:18 -0800 Subject: [PATCH 6/8] Revert coordinate updates on guiding --- src/Mount.cpp | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/Mount.cpp b/src/Mount.cpp index be747058..6ff13987 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -1566,28 +1566,9 @@ void Mount::stopGuiding(bool ra, bool dec) // Stop RA guide first, since it's just a speed change back to tracking speed if (ra && (_mountStatus & STATUS_GUIDE_PULSE_RA)) { - long raStepsDuringGuide = _stepperTRK->currentPosition() - _stepperTrkPosAtGuideStart; LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: TRK stop guide at : %l", _stepperTRK->currentPosition()); - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: TRK steps moved : %l", raStepsDuringGuide); - long extraSteps = 0; - if (_stepperTRK->speed() < _trackingSpeed) - { - // EAST (0.5) - slower so we need all the steps (with a 1.5 multiplier) - extraSteps = (1.0 - (1.0 / (2.0 - RA_PULSE_MULTIPLIER))) * raStepsDuringGuide; - } - else - { - // WEST (1.5x), faster so we need 1/3 of the steps (with a 1.5 multiplier) - extraSteps = (1.0 - (1.0 / RA_PULSE_MULTIPLIER)) * raStepsDuringGuide; - } _stepperTRK->setSpeed(_trackingSpeed); - - // Calculate the extra steps moved during guiding on top of tracking and convert from TRK stepper to RA stepper - extraSteps *= RA_SLEW_MICROSTEPPING / RA_TRACKING_MICROSTEPPING; - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: RA extra steps : %l", extraSteps); - // Adjust RA coordinate by the amount of steps moved during guiding - _stepperRA->setCurrentPosition(_stepperRA->currentPosition() + extraSteps); - + LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: TRK speed set to : %f", _trackingSpeed); _mountStatus &= ~STATUS_GUIDE_PULSE_RA; } @@ -1603,12 +1584,6 @@ void Mount::stopGuiding(bool ra, bool dec) _stepperGUIDE->run(); _stepperTRK->runSpeed(); } - long decStepsDuringGuide = _stepperGUIDE->currentPosition() - _stepperGuidePosAtGuideStart; - - LOG(DEBUG_STEPPERS | DEBUG_GUIDE, "[GUIDE]: stopGuide: DEC steps moved : %l", decStepsDuringGuide); - // Adjust DEC coordinate by the amount of steps moved during guiding - _stepperDEC->setCurrentPosition(_stepperDEC->currentPosition() - + decStepsDuringGuide * DEC_SLEW_MICROSTEPPING / DEC_GUIDE_MICROSTEPPING); _mountStatus &= ~STATUS_GUIDE_PULSE_DEC; } From 86976209bea4affbbf12420939a86f73bd0ab6e5 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 6 Mar 2025 20:49:41 -0800 Subject: [PATCH 7/8] More fixes --- Changelog.md | 1 - src/Mount.hpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 66ff7bdb..41ce3607 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,5 @@ **V1.13.14 - Updates** - Improved Serial command handling (made it less 'blocking'), which should improve general performance -- Guiding now updates RA/DEC coordinates - Guide pulses are ignored when tracking is disabled (for example, when at the limits) **V1.13.13 - Updates** diff --git a/src/Mount.hpp b/src/Mount.hpp index 40edd450..80d53351 100644 --- a/src/Mount.hpp +++ b/src/Mount.hpp @@ -654,8 +654,6 @@ class Mount unsigned long _guideRaEndTime; unsigned long _guideDecEndTime; - long _stepperGuidePosAtGuideStart; - long _stepperTrkPosAtGuideStart; unsigned long _lastMountPrint = 0; float _trackingSpeed; // RA u-steps/sec when in tracking mode float _trackingSpeedCalibration; // Dimensionless, very close to 1.0 From 07231ad04e8965972df5c8cffee836f98bf74e15 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 8 Mar 2025 14:25:31 -0800 Subject: [PATCH 8/8] PR Feedback --- src/HallSensorHoming.cpp | 9 ++++++++ src/f_serial.hpp | 46 ++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/HallSensorHoming.cpp b/src/HallSensorHoming.cpp index a53704b4..57a289a9 100644 --- a/src/HallSensorHoming.cpp +++ b/src/HallSensorHoming.cpp @@ -210,6 +210,7 @@ void HallSensorHoming::processHomingProgress() { // First time the pin has triggered, record that position _homingData.position[HOMING_START_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis); + LOG(DEBUG_STEPPERS, "[HOMING]: Potentially found start of sensor at %l", _homingData.position[HOMING_START_PIN_POSITION]); @@ -230,6 +231,10 @@ void HallSensorHoming::processHomingProgress() // Make sure we continue moving far enough to reach end long distance = _homingData.initialDir * _stepsPerDegree * _homingData.searchDistance; _pMount->moveStepperBy(_axis, distance); + LOG(DEBUG_STEPPERS, + "[HOMING]: Making sure stepper keeps going by another %l steps. New target is %l", + distance, + _pMount->getCurrentStepperPosition(_axis) + distance); _homingData.lastPinState = homingPinState; _homingData.pinChangeCount = 0; @@ -289,6 +294,10 @@ void HallSensorHoming::processHomingProgress() // Make sure we continue moving far enough to reach end long distance = -_homingData.initialDir * _stepsPerDegree * _homingData.searchDistance; _pMount->moveStepperBy(_axis, distance); + LOG(DEBUG_STEPPERS, + "[HOMING]: Making sure stepper keeps going by another %l steps. New target is %l", + distance, + _pMount->getCurrentStepperPosition(_axis) + distance); _homingData.lastPinState = homingPinState; _homingData.pinChangeCount = 0; diff --git a/src/f_serial.hpp b/src/f_serial.hpp index 2af2b337..ad3741a7 100644 --- a/src/f_serial.hpp +++ b/src/f_serial.hpp @@ -16,7 +16,6 @@ void processSerialData(); // The main loop when under serial control void serialLoop() { - //Serial.print('.'); mount.loop(); mount.displayStepperPositionThrottled(); @@ -126,36 +125,33 @@ void processSerialData() #endif index = 0; } - else + else if (buffer[index] == '#') { - if (buffer[index] == '#') - { - // Ignoring trailing hash - buffer[index] = 0; - String inCmd = String(buffer); - LOG(DEBUG_SERIAL, "[SERIAL]: ReceivedCommand(%d chars): [%s]", inCmd.length(), inCmd.c_str()); + // Ignoring trailing hash + buffer[index] = '\0'; + const String inCmd = String(buffer); + LOG(DEBUG_SERIAL, "[SERIAL]: ReceivedCommand(%d chars): [%s]", inCmd.length(), inCmd.c_str()); - String retVal = MeadeCommandProcessor::instance()->processCommand(inCmd); - if (retVal != "") - { - LOG(DEBUG_SERIAL, "[SERIAL]: RepliedWith: [%s]", retVal.c_str()); - // When not debugging, print the result to the serial port . - // When debugging, only print the result to Serial if we're on seperate ports. + const String retVal = MeadeCommandProcessor::instance()->processCommand(inCmd); + if (retVal != "") + { + LOG(DEBUG_SERIAL, "[SERIAL]: RepliedWith: [%s]", retVal.c_str()); + // When not debugging, print the result to the serial port . + // When debugging, only print the result to Serial if we're on seperate ports. #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1) - Serial.print(retVal); + Serial.print(retVal); #endif - } - // Wait for next command - index = 0; } - else if (buffer[index] > 31) + // Wait for next command + index = 0; + } + else if (buffer[index] >= ' ') + { + index++; + if (index >= sizeof(buffer)) { - index++; - if (index >= sizeof(buffer)) - { - LOG(DEBUG_SERIAL, "[SERIAL]: Command buffer overflow! Ignoring received data."); - index = 0; - } + LOG(DEBUG_SERIAL, "[SERIAL]: Command buffer overflow! Ignoring received data."); + index = 0; } } }