diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-09-08 21:27:38 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-09-08 21:27:38 +0300 |
commit | 7d449836123f59ef1c587cd981a88ea7c63518ac (patch) | |
tree | e2f7ee39df44ba1a12bf5d318f96fe3cc977ee28 /src/GCodes/GCodes.cpp | |
parent | 43119b53b6751d628b105f40382c8e686c807ab7 (diff) |
Work on restartable macros + preparatory work for multiple streams
Diffstat (limited to 'src/GCodes/GCodes.cpp')
-rw-r--r-- | src/GCodes/GCodes.cpp | 563 |
1 files changed, 285 insertions, 278 deletions
diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp index bea9a0ff..c5fbfc71 100644 --- a/src/GCodes/GCodes.cpp +++ b/src/GCodes/GCodes.cpp @@ -239,9 +239,9 @@ void GCodes::Reset() noexcept } } - currentCoordinateSystem = 0; + moveState.currentCoordinateSystem = 0; - for (float& f : moveBuffer.coords) + for (float& f : moveState.coords) { f = 0.0; // clear out all axis and extruder coordinates } @@ -253,16 +253,16 @@ void GCodes::Reset() noexcept f = 0.0; // clear babystepping before calling ToolOffsetInverseTransform } - currentZHop = 0.0; // clear this before calling ToolOffsetInverseTransform + moveState.currentZHop = 0.0; // clear this before calling ToolOffsetInverseTransform newToolNumber = -1; - moveBuffer.tool = nullptr; - moveBuffer.virtualExtruderPosition = 0.0; + moveState.tool = nullptr; + moveState.virtualExtruderPosition = 0.0; #if SUPPORT_LASER || SUPPORT_IOBITS - moveBuffer.laserPwmOrIoBits.Clear(); + moveState.laserPwmOrIoBits.Clear(); #endif - reprap.GetMove().GetKinematics().GetAssumedInitialPosition(numVisibleAxes, moveBuffer.coords); - ToolOffsetInverseTransform(moveBuffer.coords, currentUserPosition); + reprap.GetMove().GetKinematics().GetAssumedInitialPosition(numVisibleAxes, moveState.coords); + ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); updateUserPosition = false; for (RestorePoint& rp : numberedRestorePoints) @@ -282,6 +282,7 @@ void GCodes::Reset() noexcept lastDuration = 0; pauseState = PauseState::notPaused; + pausedInMacro = false; #if HAS_VOLTAGE_MONITOR isPowerFailPaused = false; #endif @@ -296,7 +297,7 @@ void GCodes::Reset() noexcept #endif printFilePositionAtMacroStart = 0; deferredPauseCommandPending = nullptr; - moveBuffer.filePos = noFilePosition; + moveState.filePos = noFilePosition; firmwareUpdateModuleMap.Clear(); isFlashing = false; isFlashingPanelDue = false; @@ -514,7 +515,7 @@ bool GCodes::SpinGCodeBuffer(GCodeBuffer& gb) noexcept if (gb.LatestMachineState().messageAcknowledged) { const bool wasCancelled = gb.LatestMachineState().messageCancelled; - gb.PopState(false); // this could fail if the current macro has already been aborted + gb.PopState(); // this could fail if the current macro has already been aborted if (wasCancelled) { @@ -662,7 +663,7 @@ bool GCodes::DoFilePrint(GCodeBuffer& gb, const StringRef& reply) noexcept CheckFinishedRunningConfigFile(gb); // Pop the stack and notify the SBC that we have closed the file - Pop(gb, false); + Pop(gb); gb.Init(); gb.LatestMachineState().firstCommandAfterRestart = false; @@ -796,7 +797,7 @@ bool GCodes::DoFilePrint(GCodeBuffer& gb, const StringRef& reply) noexcept gb.GetFileInput()->Reset(fd); fd.Close(); CheckFinishedRunningConfigFile(gb); - Pop(gb, false); + Pop(gb); gb.Init(); if (gb.GetState() == GCodeState::normal) { @@ -818,8 +819,8 @@ void GCodes::EndSimulation(GCodeBuffer *gb) noexcept // Ending a simulation, so restore the position RestorePosition(simulationRestorePoint, gb); reprap.SelectTool(simulationRestorePoint.toolNumber, true); - ToolOffsetTransform(currentUserPosition, moveBuffer.coords); - reprap.GetMove().SetNewPosition(moveBuffer.coords, true); + ToolOffsetTransform(moveState.currentUserPosition, moveState.coords); + reprap.GetMove().SetNewPosition(moveState.coords, true); axesVirtuallyHomed = axesHomed; } @@ -851,7 +852,7 @@ void GCodes::CheckTriggers() noexcept { triggersPending.ClearBit(lowestTriggerPending); // ignore a pause trigger if we are already paused or not printing } - else if (LockMovement(*triggerGCode)) // need to lock movement before executing the pause macro + else if (LockMovement(*triggerGCode)) // need to lock movement before executing the pause macro { triggersPending.ClearBit(lowestTriggerPending); // clear the trigger DoPause(*triggerGCode, PauseReason::trigger, "Print paused by external trigger"); @@ -907,6 +908,7 @@ void GCodes::DoEmergencyStop() noexcept // Pause the print. Before calling this, check that we are doing a file print that isn't already paused and get the movement lock. void GCodes::DoPause(GCodeBuffer& gb, PauseReason reason, const char *msg, uint16_t param) noexcept { + pausedInMacro = false; if (&gb == fileGCode) { // Pausing a file print because of a command in the file itself @@ -921,19 +923,19 @@ void GCodes::DoPause(GCodeBuffer& gb, PauseReason reason, const char *msg, uint1 if (movesSkipped) { // The PausePrint call has filled in the restore point with machine coordinates - ToolOffsetInverseTransform(pauseRestorePoint.moveCoords, currentUserPosition); // transform the returned coordinates to user coordinates + ToolOffsetInverseTransform(pauseRestorePoint.moveCoords, moveState.currentUserPosition); // transform the returned coordinates to user coordinates ClearMove(); } - else if (moveBuffer.segmentsLeft != 0) + else if (moveState.segmentsLeft != 0) { // We were not able to skip any moves, however we can skip the move that is waiting - pauseRestorePoint.virtualExtruderPosition = moveBuffer.virtualExtruderPosition; - pauseRestorePoint.filePos = moveBuffer.filePos; - pauseRestorePoint.feedRate = moveBuffer.feedRate; - pauseRestorePoint.proportionDone = moveBuffer.GetProportionDone(); - pauseRestorePoint.initialUserC0 = moveBuffer.initialUserC0; - pauseRestorePoint.initialUserC1 = moveBuffer.initialUserC1; - ToolOffsetInverseTransform(pauseRestorePoint.moveCoords, currentUserPosition); // transform the returned coordinates to user coordinates + pauseRestorePoint.virtualExtruderPosition = moveState.virtualExtruderPosition; + pauseRestorePoint.filePos = moveState.filePos; + pauseRestorePoint.feedRate = moveState.feedRate; + pauseRestorePoint.proportionDone = moveState.GetProportionDone(); + pauseRestorePoint.initialUserC0 = moveState.initialUserC0; + pauseRestorePoint.initialUserC1 = moveState.initialUserC1; + ToolOffsetInverseTransform(pauseRestorePoint.moveCoords, moveState.currentUserPosition); // transform the returned coordinates to user coordinates ClearMove(); } else @@ -946,15 +948,20 @@ void GCodes::DoPause(GCodeBuffer& gb, PauseReason reason, const char *msg, uint1 // TODO: when using RTOS there is a possible race condition in the following, // because we might try to pause when a waiting move has just been added but before the gcode buffer has been re-initialised ready for the next command pauseRestorePoint.filePos = GetPrintingFilePosition(); + while (fileGCode->IsDoingFileMacro()) // must call this after GetPrintingFilePosition because it changes IsDoingFileMacro + { + pausedInMacro = true; + fileGCode->PopState(); + } #if SUPPORT_LASER || SUPPORT_IOBITS - pauseRestorePoint.laserPwmOrIoBits = moveBuffer.laserPwmOrIoBits; + pauseRestorePoint.laserPwmOrIoBits = moveState.laserPwmOrIoBits; #endif } // Replace the paused machine coordinates by user coordinates, which we updated earlier if they were returned by Move::PausePrint for (size_t axis = 0; axis < numVisibleAxes; ++axis) { - pauseRestorePoint.moveCoords[axis] = currentUserPosition[axis]; + pauseRestorePoint.moveCoords[axis] = moveState.currentUserPosition[axis]; } #if HAS_LINUX_INTERFACE @@ -994,7 +1001,7 @@ void GCodes::DoPause(GCodeBuffer& gb, PauseReason reason, const char *msg, uint1 #if SUPPORT_LASER if (machineType == MachineType::laser) { - moveBuffer.laserPwmOrIoBits.laserPwm = 0; // turn off the laser when we start moving + moveState.laserPwmOrIoBits.laserPwm = 0; // turn off the laser when we start moving } #endif @@ -1140,21 +1147,21 @@ bool GCodes::DoEmergencyPause() noexcept if (movesSkipped) { // The PausePrint call has filled in the restore point with machine coordinates - ToolOffsetInverseTransform(pauseRestorePoint.moveCoords, currentUserPosition); // transform the returned coordinates to user coordinates + ToolOffsetInverseTransform(pauseRestorePoint.moveCoords, moveState.currentUserPosition); // transform the returned coordinates to user coordinates ClearMove(); } - else if (moveBuffer.segmentsLeft != 0 && moveBuffer.filePos != noFilePosition) + else if (moveState.segmentsLeft != 0 && moveState.filePos != noFilePosition) { // We were not able to skip any moves, however we can skip the remaining segments of this current move - ToolOffsetInverseTransform(moveBuffer.initialCoords, currentUserPosition); - pauseRestorePoint.feedRate = moveBuffer.feedRate; - pauseRestorePoint.virtualExtruderPosition = moveBuffer.virtualExtruderPosition; - pauseRestorePoint.filePos = moveBuffer.filePos; - pauseRestorePoint.proportionDone = moveBuffer.GetProportionDone(); - pauseRestorePoint.initialUserC0 = moveBuffer.initialUserC0; - pauseRestorePoint.initialUserC1 = moveBuffer.initialUserC1; + ToolOffsetInverseTransform(moveState.initialCoords, moveState.currentUserPosition); + pauseRestorePoint.feedRate = moveState.feedRate; + pauseRestorePoint.virtualExtruderPosition = moveState.virtualExtruderPosition; + pauseRestorePoint.filePos = moveState.filePos; + pauseRestorePoint.proportionDone = moveState.GetProportionDone(); + pauseRestorePoint.initialUserC0 = moveState.initialUserC0; + pauseRestorePoint.initialUserC1 = moveState.initialUserC1; #if SUPPORT_LASER || SUPPORT_IOBITS - pauseRestorePoint.laserPwmOrIoBits = moveBuffer.laserPwmOrIoBits; + pauseRestorePoint.laserPwmOrIoBits = moveState.laserPwmOrIoBits; #endif ClearMove(); } @@ -1168,7 +1175,7 @@ bool GCodes::DoEmergencyPause() noexcept pauseRestorePoint.proportionDone = 0.0; #if SUPPORT_LASER || SUPPORT_IOBITS - pauseRestorePoint.laserPwmOrIoBits = moveBuffer.laserPwmOrIoBits; + pauseRestorePoint.laserPwmOrIoBits = moveState.laserPwmOrIoBits; #endif } @@ -1185,7 +1192,7 @@ bool GCodes::DoEmergencyPause() noexcept // Replace the paused machine coordinates by user coordinates, which we updated earlier for (size_t axis = 0; axis < numVisibleAxes; ++axis) { - pauseRestorePoint.moveCoords[axis] = currentUserPosition[axis]; + pauseRestorePoint.moveCoords[axis] = moveState.currentUserPosition[axis]; } pauseRestorePoint.toolNumber = reprap.GetCurrentToolNumber(); @@ -1410,13 +1417,13 @@ void GCodes::SaveResumeInfo(bool wasPowerFailure) noexcept if (ok) { // Switch to the correct workplace. 'currentCoordinateSystem' is 0-based. - if (currentCoordinateSystem <= 5) + if (moveState.currentCoordinateSystem <= 5) { - buf.printf("G%u\n", 54 + currentCoordinateSystem); + buf.printf("G%u\n", 54 + moveState.currentCoordinateSystem); } else { - buf.printf("G59.%u\n", currentCoordinateSystem - 5); + buf.printf("G59.%u\n", moveState.currentCoordinateSystem - 5); } ok = f->Write(buf.c_str()); } @@ -1539,7 +1546,7 @@ void GCodes::SaveResumeInfo(bool wasPowerFailure) noexcept void GCodes::Diagnostics(MessageType mtype) noexcept { platform.Message(mtype, "=== GCodes ===\n"); - platform.MessageF(mtype, "Segments left: %u\n", moveBuffer.segmentsLeft); + platform.MessageF(mtype, "Segments left: %u\n", moveState.segmentsLeft); const GCodeBuffer * const movementOwner = resourceOwners[MoveResource]; platform.MessageF(mtype, "Movement lock held by %s\n", (movementOwner == nullptr) ? "null" : movementOwner->GetChannel().ToString()); @@ -1565,7 +1572,7 @@ bool GCodes::LockMovementAndWaitForStandstill(GCodeBuffer& gb) noexcept } // Last one gone? - if (moveBuffer.segmentsLeft != 0) + if (moveState.segmentsLeft != 0) { return false; } @@ -1609,11 +1616,11 @@ bool GCodes::Push(GCodeBuffer& gb, bool withinSameFile) } // Recover a saved state -void GCodes::Pop(GCodeBuffer& gb, bool withinSameFile) +void GCodes::Pop(GCodeBuffer& gb) { // FIXME If withinSameFile is false, we should pop all stack levels that have the same file (ID) // and output a warning message is the stack is popped more than once - if (!gb.PopState(withinSameFile)) + if (!gb.PopState()) { platform.Message(ErrorMessage, "Pop(): stack underflow\n"); } @@ -1627,32 +1634,32 @@ void GCodes::Pop(GCodeBuffer& gb, bool withinSameFile) const char * GCodes::LoadExtrusionAndFeedrateFromGCode(GCodeBuffer& gb, bool isPrintingMove) { // Deal with feed rate, also determine whether M220 and M221 speed and extrusion factors apply to this move - if (moveBuffer.isCoordinated || machineType == MachineType::fff) + if (moveState.isCoordinated || machineType == MachineType::fff) { - moveBuffer.applyM220M221 = (moveBuffer.moveType == 0 && isPrintingMove && !gb.IsDoingFileMacro()); + moveState.applyM220M221 = (moveState.moveType == 0 && isPrintingMove && !gb.IsDoingFileMacro()); if (gb.Seen(feedrateLetter)) { gb.LatestMachineState().feedRate = gb.GetSpeed(); // update requested speed, not allowing for speed factor } - moveBuffer.feedRate = (moveBuffer.applyM220M221) + moveState.feedRate = (moveState.applyM220M221) ? speedFactor * gb.LatestMachineState().feedRate : gb.LatestMachineState().feedRate; - moveBuffer.usingStandardFeedrate = true; + moveState.usingStandardFeedrate = true; } else { - moveBuffer.applyM220M221 = false; - moveBuffer.feedRate = ConvertSpeedFromMmPerMin(DefaultG0FeedRate); // use maximum feed rate, the M203 parameters will limit it - moveBuffer.usingStandardFeedrate = false; + moveState.applyM220M221 = false; + moveState.feedRate = ConvertSpeedFromMmPerMin(DefaultG0FeedRate); // use maximum feed rate, the M203 parameters will limit it + moveState.usingStandardFeedrate = false; } // Zero every extruder drive as some drives may not be moved for (size_t drive = numTotalAxes; drive < MaxAxesPlusExtruders; drive++) { - moveBuffer.coords[drive] = 0.0; + moveState.coords[drive] = 0.0; } - moveBuffer.hasPositiveExtrusion = false; - moveBuffer.virtualExtruderPosition = virtualExtruderPosition; // save this before we update it + moveState.hasPositiveExtrusion = false; + moveState.virtualExtruderPosition = virtualExtruderPosition; // save this before we update it ExtrudersBitmap extrudersMoving; // Check if we are extruding @@ -1691,14 +1698,14 @@ const char * GCodes::LoadExtrusionAndFeedrateFromGCode(GCodeBuffer& gb, bool isP if (requestedExtrusionAmount > 0.0) { - moveBuffer.hasPositiveExtrusion = true; + moveState.hasPositiveExtrusion = true; } // rawExtruderTotal is used to calculate print progress, so it must be based on the requested extrusion from the slicer // before accounting for mixing, extrusion factor etc. // We used to have 'isPrintingMove &&' in the condition too, but this excluded wipe-while-retracting moves, so it gave wrong results for % print complete. // We still exclude extrusion during tool changing and other macros, because that is extrusion not known to the slicer. - if (moveBuffer.moveType == 0 && !gb.IsDoingFileMacro()) + if (moveState.moveType == 0 && !gb.IsDoingFileMacro()) { rawExtruderTotal += requestedExtrusionAmount; } @@ -1716,21 +1723,21 @@ const char * GCodes::LoadExtrusionAndFeedrateFromGCode(GCodeBuffer& gb, bool isP { extrusionAmount *= volumetricExtrusionFactors[extruder]; } - if (eDrive == 0 && moveBuffer.moveType == 0 && !gb.IsDoingFileMacro()) + if (eDrive == 0 && moveState.moveType == 0 && !gb.IsDoingFileMacro()) { rawExtruderTotalByDrive[extruder] += extrusionAmount; } - moveBuffer.coords[ExtruderToLogicalDrive(extruder)] = (moveBuffer.applyM220M221) + moveState.coords[ExtruderToLogicalDrive(extruder)] = (moveState.applyM220M221) ? extrusionAmount * extrusionFactors[extruder] : extrusionAmount; extrudersMoving.SetBit(extruder); } } - if (!isPrintingMove && moveBuffer.usingStandardFeedrate) + if (!isPrintingMove && moveState.usingStandardFeedrate) { // For E3D: If the total mix ratio is greater than 1.0 then we should scale the feed rate accordingly, e.g. for dual serial extruder drives - moveBuffer.feedRate *= totalMix; + moveState.feedRate *= totalMix; } } else @@ -1747,7 +1754,7 @@ const char * GCodes::LoadExtrusionAndFeedrateFromGCode(GCodeBuffer& gb, bool isP { if (extrusionAmount > 0.0) { - moveBuffer.hasPositiveExtrusion = true; + moveState.hasPositiveExtrusion = true; } if (gb.LatestMachineState().volumetricExtrusion) @@ -1755,12 +1762,12 @@ const char * GCodes::LoadExtrusionAndFeedrateFromGCode(GCodeBuffer& gb, bool isP extrusionAmount *= volumetricExtrusionFactors[extruder]; } - if (eDrive < mc && moveBuffer.moveType == 0 && !gb.IsDoingFileMacro()) + if (eDrive < mc && moveState.moveType == 0 && !gb.IsDoingFileMacro()) { rawExtruderTotalByDrive[extruder] += extrusionAmount; rawExtruderTotal += extrusionAmount; } - moveBuffer.coords[ExtruderToLogicalDrive(extruder)] = (moveBuffer.applyM220M221) + moveState.coords[ExtruderToLogicalDrive(extruder)] = (moveState.applyM220M221) ? extrusionAmount * extrusionFactors[extruder] : extrusionAmount; extrudersMoving.SetBit(extruder); @@ -1775,7 +1782,7 @@ const char * GCodes::LoadExtrusionAndFeedrateFromGCode(GCodeBuffer& gb, bool isP } } - if (moveBuffer.moveType == 1 || moveBuffer.moveType == 4) + if (moveState.moveType == 1 || moveState.moveType == 4) { if (!platform.GetEndstops().EnableExtruderEndstops(extrudersMoving)) { @@ -1801,23 +1808,23 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e { if (moveFractionToSkip > 0.0) { - moveBuffer.initialUserC0 = restartInitialUserC0; - moveBuffer.initialUserC1 = restartInitialUserC1; + moveState.initialUserC0 = restartInitialUserC0; + moveState.initialUserC1 = restartInitialUserC1; } else { const unsigned int selectedPlane = gb.LatestMachineState().selectedPlane; - moveBuffer.initialUserC0 = currentUserPosition[(selectedPlane == 2) ? Y_AXIS : X_AXIS]; - moveBuffer.initialUserC1 = currentUserPosition[(selectedPlane == 0) ? Y_AXIS : Z_AXIS]; + moveState.initialUserC0 = moveState.currentUserPosition[(selectedPlane == 2) ? Y_AXIS : X_AXIS]; + moveState.initialUserC1 = moveState.currentUserPosition[(selectedPlane == 0) ? Y_AXIS : Z_AXIS]; } // Set up default move parameters - moveBuffer.isCoordinated = isCoordinated; - moveBuffer.checkEndstops = false; - moveBuffer.reduceAcceleration = false; - moveBuffer.moveType = 0; - moveBuffer.tool = reprap.GetCurrentTool(); - moveBuffer.usePressureAdvance = false; + moveState.isCoordinated = isCoordinated; + moveState.checkEndstops = false; + moveState.reduceAcceleration = false; + moveState.moveType = 0; + moveState.tool = reprap.GetCurrentTool(); + moveState.usePressureAdvance = false; axesToSenseLength.Clear(); // Check to see if the move is a 'homing' move that endstops are checked on. @@ -1831,8 +1838,8 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e { return false; } - moveBuffer.moveType = ival; - moveBuffer.tool = nullptr; + moveState.moveType = ival; + moveState.tool = nullptr; } if (!gb.Seen('H')) { @@ -1842,7 +1849,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e // Check for 'R' parameter to move relative to a restore point const RestorePoint * rp = nullptr; - if (moveBuffer.moveType == 0 && gb.Seen('R')) + if (moveState.moveType == 0 && gb.Seen('R')) { const uint32_t rParam = gb.GetUIValue(); if (rParam < ARRAY_SIZE(numberedRestorePoints)) @@ -1860,18 +1867,18 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e #if SUPPORT_LASER || SUPPORT_IOBITS if (rp != nullptr) { - moveBuffer.laserPwmOrIoBits = rp->laserPwmOrIoBits; + moveState.laserPwmOrIoBits = rp->laserPwmOrIoBits; } # if SUPPORT_LASER else if (machineType == MachineType::laser) { if (gb.Seen('S')) { - moveBuffer.laserPwmOrIoBits.laserPwm = ConvertLaserPwm(gb.GetFValue()); + moveState.laserPwmOrIoBits.laserPwm = ConvertLaserPwm(gb.GetFValue()); } - else if (moveBuffer.moveType != 0) + else if (moveState.moveType != 0) { - moveBuffer.laserPwmOrIoBits.laserPwm = 0; // it's a homing move or similar, so turn the laser off + moveState.laserPwmOrIoBits.laserPwm = 0; // it's a homing move or similar, so turn the laser off } else if (laserPowerSticky) { @@ -1880,7 +1887,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e } else { - moveBuffer.laserPwmOrIoBits.laserPwm = 0; + moveState.laserPwmOrIoBits.laserPwm = 0; } } # endif @@ -1890,7 +1897,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e // Update the iobits parameter if (gb.Seen('P')) { - moveBuffer.laserPwmOrIoBits.ioBits = (IoBits_t)gb.GetIValue(); + moveState.laserPwmOrIoBits.ioBits = (IoBits_t)gb.GetIValue(); } else { @@ -1900,20 +1907,20 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e # endif #endif - if (moveBuffer.moveType != 0) + if (moveState.moveType != 0) { // This may be a raw motor move, in which case we need the current raw motor positions in moveBuffer.coords. // If it isn't a raw motor move, it will still be applied without axis or bed transform applied, // so make sure the initial coordinates don't have those either to avoid unwanted Z movement. - reprap.GetMove().GetCurrentUserPosition(moveBuffer.coords, moveBuffer.moveType, reprap.GetCurrentTool()); + reprap.GetMove().GetCurrentUserPosition(moveState.coords, moveState.moveType, reprap.GetCurrentTool()); } // Set up the initial coordinates - memcpyf(moveBuffer.initialCoords, moveBuffer.coords, numVisibleAxes); + memcpyf(moveState.initialCoords, moveState.coords, numVisibleAxes); // Save the current position, we need it possibly later float initialUserPosition[MaxAxes]; - memcpyf(initialUserPosition, currentUserPosition, numVisibleAxes); + memcpyf(initialUserPosition, moveState.currentUserPosition, numVisibleAxes); AxesBitmap axesMentioned; for (size_t axis = 0; axis < numVisibleAxes; axis++) @@ -1921,7 +1928,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e if (gb.Seen(axisLetters[axis])) { // If it is a special move on a delta, movement must be relative. - if (moveBuffer.moveType != 0 && !gb.LatestMachineState().axesRelative && reprap.GetMove().GetKinematics().GetKinematicsType() == KinematicsType::linearDelta) + if (moveState.moveType != 0 && !gb.LatestMachineState().axesRelative && reprap.GetMove().GetKinematics().GetKinematicsType() == KinematicsType::linearDelta) { err = "G0/G1: attempt to move individual motors of a delta machine to absolute positions"; return true; @@ -1929,46 +1936,46 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e axesMentioned.SetBit(axis); const float moveArg = gb.GetDistance(); - if (moveBuffer.moveType != 0) + if (moveState.moveType != 0) { // Special moves update the move buffer directly, bypassing the user coordinates if (gb.LatestMachineState().axesRelative) { - moveBuffer.coords[axis] += moveArg * (1.0 - moveFractionToSkip); + moveState.coords[axis] += moveArg * (1.0 - moveFractionToSkip); } else { - moveBuffer.coords[axis] = moveArg; + moveState.coords[axis] = moveArg; } } else if (rp != nullptr) { - currentUserPosition[axis] = moveArg + rp->moveCoords[axis]; + moveState.currentUserPosition[axis] = moveArg + rp->moveCoords[axis]; // When a restore point is being used (G1 R parameter) then we used to set any coordinates that were not mentioned to the restore point values. // But that causes issues for tool change on IDEX machines because we end up restoring the U axis when we shouldn't. // So we no longer do that, and the user must mention any axes that he wants restored e.g. G1 R2 X0 Y0. } else if (gb.LatestMachineState().axesRelative) { - currentUserPosition[axis] += moveArg * (1.0 - moveFractionToSkip); + moveState.currentUserPosition[axis] += moveArg * (1.0 - moveFractionToSkip); } else if (gb.LatestMachineState().g53Active) { - currentUserPosition[axis] = moveArg + GetCurrentToolOffset(axis); // g53 ignores tool offsets as well as workplace coordinates + moveState.currentUserPosition[axis] = moveArg + GetCurrentToolOffset(axis); // g53 ignores tool offsets as well as workplace coordinates } else if (gb.LatestMachineState().runningSystemMacro) { - currentUserPosition[axis] = moveArg; // don't apply workplace offsets to commands in system macros + moveState.currentUserPosition[axis] = moveArg; // don't apply workplace offsets to commands in system macros } else { - currentUserPosition[axis] = moveArg + GetWorkplaceOffset(axis); + moveState.currentUserPosition[axis] = moveArg + GetWorkplaceOffset(axis); } } } // Check enough axes have been homed - switch (moveBuffer.moveType) + switch (moveState.moveType) { case 0: if (!doingManualBedProbe && CheckEnoughAxesHomed(axesMentioned)) @@ -1983,12 +1990,12 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e // no break case 1: case 4: - if (!platform.GetEndstops().EnableAxisEndstops(axesMentioned & AxesBitmap::MakeLowestNBits(numTotalAxes), moveBuffer.moveType == 1)) + if (!platform.GetEndstops().EnableAxisEndstops(axesMentioned & AxesBitmap::MakeLowestNBits(numTotalAxes), moveState.moveType == 1)) { err = "Failed to enable endstops"; return true; } - moveBuffer.checkEndstops = true; + moveState.checkEndstops = true; break; case 2: @@ -2002,7 +2009,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e return true; } - const bool isPrintingMove = moveBuffer.hasPositiveExtrusion && axesMentioned.IsNonEmpty(); + const bool isPrintingMove = moveState.hasPositiveExtrusion && axesMentioned.IsNonEmpty(); if (buildObjects.IsFirstMoveSincePrintingResumed()) // if this is the first move after skipping an object { if (isPrintingMove) @@ -2024,25 +2031,25 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e { // Update the object coordinates limits. For efficiency, we only update the final coordinate. // Except in the case of a straight line that is only one extrusion width wide, this is sufficient. - buildObjects.UpdateObjectCoordinates(currentUserPosition, axesMentioned); + buildObjects.UpdateObjectCoordinates(moveState.currentUserPosition, axesMentioned); } #endif // Set up the move. We must assign segmentsLeft last, so that when Move runs as a separate task the move won't be picked up by the Move process before it is complete. // Note that if this is an extruder-only move, we don't do axis movements to allow for tool offset changes, we defer those until an axis moves. - if (moveBuffer.moveType != 0) + if (moveState.moveType != 0) { // It's a raw motor move, so do it in a single segment and wait for it to complete - moveBuffer.totalSegments = 1; + moveState.totalSegments = 1; gb.SetState(GCodeState::waitingForSpecialMoveToComplete); } else if (axesMentioned.IsEmpty()) { - moveBuffer.totalSegments = 1; + moveState.totalSegments = 1; } else { - ToolOffsetTransform(currentUserPosition, moveBuffer.coords, axesMentioned); + ToolOffsetTransform(moveState.currentUserPosition, moveState.coords, axesMentioned); // apply tool offset, baby stepping, Z hop and axis scaling AxesBitmap effectiveAxesHomed = axesVirtuallyHomed; if (doingManualBedProbe) @@ -2050,7 +2057,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e effectiveAxesHomed.ClearBit(Z_AXIS); // if doing a manual Z probe, don't limit the Z movement } - const LimitPositionResult lp = reprap.GetMove().GetKinematics().LimitPosition(moveBuffer.coords, moveBuffer.initialCoords, numVisibleAxes, effectiveAxesHomed, moveBuffer.isCoordinated, limitAxes); + const LimitPositionResult lp = reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, moveState.initialCoords, numVisibleAxes, effectiveAxesHomed, moveState.isCoordinated, limitAxes); switch (lp) { case LimitPositionResult::adjusted: @@ -2060,7 +2067,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e err = "G0/G1: target position outside machine limits"; // it's a laser or CNC so this is a definite error return true; } - ToolOffsetInverseTransform(moveBuffer.coords, currentUserPosition); // make sure the limits are reflected in the user position + ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // make sure the limits are reflected in the user position if (lp == LimitPositionResult::adjusted) { break; // we can reach the intermediate positions, so nothing more to do @@ -2068,19 +2075,19 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e // no break case LimitPositionResult::intermediateUnreachable: - if ( moveBuffer.isCoordinated - && ( (machineType == MachineType::fff && !moveBuffer.hasPositiveExtrusion) + if ( moveState.isCoordinated + && ( (machineType == MachineType::fff && !moveState.hasPositiveExtrusion) #if SUPPORT_LASER || SUPPORT_IOBITS - || (machineType == MachineType::laser && moveBuffer.laserPwmOrIoBits.laserPwm == 0) + || (machineType == MachineType::laser && moveState.laserPwmOrIoBits.laserPwm == 0) #endif ) ) { // It's a coordinated travel move on a 3D printer or laser cutter, so see whether an uncoordinated move will work - const LimitPositionResult lp2 = reprap.GetMove().GetKinematics().LimitPosition(moveBuffer.coords, moveBuffer.initialCoords, numVisibleAxes, effectiveAxesHomed, false, limitAxes); + const LimitPositionResult lp2 = reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, moveState.initialCoords, numVisibleAxes, effectiveAxesHomed, false, limitAxes); if (lp2 == LimitPositionResult::ok) { - moveBuffer.isCoordinated = false; // change it to an uncoordinated move + moveState.isCoordinated = false; // change it to an uncoordinated move break; } } @@ -2104,30 +2111,30 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e { AxesBitmap axesMentionedExceptZ = axesMentioned; axesMentionedExceptZ.ClearBit(Z_AXIS); - moveBuffer.usePressureAdvance = moveBuffer.hasPositiveExtrusion && axesMentionedExceptZ.IsNonEmpty(); + moveState.usePressureAdvance = moveState.hasPositiveExtrusion && axesMentionedExceptZ.IsNonEmpty(); } // Apply segmentation if necessary. To speed up simulation on SCARA printers, we don't apply kinematics segmentation when simulating. // As soon as we set segmentsLeft nonzero, the Move process will assume that the move is ready to take, so this must be the last thing we do. const Kinematics& kin = reprap.GetMove().GetKinematics(); const SegmentationType st = kin.GetSegmentationType(); - if (st.useSegmentation && simulationMode != 1 && (moveBuffer.hasPositiveExtrusion || moveBuffer.isCoordinated || st.useG0Segmentation)) + if (st.useSegmentation && simulationMode != 1 && (moveState.hasPositiveExtrusion || moveState.isCoordinated || st.useG0Segmentation)) { // This kinematics approximates linear motion by means of segmentation - float moveLengthSquared = fsquare(currentUserPosition[X_AXIS] - initialUserPosition[X_AXIS]) + fsquare(currentUserPosition[Y_AXIS] - initialUserPosition[Y_AXIS]); + float moveLengthSquared = fsquare(moveState.currentUserPosition[X_AXIS] - initialUserPosition[X_AXIS]) + fsquare(moveState.currentUserPosition[Y_AXIS] - initialUserPosition[Y_AXIS]); if (st.useZSegmentation) { - moveLengthSquared += fsquare(currentUserPosition[Z_AXIS] - initialUserPosition[Z_AXIS]); + moveLengthSquared += fsquare(moveState.currentUserPosition[Z_AXIS] - initialUserPosition[Z_AXIS]); } const float moveLength = fastSqrtf(moveLengthSquared); - const float moveTime = moveLength/(moveBuffer.feedRate * StepClockRate); // this is a best-case time, often the move will take longer - moveBuffer.totalSegments = (unsigned int)max<long>(1, lrintf(min<float>(moveLength * kin.GetReciprocalMinSegmentLength(), moveTime * kin.GetSegmentsPerSecond()))); + const float moveTime = moveLength/(moveState.feedRate * StepClockRate); // this is a best-case time, often the move will take longer + moveState.totalSegments = (unsigned int)max<long>(1, lrintf(min<float>(moveLength * kin.GetReciprocalMinSegmentLength(), moveTime * kin.GetSegmentsPerSecond()))); } else { - moveBuffer.totalSegments = 1; + moveState.totalSegments = 1; } - if (reprap.GetMove().IsUsingMesh() && (moveBuffer.isCoordinated || machineType == MachineType::fff)) + if (reprap.GetMove().IsUsingMesh() && (moveState.isCoordinated || machineType == MachineType::fff)) { ReadLocker locker(reprap.GetMove().heightMapLock); const HeightMap& heightMap = reprap.GetMove().AccessHeightMap(); @@ -2135,18 +2142,18 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e const unsigned int minMeshSegments = max<unsigned int>( 1, heightMap.GetMinimumSegments( - currentUserPosition[grid.GetAxisNumber(0)] - initialUserPosition[grid.GetAxisNumber(0)], - currentUserPosition[grid.GetAxisNumber(1)] - initialUserPosition[grid.GetAxisNumber(1)] + moveState.currentUserPosition[grid.GetAxisNumber(0)] - initialUserPosition[grid.GetAxisNumber(0)], + moveState.currentUserPosition[grid.GetAxisNumber(1)] - initialUserPosition[grid.GetAxisNumber(1)] ) ); - if (minMeshSegments > moveBuffer.totalSegments) + if (minMeshSegments > moveState.totalSegments) { - moveBuffer.totalSegments = minMeshSegments; + moveState.totalSegments = minMeshSegments; } } } - moveBuffer.doingArcMove = false; + moveState.doingArcMove = false; FinaliseMove(gb); UnlockAll(gb); // allow pause err = nullptr; @@ -2167,13 +2174,13 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) if (moveFractionToSkip > 0.0) { - moveBuffer.initialUserC0 = restartInitialUserC0; - moveBuffer.initialUserC1 = restartInitialUserC1; + moveState.initialUserC0 = restartInitialUserC0; + moveState.initialUserC1 = restartInitialUserC1; } else { - moveBuffer.initialUserC0 = currentUserPosition[axis0]; - moveBuffer.initialUserC1 = currentUserPosition[axis1]; + moveState.initialUserC0 = moveState.currentUserPosition[axis0]; + moveState.initialUserC1 = moveState.currentUserPosition[axis1]; } // Get the axis parameters @@ -2183,7 +2190,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) newAxis0Pos = gb.GetDistance(); if (gb.LatestMachineState().axesRelative) { - newAxis0Pos += moveBuffer.initialUserC0; + newAxis0Pos += moveState.initialUserC0; } else if (gb.LatestMachineState().g53Active) { @@ -2196,7 +2203,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } else { - newAxis0Pos = moveBuffer.initialUserC0; + newAxis0Pos = moveState.initialUserC0; } if (gb.Seen(axisLetters[axis1])) @@ -2204,7 +2211,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) newAxis1Pos = gb.GetDistance(); if (gb.LatestMachineState().axesRelative) { - newAxis1Pos += moveBuffer.initialUserC1; + newAxis1Pos += moveState.initialUserC1; } else if (gb.LatestMachineState().g53Active) { @@ -2217,7 +2224,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } else { - newAxis1Pos = moveBuffer.initialUserC1; + newAxis1Pos = moveState.initialUserC1; } float iParam, jParam; @@ -2227,8 +2234,8 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) const float rParam = gb.GetDistance(); // Get the XY coordinates of the midpoints between the start and end points X and Y distances between start and end points - const float deltaAxis0 = newAxis0Pos - moveBuffer.initialUserC0; - const float deltaAxis1 = newAxis1Pos - moveBuffer.initialUserC1; + const float deltaAxis0 = newAxis0Pos - moveState.initialUserC0; + const float deltaAxis1 = newAxis1Pos - moveState.initialUserC1; const float dSquared = fsquare(deltaAxis0) + fsquare(deltaAxis1); // square of the distance between start and end points @@ -2295,19 +2302,19 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } } - memcpyf(moveBuffer.initialCoords, moveBuffer.coords, numVisibleAxes); + memcpyf(moveState.initialCoords, moveState.coords, numVisibleAxes); // Save the arc centre user coordinates for later - const float userArcCentreAxis0 = moveBuffer.initialUserC0 + iParam; - const float userArcCentreAxis1 = moveBuffer.initialUserC1 + jParam; + const float userArcCentreAxis0 = moveState.initialUserC0 + iParam; + const float userArcCentreAxis1 = moveState.initialUserC1 + jParam; // Work out the new user position - currentUserPosition[axis0] = newAxis0Pos; - currentUserPosition[axis1] = newAxis1Pos; + moveState.currentUserPosition[axis0] = newAxis0Pos; + moveState.currentUserPosition[axis1] = newAxis1Pos; // CNC machines usually do a full circle if the initial and final XY coordinates are the same. // Usually this is because X and Y were not given, but repeating the coordinates is permitted. - const bool wholeCircle = (moveBuffer.initialUserC0 == currentUserPosition[axis0] && moveBuffer.initialUserC1 == currentUserPosition[axis1]); + const bool wholeCircle = (moveState.initialUserC0 == moveState.currentUserPosition[axis0] && moveState.initialUserC1 == moveState.currentUserPosition[axis1]); // Get any additional axes AxesBitmap axesMentioned; @@ -2320,19 +2327,19 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) const float moveArg = gb.GetDistance(); if (gb.LatestMachineState().axesRelative) { - currentUserPosition[axis] += moveArg * (1.0 - moveFractionToSkip); + moveState.currentUserPosition[axis] += moveArg * (1.0 - moveFractionToSkip); } else if (gb.LatestMachineState().g53Active) { - currentUserPosition[axis] = moveArg + GetCurrentToolOffset(axis); // g53 ignores tool offsets as well as workplace coordinates + moveState.currentUserPosition[axis] = moveArg + GetCurrentToolOffset(axis); // g53 ignores tool offsets as well as workplace coordinates } else if (gb.LatestMachineState().runningSystemMacro) { - currentUserPosition[axis] = moveArg; // don't apply workplace offsets to commands in system macros + moveState.currentUserPosition[axis] = moveArg; // don't apply workplace offsets to commands in system macros } else { - currentUserPosition[axis] = moveArg + GetWorkplaceOffset(axis); + moveState.currentUserPosition[axis] = moveArg + GetWorkplaceOffset(axis); } axesMentioned.SetBit(axis); } @@ -2346,22 +2353,22 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } // Transform to machine coordinates and check that it is within limits - ToolOffsetTransform(currentUserPosition, moveBuffer.coords, axesMentioned); // set the final position - if (reprap.GetMove().GetKinematics().LimitPosition(moveBuffer.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, true, limitAxes) != LimitPositionResult::ok) + ToolOffsetTransform(moveState.currentUserPosition, moveState.coords, axesMentioned); // set the final position + if (reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, true, limitAxes) != LimitPositionResult::ok) { err = "G2/G3: outside machine limits"; // abandon the move return true; } // Compute the angle at which we stop - const float finalTheta = atan2(currentUserPosition[axis1] - userArcCentreAxis1, currentUserPosition[axis0] - userArcCentreAxis0); + const float finalTheta = atan2(moveState.currentUserPosition[axis1] - userArcCentreAxis1, moveState.currentUserPosition[axis0] - userArcCentreAxis0); // Set up default move parameters - moveBuffer.checkEndstops = false; - moveBuffer.reduceAcceleration = false; - moveBuffer.moveType = 0; - moveBuffer.tool = reprap.GetCurrentTool(); - moveBuffer.isCoordinated = true; + moveState.checkEndstops = false; + moveState.reduceAcceleration = false; + moveState.moveType = 0; + moveState.tool = reprap.GetCurrentTool(); + moveState.isCoordinated = true; // Set up the arc centre coordinates and record which axes behave like an X axis. // The I and J parameters are always relative to present position. @@ -2372,11 +2379,11 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) { if (axis0Mapping.IsBitSet(axis)) { - moveBuffer.arcCentre[axis] = (userArcCentreAxis0 * axisScaleFactors[axis]) + currentBabyStepOffsets[axis] - Tool::GetOffset(reprap.GetCurrentTool(), axis); + moveState.arcCentre[axis] = (userArcCentreAxis0 * axisScaleFactors[axis]) + currentBabyStepOffsets[axis] - Tool::GetOffset(reprap.GetCurrentTool(), axis); } else if (axis1Mapping.IsBitSet(axis)) { - moveBuffer.arcCentre[axis] = (userArcCentreAxis1 * axisScaleFactors[axis]) + currentBabyStepOffsets[axis] - Tool::GetOffset(reprap.GetCurrentTool(), axis); + moveState.arcCentre[axis] = (userArcCentreAxis1 * axisScaleFactors[axis]) + currentBabyStepOffsets[axis] - Tool::GetOffset(reprap.GetCurrentTool(), axis); } } @@ -2388,7 +2395,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) if (buildObjects.IsFirstMoveSincePrintingResumed()) { - if (moveBuffer.hasPositiveExtrusion) // check whether this is the first move after skipping an object and is extruding + if (moveState.hasPositiveExtrusion) // check whether this is the first move after skipping an object and is extruding { if (TravelToStartPoint(gb)) // don't start a printing move from the wrong point { @@ -2403,11 +2410,11 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } #if TRACK_OBJECT_NAMES - if (moveBuffer.hasPositiveExtrusion) + if (moveState.hasPositiveExtrusion) { //TODO ideally we should calculate the min and max X and Y coordinates of the entire arc here and call UpdateObjectCoordinates twice. // But it is currently very rare to use G2/G3 with extrusion, so for now we don't bother. - buildObjects.UpdateObjectCoordinates(currentUserPosition, AxesBitmap::MakeLowestNBits(2)); + buildObjects.UpdateObjectCoordinates(moveState.currentUserPosition, AxesBitmap::MakeLowestNBits(2)); } #endif @@ -2416,7 +2423,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) { if (gb.Seen('S')) { - moveBuffer.laserPwmOrIoBits.laserPwm = ConvertLaserPwm(gb.GetFValue()); + moveState.laserPwmOrIoBits.laserPwm = ConvertLaserPwm(gb.GetFValue()); } else if (laserPowerSticky) { @@ -2424,7 +2431,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } else { - moveBuffer.laserPwmOrIoBits.laserPwm = 0; + moveState.laserPwmOrIoBits.laserPwm = 0; } } # if SUPPORT_IOBITS @@ -2436,7 +2443,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) // Update the iobits parameter if (gb.Seen('P')) { - moveBuffer.laserPwmOrIoBits.ioBits = (IoBits_t)gb.GetIValue(); + moveState.laserPwmOrIoBits.ioBits = (IoBits_t)gb.GetIValue(); } else { @@ -2445,10 +2452,10 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } #endif - moveBuffer.usePressureAdvance = moveBuffer.hasPositiveExtrusion; + moveState.usePressureAdvance = moveState.hasPositiveExtrusion; - moveBuffer.arcRadius = fastSqrtf(iParam * iParam + jParam * jParam); - moveBuffer.arcCurrentAngle = atan2(-jParam, -iParam); + moveState.arcRadius = fastSqrtf(iParam * iParam + jParam * jParam); + moveState.arcCurrentAngle = atan2(-jParam, -iParam); // Calculate the total angle moved, which depends on which way round we are going float totalArc; @@ -2458,7 +2465,7 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) } else { - totalArc = (clockwise) ? moveBuffer.arcCurrentAngle - finalTheta : finalTheta - moveBuffer.arcCurrentAngle; + totalArc = (clockwise) ? moveState.arcCurrentAngle - finalTheta : finalTheta - moveState.arcCurrentAngle; if (totalArc < 0.0) { totalArc += TwoPi; @@ -2470,24 +2477,24 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) // We leave out the square term because it is very small // In CNC applications even very small deviations can be visible, so we use a smaller segment length at low speeds const float arcSegmentLength = constrain<float> - ( min<float>(fastSqrtf(8 * moveBuffer.arcRadius * MaxArcDeviation), moveBuffer.feedRate * StepClockRate * (1.0/MinArcSegmentsPerSec)), + ( min<float>(fastSqrtf(8 * moveState.arcRadius * MaxArcDeviation), moveState.feedRate * StepClockRate * (1.0/MinArcSegmentsPerSec)), MinArcSegmentLength, MaxArcSegmentLength ); - moveBuffer.totalSegments = max<unsigned int>((unsigned int)((moveBuffer.arcRadius * totalArc)/arcSegmentLength + 0.8), 1u); - moveBuffer.arcAngleIncrement = totalArc/moveBuffer.totalSegments; + moveState.totalSegments = max<unsigned int>((unsigned int)((moveState.arcRadius * totalArc)/arcSegmentLength + 0.8), 1u); + moveState.arcAngleIncrement = totalArc/moveState.totalSegments; if (clockwise) { - moveBuffer.arcAngleIncrement = -moveBuffer.arcAngleIncrement; + moveState.arcAngleIncrement = -moveState.arcAngleIncrement; } - moveBuffer.angleIncrementSine = sinf(moveBuffer.arcAngleIncrement); - moveBuffer.angleIncrementCosine = cosf(moveBuffer.arcAngleIncrement); - moveBuffer.segmentsTillNextFullCalc = 0; + moveState.angleIncrementSine = sinf(moveState.arcAngleIncrement); + moveState.angleIncrementCosine = cosf(moveState.arcAngleIncrement); + moveState.segmentsTillNextFullCalc = 0; - moveBuffer.arcAxis0 = axis0; - moveBuffer.arcAxis1 = axis1; - moveBuffer.doingArcMove = true; - moveBuffer.xyPlane = (selectedPlane == 0); + moveState.arcAxis0 = axis0; + moveState.arcAxis1 = axis1; + moveState.doingArcMove = true; + moveState.xyPlane = (selectedPlane == 0); FinaliseMove(gb); UnlockAll(gb); // allow pause // debugPrintf("Radius %.2f, initial angle %.1f, increment %.1f, segments %u\n", @@ -2498,8 +2505,8 @@ bool GCodes::DoArcMove(GCodeBuffer& gb, bool clockwise, const char *& err) // Adjust the move parameters to account for segmentation and/or part of the move having been done already void GCodes::FinaliseMove(GCodeBuffer& gb) noexcept { - moveBuffer.canPauseAfter = !moveBuffer.checkEndstops && !moveBuffer.doingArcMove; // pausing during an arc move isn't safe because the arc centre get recomputed incorrectly when we resume - moveBuffer.filePos = (&gb == fileGCode) ? gb.GetFilePosition() : noFilePosition; + moveState.canPauseAfter = !moveState.checkEndstops && !moveState.doingArcMove; // pausing during an arc move isn't safe because the arc centre get recomputed incorrectly when we resume + moveState.filePos = (&gb == fileGCode) ? gb.GetFilePosition() : noFilePosition; gb.MotionCommanded(); if (buildObjects.IsCurrentObjectCancelled()) @@ -2513,31 +2520,31 @@ void GCodes::FinaliseMove(GCodeBuffer& gb) noexcept } else { - if (moveBuffer.totalSegments > 1) + if (moveState.totalSegments > 1) { - moveBuffer.segMoveState = SegmentedMoveState::active; + moveState.segMoveState = SegmentedMoveState::active; gb.SetState(GCodeState::waitingForSegmentedMoveToGo); for (size_t extruder = 0; extruder < numExtruders; ++extruder) { - moveBuffer.coords[ExtruderToLogicalDrive(extruder)] /= moveBuffer.totalSegments; // change the extrusion to extrusion per segment + moveState.coords[ExtruderToLogicalDrive(extruder)] /= moveState.totalSegments; // change the extrusion to extrusion per segment } if (moveFractionToSkip != 0.0) { - const float fseg = floor(moveBuffer.totalSegments * moveFractionToSkip); // round down to the start of a move - segmentsLeftToStartAt = moveBuffer.totalSegments - (unsigned int)fseg; - firstSegmentFractionToSkip = (moveFractionToSkip * moveBuffer.totalSegments) - fseg; + const float fseg = floor(moveState.totalSegments * moveFractionToSkip); // round down to the start of a move + segmentsLeftToStartAt = moveState.totalSegments - (unsigned int)fseg; + firstSegmentFractionToSkip = (moveFractionToSkip * moveState.totalSegments) - fseg; NewMoveAvailable(); return; } } else { - moveBuffer.segMoveState = SegmentedMoveState::inactive; + moveState.segMoveState = SegmentedMoveState::inactive; } - segmentsLeftToStartAt = moveBuffer.totalSegments; + segmentsLeftToStartAt = moveState.totalSegments; firstSegmentFractionToSkip = moveFractionToSkip; NewMoveAvailable(); @@ -2555,10 +2562,10 @@ bool GCodes::TravelToStartPoint(GCodeBuffer& gb) noexcept } SetMoveBufferDefaults(); - ToolOffsetTransform(currentUserPosition, moveBuffer.initialCoords); - ToolOffsetTransform(buildObjects.GetInitialPosition().moveCoords, moveBuffer.coords); - moveBuffer.feedRate = buildObjects.GetInitialPosition().feedRate; - moveBuffer.tool = reprap.GetCurrentTool(); + ToolOffsetTransform(moveState.currentUserPosition, moveState.initialCoords); + ToolOffsetTransform(buildObjects.GetInitialPosition().moveCoords, moveState.coords); + moveState.feedRate = buildObjects.GetInitialPosition().feedRate; + moveState.tool = reprap.GetCurrentTool(); NewMoveAvailable(1); return true; } @@ -2567,14 +2574,14 @@ bool GCodes::TravelToStartPoint(GCodeBuffer& gb) noexcept // Returns true if a new move was copied to 'm'. bool GCodes::ReadMove(RawMove& m) noexcept { - if (moveBuffer.segmentsLeft == 0) + if (moveState.segmentsLeft == 0) { return false; } - m = moveBuffer; + m = moveState; - if (moveBuffer.segmentsLeft == 1) + if (moveState.segmentsLeft == 1) { // If there is just 1 segment left, it doesn't matter if it is an arc move or not, just move to the end position if (segmentsLeftToStartAt == 1 && firstSegmentFractionToSkip != 0.0) // if this is the segment we are starting at and we need to skip some of it @@ -2586,7 +2593,7 @@ bool GCodes::ReadMove(RawMove& m) noexcept } } m.proportionDone = 1.0; - if (moveBuffer.doingArcMove) + if (moveState.doingArcMove) { m.canPauseAfter = true; // we can pause after the final segment of an arc move } @@ -2597,68 +2604,68 @@ bool GCodes::ReadMove(RawMove& m) noexcept // This move needs to be divided into 2 or more segments // Do the axes AxesBitmap axisMap0, axisMap1; - if (moveBuffer.doingArcMove) + if (moveState.doingArcMove) { - moveBuffer.arcCurrentAngle += moveBuffer.arcAngleIncrement; - if (moveBuffer.segmentsTillNextFullCalc == 0) + moveState.arcCurrentAngle += moveState.arcAngleIncrement; + if (moveState.segmentsTillNextFullCalc == 0) { // Do the full calculation - moveBuffer.segmentsTillNextFullCalc = SegmentsPerFulArcCalculation; - moveBuffer.currentAngleCosine = cosf(moveBuffer.arcCurrentAngle); - moveBuffer.currentAngleSine = sinf(moveBuffer.arcCurrentAngle); + moveState.segmentsTillNextFullCalc = SegmentsPerFulArcCalculation; + moveState.currentAngleCosine = cosf(moveState.arcCurrentAngle); + moveState.currentAngleSine = sinf(moveState.arcCurrentAngle); } else { // Speed up the computation by doing two multiplications and an addition or subtraction instead of a sine or cosine - --moveBuffer.segmentsTillNextFullCalc; - const float newCosine = moveBuffer.currentAngleCosine * moveBuffer.angleIncrementCosine - moveBuffer.currentAngleSine * moveBuffer.angleIncrementSine; - const float newSine = moveBuffer.currentAngleSine * moveBuffer.angleIncrementCosine + moveBuffer.currentAngleCosine * moveBuffer.angleIncrementSine; - moveBuffer.currentAngleCosine = newCosine; - moveBuffer.currentAngleSine = newSine; + --moveState.segmentsTillNextFullCalc; + const float newCosine = moveState.currentAngleCosine * moveState.angleIncrementCosine - moveState.currentAngleSine * moveState.angleIncrementSine; + const float newSine = moveState.currentAngleSine * moveState.angleIncrementCosine + moveState.currentAngleCosine * moveState.angleIncrementSine; + moveState.currentAngleCosine = newCosine; + moveState.currentAngleSine = newSine; } - axisMap0 = Tool::GetAxisMapping(moveBuffer.tool, moveBuffer.arcAxis0); - axisMap1 = Tool::GetAxisMapping(moveBuffer.tool, moveBuffer.arcAxis1); - moveBuffer.cosXyAngle = (moveBuffer.xyPlane) ? moveBuffer.angleIncrementCosine : 1.0; + axisMap0 = Tool::GetAxisMapping(moveState.tool, moveState.arcAxis0); + axisMap1 = Tool::GetAxisMapping(moveState.tool, moveState.arcAxis1); + moveState.cosXyAngle = (moveState.xyPlane) ? moveState.angleIncrementCosine : 1.0; } for (size_t drive = 0; drive < numVisibleAxes; ++drive) { - if (moveBuffer.doingArcMove && axisMap1.IsBitSet(drive)) + if (moveState.doingArcMove && axisMap1.IsBitSet(drive)) { // Axis1 or a substitute in the selected plane - moveBuffer.initialCoords[drive] = moveBuffer.arcCentre[drive] + moveBuffer.arcRadius * axisScaleFactors[drive] * moveBuffer.currentAngleSine; + moveState.initialCoords[drive] = moveState.arcCentre[drive] + moveState.arcRadius * axisScaleFactors[drive] * moveState.currentAngleSine; } - else if (moveBuffer.doingArcMove && axisMap0.IsBitSet(drive)) + else if (moveState.doingArcMove && axisMap0.IsBitSet(drive)) { // Axis0 or a substitute in the selected plane - moveBuffer.initialCoords[drive] = moveBuffer.arcCentre[drive] + moveBuffer.arcRadius * axisScaleFactors[drive] * moveBuffer.currentAngleCosine; + moveState.initialCoords[drive] = moveState.arcCentre[drive] + moveState.arcRadius * axisScaleFactors[drive] * moveState.currentAngleCosine; } else { // This axis is not moving in an arc - const float movementToDo = (moveBuffer.coords[drive] - moveBuffer.initialCoords[drive])/moveBuffer.segmentsLeft; - moveBuffer.initialCoords[drive] += movementToDo; + const float movementToDo = (moveState.coords[drive] - moveState.initialCoords[drive])/moveState.segmentsLeft; + moveState.initialCoords[drive] += movementToDo; } - m.coords[drive] = moveBuffer.initialCoords[drive]; + m.coords[drive] = moveState.initialCoords[drive]; } - if (segmentsLeftToStartAt < moveBuffer.segmentsLeft) + if (segmentsLeftToStartAt < moveState.segmentsLeft) { // We are resuming a print part way through a move and we printed this segment already - --moveBuffer.segmentsLeft; + --moveState.segmentsLeft; return false; } // Limit the end position at each segment. This is needed for arc moves on any printer, and for [segmented] straight moves on SCARA printers. if (reprap.GetMove().GetKinematics().LimitPosition(m.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, true, limitAxes) != LimitPositionResult::ok) { - moveBuffer.segMoveState = SegmentedMoveState::aborted; - moveBuffer.doingArcMove = false; - moveBuffer.segmentsLeft = 0; + moveState.segMoveState = SegmentedMoveState::aborted; + moveState.doingArcMove = false; + moveState.segmentsLeft = 0; return false; } - if (segmentsLeftToStartAt == moveBuffer.segmentsLeft && firstSegmentFractionToSkip != 0.0) // if this is the segment we are starting at and we need to skip some of it + if (segmentsLeftToStartAt == moveState.segmentsLeft && firstSegmentFractionToSkip != 0.0) // if this is the segment we are starting at and we need to skip some of it { // Reduce the extrusion by the amount to be skipped for (size_t extruder = 0; extruder < numExtruders; ++extruder) @@ -2666,9 +2673,9 @@ bool GCodes::ReadMove(RawMove& m) noexcept m.coords[ExtruderToLogicalDrive(extruder)] *= (1.0 - firstSegmentFractionToSkip); } } - --moveBuffer.segmentsLeft; + --moveState.segmentsLeft; - m.proportionDone = moveBuffer.GetProportionDone(); + m.proportionDone = moveState.GetProportionDone(); } return true; @@ -2678,13 +2685,13 @@ void GCodes::ClearMove() noexcept { TaskCriticalSectionLocker lock; // make sure that other tasks sees a consistent memory state - moveBuffer.segmentsLeft = 0; - moveBuffer.segMoveState = SegmentedMoveState::inactive; - moveBuffer.doingArcMove = false; - moveBuffer.checkEndstops = false; - moveBuffer.reduceAcceleration = false; - moveBuffer.moveType = 0; - moveBuffer.applyM220M221 = false; + moveState.segmentsLeft = 0; + moveState.segMoveState = SegmentedMoveState::inactive; + moveState.doingArcMove = false; + moveState.checkEndstops = false; + moveState.reduceAcceleration = false; + moveState.moveType = 0; + moveState.applyM220M221 = false; moveFractionToSkip = 0.0; } @@ -2693,9 +2700,9 @@ void GCodes::ClearMove() noexcept // then call this function to update SegmentsLeft safely in a multi-threaded environment void GCodes::NewMoveAvailable(unsigned int sl) noexcept { - moveBuffer.totalSegments = sl; + moveState.totalSegments = sl; __DMB(); // make sure that all the move details have been written first - moveBuffer.segmentsLeft = sl; // set the number of segments to indicate that a move is available to be taken + moveState.segmentsLeft = sl; // set the number of segments to indicate that a move is available to be taken reprap.GetMove().MoveAvailable(); // notify the Move task that we have a move } @@ -2703,9 +2710,9 @@ void GCodes::NewMoveAvailable(unsigned int sl) noexcept // This version is for when totalSegments has already be set up. void GCodes::NewMoveAvailable() noexcept { - const unsigned int sl = moveBuffer.totalSegments; + const unsigned int sl = moveState.totalSegments; __DMB(); // make sure that the move details have been written first - moveBuffer.segmentsLeft = sl; // set the number of segments to indicate that a move is available to be taken + moveState.segmentsLeft = sl; // set the number of segments to indicate that a move is available to be taken reprap.GetMove().MoveAvailable(); // notify the Move task that we have a move } @@ -2730,7 +2737,7 @@ void GCodes::EmergencyStop() noexcept } } #if SUPPORT_LASER - moveBuffer.laserPwmOrIoBits.laserPwm = 0; + moveState.laserPwmOrIoBits.laserPwm = 0; #endif } @@ -2888,7 +2895,7 @@ void GCodes::FileMacroCyclesReturn(GCodeBuffer& gb) noexcept gb.GetFileInput()->Reset(file); file.Close(); - gb.PopState(true); + gb.PopState(); #endif } @@ -2977,9 +2984,9 @@ GCodeResult GCodes::ExecuteG30(GCodeBuffer& gb, const StringRef& reply) else { // Set the specified probe point index to the specified coordinates - const float x = (gb.Seen(axisLetters[X_AXIS])) ? gb.GetFValue() : currentUserPosition[X_AXIS]; - const float y = (gb.Seen(axisLetters[Y_AXIS])) ? gb.GetFValue() : currentUserPosition[Y_AXIS]; - const float z = (gb.Seen(axisLetters[Z_AXIS])) ? gb.GetFValue() : currentUserPosition[Z_AXIS]; + const float x = (gb.Seen(axisLetters[X_AXIS])) ? gb.GetFValue() : moveState.currentUserPosition[X_AXIS]; + const float y = (gb.Seen(axisLetters[Y_AXIS])) ? gb.GetFValue() : moveState.currentUserPosition[Y_AXIS]; + const float z = (gb.Seen(axisLetters[Z_AXIS])) ? gb.GetFValue() : moveState.currentUserPosition[Z_AXIS]; reprap.GetMove().SetXYBedProbePoint((size_t)g30ProbePointIndex, x, y); if (z > SILLY_Z_VALUE) @@ -3205,8 +3212,8 @@ GCodeResult GCodes::SaveHeightMap(GCodeBuffer& gb, const StringRef& reply) const void GCodes::ClearBedMapping() { reprap.GetMove().SetIdentityTransform(); - reprap.GetMove().GetCurrentUserPosition(moveBuffer.coords, 0, reprap.GetCurrentTool()); - ToolOffsetInverseTransform(moveBuffer.coords, currentUserPosition); // update user coordinates to remove any height map offset there was at the current position + reprap.GetMove().GetCurrentUserPosition(moveState.coords, 0, reprap.GetCurrentTool()); + ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // update user coordinates to remove any height map offset there was at the current position } // Return the current coordinates as a printable string. @@ -3241,7 +3248,7 @@ void GCodes::GetCurrentCoordinates(const StringRef& s) const noexcept // Add the machine coordinates because they may be different from the user coordinates under some conditions s.cat(" Machine"); float machineCoordinates[MaxAxes]; - ToolOffsetTransform(currentUserPosition, machineCoordinates); + ToolOffsetTransform(moveState.currentUserPosition, machineCoordinates); for (size_t axis = 0; axis < numVisibleAxes; ++axis) { s.catf(" %.3f", HideNan(machineCoordinates[axis])); @@ -3406,7 +3413,7 @@ GCodeResult GCodes::SetOrReportOffsets(GCodeBuffer &gb, const StringRef& reply, if (settingOffset) { - ToolOffsetInverseTransform(moveBuffer.coords, currentUserPosition); // update user coordinates to reflect the new tool offset, in case we have this tool selected + ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // update user coordinates to reflect the new tool offset, in case we have this tool selected } } @@ -3948,7 +3955,7 @@ GCodeResult GCodes::RetractFilament(GCodeBuffer& gb, bool retract) return GCodeResult::notFinished; } - if (moveBuffer.segmentsLeft != 0) + if (moveState.segmentsLeft != 0) { return GCodeResult::notFinished; } @@ -3956,9 +3963,9 @@ GCodeResult GCodes::RetractFilament(GCodeBuffer& gb, bool retract) // New code does the retraction and the Z hop as separate moves // Get ready to generate a move SetMoveBufferDefaults(); - moveBuffer.tool = reprap.GetCurrentTool(); - reprap.GetMove().GetCurrentUserPosition(moveBuffer.coords, 0, moveBuffer.tool); - moveBuffer.filePos = (&gb == fileGCode) ? gb.GetFilePosition() : noFilePosition; + moveState.tool = reprap.GetCurrentTool(); + reprap.GetMove().GetCurrentUserPosition(moveState.coords, 0, moveState.tool); + moveState.filePos = (&gb == fileGCode) ? gb.GetFilePosition() : noFilePosition; if (retract) { @@ -3968,10 +3975,10 @@ GCodeResult GCodes::RetractFilament(GCodeBuffer& gb, bool retract) { for (size_t i = 0; i < tool->DriveCount(); ++i) { - moveBuffer.coords[ExtruderToLogicalDrive(tool->Drive(i))] = -currentTool->GetRetractLength(); + moveState.coords[ExtruderToLogicalDrive(tool->Drive(i))] = -currentTool->GetRetractLength(); } - moveBuffer.feedRate = currentTool->GetRetractSpeed() * tool->DriveCount(); - moveBuffer.canPauseAfter = false; // don't pause after a retraction because that could cause too much retraction + moveState.feedRate = currentTool->GetRetractSpeed() * tool->DriveCount(); + moveState.canPauseAfter = false; // don't pause after a retraction because that could cause too much retraction NewMoveAvailable(1); } if (currentTool->GetRetractHop() > 0.0) @@ -3979,13 +3986,13 @@ GCodeResult GCodes::RetractFilament(GCodeBuffer& gb, bool retract) gb.SetState(GCodeState::doingFirmwareRetraction); } } - else if (currentZHop > 0.0) + else if (moveState.currentZHop > 0.0) { // Set up the reverse Z hop move - moveBuffer.feedRate = platform.MaxFeedrate(Z_AXIS); - moveBuffer.coords[Z_AXIS] -= currentZHop; - currentZHop = 0.0; - moveBuffer.canPauseAfter = false; // don't pause in the middle of a command + moveState.feedRate = platform.MaxFeedrate(Z_AXIS); + moveState.coords[Z_AXIS] -= moveState.currentZHop; + moveState.currentZHop = 0.0; + moveState.canPauseAfter = false; // don't pause in the middle of a command NewMoveAvailable(1); gb.SetState(GCodeState::doingFirmwareUnRetraction); } @@ -3997,10 +4004,10 @@ GCodeResult GCodes::RetractFilament(GCodeBuffer& gb, bool retract) { for (size_t i = 0; i < tool->DriveCount(); ++i) { - moveBuffer.coords[ExtruderToLogicalDrive(tool->Drive(i))] = currentTool->GetRetractLength() + currentTool->GetRetractExtra(); + moveState.coords[ExtruderToLogicalDrive(tool->Drive(i))] = currentTool->GetRetractLength() + currentTool->GetRetractExtra(); } - moveBuffer.feedRate = currentTool->GetUnRetractSpeed() * tool->DriveCount(); - moveBuffer.canPauseAfter = true; + moveState.feedRate = currentTool->GetUnRetractSpeed() * tool->DriveCount(); + moveState.canPauseAfter = true; NewMoveAvailable(1); } } @@ -4114,7 +4121,7 @@ bool GCodes::IsCodeQueueIdle() const noexcept // This is called from Pid.cpp when there is a heater fault, and from elsewhere in this module. void GCodes::StopPrint(StopPrintReason reason) noexcept { - moveBuffer.segmentsLeft = 0; + moveState.segmentsLeft = 0; deferredPauseCommandPending = nullptr; pauseState = PauseState::notPaused; @@ -4150,8 +4157,8 @@ void GCodes::StopPrint(StopPrintReason reason) noexcept Tool* const currentTool = reprap.GetCurrentTool(); if (currentTool != nullptr && currentTool->IsRetracted()) { - currentUserPosition[Z_AXIS] += currentZHop; - currentZHop = 0.0; + moveState.currentUserPosition[Z_AXIS] += moveState.currentZHop; + moveState.currentZHop = 0.0; currentTool->SetRetracted(false); } @@ -4207,7 +4214,7 @@ void GCodes::StopPrint(StopPrintReason reason) noexcept #if SUPPORT_LASER case MachineType::laser: platform.SetLaserPwm(0); - moveBuffer.laserPwmOrIoBits.laserPwm = 0; + moveState.laserPwmOrIoBits.laserPwm = 0; break; #endif @@ -4266,8 +4273,8 @@ bool GCodes::ToolHeatersAtSetTemperatures(const Tool *tool, bool waitWhenCooling // Get the current position from the Move class void GCodes::UpdateCurrentUserPosition() noexcept { - reprap.GetMove().GetCurrentUserPosition(moveBuffer.coords, 0, reprap.GetCurrentTool()); - ToolOffsetInverseTransform(moveBuffer.coords, currentUserPosition); + reprap.GetMove().GetCurrentUserPosition(moveState.coords, 0, reprap.GetCurrentTool()); + ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); } // Save position etc. to a restore point. @@ -4276,7 +4283,7 @@ void GCodes::SavePosition(RestorePoint& rp, const GCodeBuffer& gb) const noexcep { for (size_t axis = 0; axis < numVisibleAxes; ++axis) { - rp.moveCoords[axis] = currentUserPosition[axis]; + rp.moveCoords[axis] = moveState.currentUserPosition[axis]; } rp.feedRate = gb.LatestMachineState().feedRate; @@ -4286,7 +4293,7 @@ void GCodes::SavePosition(RestorePoint& rp, const GCodeBuffer& gb) const noexcep rp.fanSpeed = lastDefaultFanSpeed; #if SUPPORT_LASER || SUPPORT_IOBITS - rp.laserPwmOrIoBits = moveBuffer.laserPwmOrIoBits; + rp.laserPwmOrIoBits = moveState.laserPwmOrIoBits; #endif } @@ -4295,7 +4302,7 @@ void GCodes::RestorePosition(const RestorePoint& rp, GCodeBuffer *gb) noexcept { for (size_t axis = 0; axis < numVisibleAxes; ++axis) { - currentUserPosition[axis] = rp.moveCoords[axis]; + moveState.currentUserPosition[axis] = rp.moveCoords[axis]; } if (gb != nullptr) @@ -4303,11 +4310,11 @@ void GCodes::RestorePosition(const RestorePoint& rp, GCodeBuffer *gb) noexcept gb->LatestMachineState().feedRate = rp.feedRate; } - moveBuffer.initialUserC0 = rp.initialUserC0; - moveBuffer.initialUserC1 = rp.initialUserC1; + moveState.initialUserC0 = rp.initialUserC0; + moveState.initialUserC1 = rp.initialUserC1; #if SUPPORT_LASER || SUPPORT_IOBITS - moveBuffer.laserPwmOrIoBits = rp.laserPwmOrIoBits; + moveState.laserPwmOrIoBits = rp.laserPwmOrIoBits; #endif } @@ -4343,7 +4350,7 @@ void GCodes::ToolOffsetTransform(const float coordsIn[MaxAxes], float coordsOut[ } } } - coordsOut[Z_AXIS] += currentZHop; + coordsOut[Z_AXIS] += moveState.currentZHop; } // Convert head reference point coordinates to user coordinates, allowing for XY axis mapping @@ -4389,7 +4396,7 @@ void GCodes::ToolOffsetInverseTransform(const float coordsIn[MaxAxes], float coo coordsOut[Y_AXIS] = yCoord/numYAxes; } } - coordsOut[Z_AXIS] -= currentZHop/axisScaleFactors[Z_AXIS]; + coordsOut[Z_AXIS] -= moveState.currentZHop/axisScaleFactors[Z_AXIS]; } // Get an axis offset of the current tool @@ -4402,7 +4409,7 @@ float GCodes::GetCurrentToolOffset(size_t axis) const noexcept // Get the current user coordinate and remove the workplace offset float GCodes::GetUserCoordinate(size_t axis) const noexcept { - return (axis < numTotalAxes) ? currentUserPosition[axis] - GetWorkplaceOffset(axis) : 0.0; + return (axis < numTotalAxes) ? moveState.currentUserPosition[axis] - GetWorkplaceOffset(axis) : 0.0; } #if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES @@ -4740,7 +4747,7 @@ void GCodes::StartToolChange(GCodeBuffer& gb, int toolNum, uint8_t param) noexce // Set up some default values in the move buffer for special moves, e.g. for Z probing and firmware retraction void GCodes::SetMoveBufferDefaults() noexcept { - moveBuffer.SetDefaults(numTotalAxes); + moveState.SetDefaults(numTotalAxes); } // Resource locking/unlocking @@ -4967,8 +4974,8 @@ void GCodes::ActivateHeightmap(bool activate) noexcept if (activate) { // Update the current position to allow for any bed compensation at the current XY coordinates - reprap.GetMove().GetCurrentUserPosition(moveBuffer.coords, 0, reprap.GetCurrentTool()); - ToolOffsetInverseTransform(moveBuffer.coords, currentUserPosition); // update user coordinates to reflect any height map offset at the current position + reprap.GetMove().GetCurrentUserPosition(moveState.coords, 0, reprap.GetCurrentTool()); + ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // update user coordinates to reflect any height map offset at the current position #if HAS_LINUX_INTERFACE // Set a dummy heightmap filename |