diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-07-24 19:25:43 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-07-24 19:25:43 +0300 |
commit | 65f74b5d87808e00eefefe29916c90a12c3376b5 (patch) | |
tree | 4099381700142a8d50cef526251ad71435b2fad3 /src | |
parent | a1c2af661f19f248c70e9716f6142c597deb5ca0 (diff) |
More fixes for new time units
Diffstat (limited to 'src')
-rw-r--r-- | src/Configuration.h | 3 | ||||
-rw-r--r-- | src/GCodes/GCodeBuffer/GCodeBuffer.cpp | 6 | ||||
-rw-r--r-- | src/GCodes/GCodes.cpp | 4 | ||||
-rw-r--r-- | src/GCodes/GCodes2.cpp | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes4.cpp | 8 | ||||
-rw-r--r-- | src/Tools/Tool.cpp | 52 | ||||
-rw-r--r-- | src/Tools/Tool.h | 4 |
7 files changed, 41 insertions, 38 deletions
diff --git a/src/Configuration.h b/src/Configuration.h index b5b6b4a2..14878668 100644 --- a/src/Configuration.h +++ b/src/Configuration.h @@ -293,7 +293,8 @@ constexpr size_t ObjectNamesStringSpace = 500; // How much space we reserve fo // Move system constexpr float DefaultFeedRate = 3000.0; // The initial requested feed rate after resetting the printer, in mm/min constexpr float DefaultG0FeedRate = 18000; // The initial feed rate for G0 commands after resetting the printer, in mm/min -constexpr float DefaultRetractSpeed = 1000.0; // The default firmware retraction and un-retraction speed, in mm +constexpr float MinRetractSpeed = 60.0; // The minimum firmware retraction/un-retraction speed in mm/min +constexpr float DefaultRetractSpeed = 1000.0; // The default firmware retraction and un-retraction speed, in mm/min constexpr float DefaultRetractLength = 2.0; constexpr float MaxArcDeviation = 0.005; // maximum deviation from ideal arc due to segmentation diff --git a/src/GCodes/GCodeBuffer/GCodeBuffer.cpp b/src/GCodes/GCodeBuffer/GCodeBuffer.cpp index 117df375..d4ee40fd 100644 --- a/src/GCodes/GCodeBuffer/GCodeBuffer.cpp +++ b/src/GCodes/GCodeBuffer/GCodeBuffer.cpp @@ -755,14 +755,16 @@ float GCodeBuffer::InverseConvertDistance(float distance) const noexcept return (UsingInches()) ? distance/InchToMm : distance; } +// Convert speed from mm/min or inches/min to mm per step clock float GCodeBuffer::ConvertSpeed(float speed) const noexcept { - return speed * ((UsingInches()) ? InchToMm/StepClockRate : 1.0/StepClockRate); + return speed * ((UsingInches()) ? InchToMm/(StepClockRate * iMinutesToSeconds) : 1.0/(StepClockRate * iMinutesToSeconds)); } +// Convert speed to mm/min or inches/min float GCodeBuffer::InverseConvertSpeed(float speed) const noexcept { - return speed * ((UsingInches()) ? StepClockRate/InchToMm : (float)StepClockRate); + return speed * ((UsingInches()) ? (StepClockRate * iMinutesToSeconds)/InchToMm : (float)(StepClockRate * iMinutesToSeconds)); } const char *GCodeBuffer::GetDistanceUnits() const noexcept diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp index 005b5018..5e7c5703 100644 --- a/src/GCodes/GCodes.cpp +++ b/src/GCodes/GCodes.cpp @@ -2118,7 +2118,7 @@ bool GCodes::DoStraightMove(GCodeBuffer& gb, bool isCoordinated, const char *& e moveLengthSquared += fsquare(currentUserPosition[Z_AXIS] - initialUserPosition[Z_AXIS]); } const float moveLength = fastSqrtf(moveLengthSquared); - const float moveTime = moveLength/moveBuffer.feedRate; // this is a best-case time, often the move will take longer + 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()))); } else @@ -2468,7 +2468,7 @@ 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 * (1.0/MinArcSegmentsPerSec)), + ( min<float>(fastSqrtf(8 * moveBuffer.arcRadius * MaxArcDeviation), moveBuffer.feedRate * StepClockRate * (1.0/MinArcSegmentsPerSec)), MinArcSegmentLength, MaxArcSegmentLength ); diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index 22510e8a..e8311082 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -2415,7 +2415,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx { // The pipeline is empty, so execute the babystepping move immediately SetMoveBufferDefaults(); - moveBuffer.feedRate = DefaultFeedRate; + moveBuffer.feedRate = ConvertSpeedFromMmPerMin(DefaultFeedRate); moveBuffer.tool = reprap.GetCurrentTool(); NewMoveAvailable(1); } diff --git a/src/GCodes/GCodes4.cpp b/src/GCodes/GCodes4.cpp index 4b870d46..ffdcaafd 100644 --- a/src/GCodes/GCodes4.cpp +++ b/src/GCodes/GCodes4.cpp @@ -399,8 +399,8 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept SetMoveBufferDefaults(); currentUserPosition[Z_AXIS] = toolChangeRestorePoint.moveCoords[Z_AXIS]; ToolOffsetTransform(currentUserPosition, moveBuffer.coords); - moveBuffer.feedRate = DefaultFeedRate * SecondsToMinutes; // ask for a good feed rate, we may have paused during a slow move - moveBuffer.tool = reprap.GetCurrentTool(); // needed so that bed compensation is applied correctly + moveBuffer.feedRate = ConvertSpeedFromMmPerMin(DefaultFeedRate); // ask for a good feed rate, we may have paused during a slow move + moveBuffer.tool = reprap.GetCurrentTool(); // needed so that bed compensation is applied correctly NewMoveAvailable(1); gb.AdvanceState(); } @@ -511,8 +511,8 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept } SetMoveBufferDefaults(); ToolOffsetTransform(currentUserPosition, moveBuffer.coords); - moveBuffer.feedRate = DefaultFeedRate * SecondsToMinutes; // ask for a good feed rate, we may have paused during a slow move - moveBuffer.tool = reprap.GetCurrentTool(); // needed so that bed compensation is applied correctly + moveBuffer.feedRate = ConvertSpeedFromMmPerMin(DefaultFeedRate); // ask for a good feed rate, we may have paused during a slow move + moveBuffer.tool = reprap.GetCurrentTool(); // needed so that bed compensation is applied correctly if (gb.GetState() == GCodeState::resuming1 && currentZ > pauseRestorePoint.moveCoords[Z_AXIS]) { // First move the head to the correct XY point, then move it down in a separate move diff --git a/src/Tools/Tool.cpp b/src/Tools/Tool.cpp index b9967295..081efc3e 100644 --- a/src/Tools/Tool.cpp +++ b/src/Tools/Tool.cpp @@ -94,30 +94,30 @@ constexpr ObjectModelTableEntry Tool::objectModelTable[] = { // Within each group, these entries must be in alphabetical order // 0. Tool members - { "active", OBJECT_MODEL_FUNC_NOSELF(&activeTempsArrayDescriptor), ObjectModelEntryFlags::live }, - { "axes", OBJECT_MODEL_FUNC_NOSELF(&axesArrayDescriptor), ObjectModelEntryFlags::none }, - { "extruders", OBJECT_MODEL_FUNC_NOSELF(&extrudersArrayDescriptor), ObjectModelEntryFlags::none }, - { "fans", OBJECT_MODEL_FUNC(self->fanMapping), ObjectModelEntryFlags::none }, - { "filamentExtruder", OBJECT_MODEL_FUNC((int32_t)self->filamentExtruder), ObjectModelEntryFlags::none }, - { "heaters", OBJECT_MODEL_FUNC_NOSELF(&heatersArrayDescriptor), ObjectModelEntryFlags::none }, - { "isRetracted", OBJECT_MODEL_FUNC(self->IsRetracted()), ObjectModelEntryFlags::live }, - { "mix", OBJECT_MODEL_FUNC_NOSELF(&mixArrayDescriptor), ObjectModelEntryFlags::none }, - { "name", OBJECT_MODEL_FUNC(self->name), ObjectModelEntryFlags::none }, - { "number", OBJECT_MODEL_FUNC((int32_t)self->myNumber), ObjectModelEntryFlags::none }, - { "offsets", OBJECT_MODEL_FUNC_NOSELF(&offsetsArrayDescriptor), ObjectModelEntryFlags::none }, - { "offsetsProbed", OBJECT_MODEL_FUNC((int32_t)self->axisOffsetsProbed.GetRaw()), ObjectModelEntryFlags::none }, - { "retraction", OBJECT_MODEL_FUNC(self, 1), ObjectModelEntryFlags::none }, - { "spindle", OBJECT_MODEL_FUNC((int32_t)self->spindleNumber), ObjectModelEntryFlags::none }, - { "spindleRpm", OBJECT_MODEL_FUNC((int32_t)self->spindleRpm), ObjectModelEntryFlags::none }, - { "standby", OBJECT_MODEL_FUNC_NOSELF(&standbyTempsArrayDescriptor), ObjectModelEntryFlags::live }, - { "state", OBJECT_MODEL_FUNC(self->state.ToString()), ObjectModelEntryFlags::live }, + { "active", OBJECT_MODEL_FUNC_NOSELF(&activeTempsArrayDescriptor), ObjectModelEntryFlags::live }, + { "axes", OBJECT_MODEL_FUNC_NOSELF(&axesArrayDescriptor), ObjectModelEntryFlags::none }, + { "extruders", OBJECT_MODEL_FUNC_NOSELF(&extrudersArrayDescriptor), ObjectModelEntryFlags::none }, + { "fans", OBJECT_MODEL_FUNC(self->fanMapping), ObjectModelEntryFlags::none }, + { "filamentExtruder", OBJECT_MODEL_FUNC((int32_t)self->filamentExtruder), ObjectModelEntryFlags::none }, + { "heaters", OBJECT_MODEL_FUNC_NOSELF(&heatersArrayDescriptor), ObjectModelEntryFlags::none }, + { "isRetracted", OBJECT_MODEL_FUNC(self->IsRetracted()), ObjectModelEntryFlags::live }, + { "mix", OBJECT_MODEL_FUNC_NOSELF(&mixArrayDescriptor), ObjectModelEntryFlags::none }, + { "name", OBJECT_MODEL_FUNC(self->name), ObjectModelEntryFlags::none }, + { "number", OBJECT_MODEL_FUNC((int32_t)self->myNumber), ObjectModelEntryFlags::none }, + { "offsets", OBJECT_MODEL_FUNC_NOSELF(&offsetsArrayDescriptor), ObjectModelEntryFlags::none }, + { "offsetsProbed", OBJECT_MODEL_FUNC((int32_t)self->axisOffsetsProbed.GetRaw()), ObjectModelEntryFlags::none }, + { "retraction", OBJECT_MODEL_FUNC(self, 1), ObjectModelEntryFlags::none }, + { "spindle", OBJECT_MODEL_FUNC((int32_t)self->spindleNumber), ObjectModelEntryFlags::none }, + { "spindleRpm", OBJECT_MODEL_FUNC((int32_t)self->spindleRpm), ObjectModelEntryFlags::none }, + { "standby", OBJECT_MODEL_FUNC_NOSELF(&standbyTempsArrayDescriptor), ObjectModelEntryFlags::live }, + { "state", OBJECT_MODEL_FUNC(self->state.ToString()), ObjectModelEntryFlags::live }, // 1. Tool.retraction members - { "extraRestart", OBJECT_MODEL_FUNC(self->retractExtra, 1), ObjectModelEntryFlags::none }, - { "length", OBJECT_MODEL_FUNC(self->retractLength, 1), ObjectModelEntryFlags::none }, - { "speed" , OBJECT_MODEL_FUNC(self->retractSpeed, 1), ObjectModelEntryFlags::none }, - { "unretractSpeed", OBJECT_MODEL_FUNC(self->unRetractSpeed, 1), ObjectModelEntryFlags::none }, - { "zHop", OBJECT_MODEL_FUNC(self->retractHop, 2), ObjectModelEntryFlags::none }, + { "extraRestart", OBJECT_MODEL_FUNC(self->retractExtra, 1), ObjectModelEntryFlags::none }, + { "length", OBJECT_MODEL_FUNC(self->retractLength, 1), ObjectModelEntryFlags::none }, + { "speed" , OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerSec(self->retractSpeed), 1), ObjectModelEntryFlags::none }, + { "unretractSpeed", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerSec(self->unRetractSpeed), 1), ObjectModelEntryFlags::none }, + { "zHop", OBJECT_MODEL_FUNC(self->retractHop, 2), ObjectModelEntryFlags::none }, }; constexpr uint8_t Tool::objectModelTableDescriptor[] = { 2, 17, 5 }; @@ -217,7 +217,7 @@ DEFINE_GET_OBJECT_MODEL_TABLE(Tool) t->retractLength = DefaultRetractLength; t->retractExtra = 0.0; t->retractHop = 0.0; - t->retractSpeed = t->unRetractSpeed = DefaultRetractSpeed * SecondsToMinutes; + t->retractSpeed = t->unRetractSpeed = ConvertSpeedFromMmPerMin(DefaultRetractSpeed); t->isRetracted = false; t->spindleNumber = spindleNo; t->spindleRpm = 0; @@ -777,12 +777,12 @@ GCodeResult Tool::SetFirmwareRetraction(GCodeBuffer &gb, const StringRef &reply, } if (gb.Seen('F')) { - unRetractSpeed = retractSpeed = max<float>(gb.GetFValue(), 60.0) * SecondsToMinutes; + unRetractSpeed = retractSpeed = max<float>(gb.GetSpeedFromMm(false), ConvertSpeedFromMmPerMin(MinRetractSpeed)); seen = true; } if (gb.Seen('T')) // must do this one after 'F' { - unRetractSpeed = max<float>(gb.GetFValue(), 60.0) * SecondsToMinutes; + unRetractSpeed = max<float>(gb.GetSpeedFromMm(false), ConvertSpeedFromMmPerMin(MinRetractSpeed)); seen = true; } if (gb.Seen('Z')) @@ -803,7 +803,7 @@ GCodeResult Tool::SetFirmwareRetraction(GCodeBuffer &gb, const StringRef &reply, return GCodeResult::notFinished; } outBuf->lcatf("Tool %u retract/reprime: length %.2f/%.2fmm, speed %.1f/%.1fmm/sec, Z hop %.2fmm", - myNumber, (double)retractLength, (double)(retractLength + retractExtra), (double)retractSpeed, (double)unRetractSpeed, (double)retractHop); + myNumber, (double)retractLength, (double)(retractLength + retractExtra), (double)InverseConvertSpeedToMmPerSec(retractSpeed), (double)InverseConvertSpeedToMmPerSec(unRetractSpeed), (double)retractHop); } return GCodeResult::ok; } diff --git a/src/Tools/Tool.h b/src/Tools/Tool.h index a12356ef..bc49e058 100644 --- a/src/Tools/Tool.h +++ b/src/Tools/Tool.h @@ -157,8 +157,8 @@ private: // Firmware retraction settings float retractLength, retractExtra; // retraction length and extra length to un-retract - float retractSpeed; // retract speed in mm/min - float unRetractSpeed; // un=retract speed in mm/min + float retractSpeed; // retract speed in mm per step clock + float unRetractSpeed; // un-retract speed in mm per step clock float retractHop; // Z hop when retracting FansBitmap fanMapping; |