diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-02-23 14:38:21 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-02-23 14:38:21 +0300 |
commit | ee4605150e38bea73bef0a1751f1f7e7b4abc96a (patch) | |
tree | 718209dd7e032513e7e0aea7cb9cdafebde8af35 /src/Movement | |
parent | 42368635350ecbd15eb618304fec1deea514d363 (diff) | |
parent | 0d8a8dc0f2f358303f0a21769039664cb311e10d (diff) |
Merge branch '3.3-dev' into 3.3-input-shaping
Diffstat (limited to 'src/Movement')
-rw-r--r-- | src/Movement/BedProbing/Grid.cpp | 208 | ||||
-rw-r--r-- | src/Movement/BedProbing/Grid.h | 34 | ||||
-rw-r--r-- | src/Movement/Move.cpp | 12 |
3 files changed, 137 insertions, 117 deletions
diff --git a/src/Movement/BedProbing/Grid.cpp b/src/Movement/BedProbing/Grid.cpp index b9e5a129..61cf5517 100644 --- a/src/Movement/BedProbing/Grid.cpp +++ b/src/Movement/BedProbing/Grid.cpp @@ -24,22 +24,53 @@ #define OBJECT_MODEL_FUNC(...) OBJECT_MODEL_FUNC_BODY(GridDefinition, __VA_ARGS__) #define OBJECT_MODEL_FUNC_IF(...) OBJECT_MODEL_FUNC_IF_BODY(GridDefinition, __VA_ARGS__) +static constexpr ObjectModelArrayDescriptor axisArrayDescriptor = +{ + nullptr, // no lock needed + [] (const ObjectModel *self, const ObjectExplorationContext&) noexcept -> size_t { return 2; }, + [] (const ObjectModel *self, ObjectExplorationContext& context) noexcept -> ExpressionValue { return ExpressionValue(((const GridDefinition*)self)->GetAxisLetter(context.GetLastIndex())); } +}; + +static constexpr ObjectModelArrayDescriptor maxsArrayDescriptor = +{ + nullptr, // no lock needed + [] (const ObjectModel *self, const ObjectExplorationContext&) noexcept -> size_t { return 2; }, + [] (const ObjectModel *self, ObjectExplorationContext& context) noexcept -> ExpressionValue { return ExpressionValue(((const GridDefinition*)self)->GetMax(context.GetLastIndex()), 1); } +}; + +static constexpr ObjectModelArrayDescriptor minsArrayDescriptor = +{ + nullptr, // no lock needed + [] (const ObjectModel *self, const ObjectExplorationContext&) noexcept -> size_t { return 2; }, + [] (const ObjectModel *self, ObjectExplorationContext& context) noexcept -> ExpressionValue { return ExpressionValue(((const GridDefinition*)self)->GetMin(context.GetLastIndex()), 1); } +}; + +static constexpr ObjectModelArrayDescriptor spacingsArrayDescriptor = +{ + nullptr, // no lock needed + [] (const ObjectModel *self, const ObjectExplorationContext&) noexcept -> size_t { return 2; }, + [] (const ObjectModel *self, ObjectExplorationContext& context) noexcept -> ExpressionValue { return ExpressionValue(((const GridDefinition*)self)->GetSpacing(context.GetLastIndex()), 1); } +}; + constexpr ObjectModelTableEntry GridDefinition::objectModelTable[] = { // Within each group, these entries must be in alphabetical order // 0. GridDefinition members - { "axis0", OBJECT_MODEL_FUNC(self->letter0), ObjectModelEntryFlags::none }, - { "axis1", OBJECT_MODEL_FUNC(self->letter1), ObjectModelEntryFlags::none }, - { "max0", OBJECT_MODEL_FUNC(self->max0, 1), ObjectModelEntryFlags::none }, - { "max1", OBJECT_MODEL_FUNC(self->max1, 1), ObjectModelEntryFlags::none }, - { "min0", OBJECT_MODEL_FUNC(self->min0, 1), ObjectModelEntryFlags::none }, - { "min1", OBJECT_MODEL_FUNC(self->min1, 1), ObjectModelEntryFlags::none }, - { "radius", OBJECT_MODEL_FUNC(self->radius, 1), ObjectModelEntryFlags::none }, - { "spacing0", OBJECT_MODEL_FUNC(self->spacing0, 1), ObjectModelEntryFlags::none }, - { "spacing1", OBJECT_MODEL_FUNC(self->spacing1, 1), ObjectModelEntryFlags::none }, + { "axes", OBJECT_MODEL_FUNC_NOSELF(&axisArrayDescriptor), ObjectModelEntryFlags::none }, + { "maxs", OBJECT_MODEL_FUNC_NOSELF(&maxsArrayDescriptor), ObjectModelEntryFlags::none }, + { "mins", OBJECT_MODEL_FUNC_NOSELF(&minsArrayDescriptor), ObjectModelEntryFlags::none }, + { "radius", OBJECT_MODEL_FUNC(self->radius, 1), ObjectModelEntryFlags::none }, + { "spacings", OBJECT_MODEL_FUNC_NOSELF(&spacingsArrayDescriptor), ObjectModelEntryFlags::none }, + + { "xMax", OBJECT_MODEL_FUNC(self->maxs[0], 1), ObjectModelEntryFlags::obsolete }, + { "xMin", OBJECT_MODEL_FUNC(self->mins[0], 1), ObjectModelEntryFlags::obsolete }, + { "xSpacing", OBJECT_MODEL_FUNC(self->spacings[0], 1), ObjectModelEntryFlags::obsolete }, + { "yMax", OBJECT_MODEL_FUNC(self->maxs[1], 1), ObjectModelEntryFlags::obsolete }, + { "yMin", OBJECT_MODEL_FUNC(self->mins[1], 1), ObjectModelEntryFlags::obsolete }, + { "ySpacing", OBJECT_MODEL_FUNC(self->spacings[1], 1), ObjectModelEntryFlags::obsolete }, }; -constexpr uint8_t GridDefinition::objectModelTableDescriptor[] = { 1, 9 }; +constexpr uint8_t GridDefinition::objectModelTableDescriptor[] = { 1, 11 }; DEFINE_GET_OBJECT_MODEL_TABLE(GridDefinition) @@ -53,31 +84,30 @@ const char * const GridDefinition::HeightMapLabelLines[] = }; // Initialise the grid to be invalid -GridDefinition::GridDefinition() noexcept - : letter0('X'), letter1('Y'), - min0(0.0), max0(-1.0), - min1(0.0), max1(-1.0), - radius(-1.0), - spacing0(0.0), spacing1(0.0), - axis0Number(X_AXIS), axis1Number(Y_AXIS), - num0(0), num1(0), - recipAxis0spacing(0.0), recipAxis1spacing(0.0), - isValid(false) +GridDefinition::GridDefinition() noexcept : radius(-1.0), isValid(false) { + letters[0] = 'X'; + letters[1] = 'Y'; + mins[0] = mins[1] = 0.0; + maxs[0] = maxs[1] = -1.0; + spacings[0] = spacings[1] = 0.0; + + nums[0] = nums[1] = 0; + recipAxisSpacings[0] = recipAxisSpacings[1] = 0.0; } // Set the grid parameters ands return true if it is now valid -bool GridDefinition::Set(const char axesLetters[2], const float axis0Range[2], const float axis1Range[2], float pRadius, const float pSpacings[2]) noexcept +bool GridDefinition::Set(const char axisLetters[2], const float axis0Range[2], const float axis1Range[2], float pRadius, const float pSpacings[2]) noexcept { - letter0 = axesLetters[0]; - letter1 = axesLetters[1]; - min0 = axis0Range[0]; - max0 = axis0Range[1]; - min1 = axis1Range[0]; - max1 = axis1Range[1]; + letters[0] = axisLetters[0]; + letters[1] = axisLetters[1]; + mins[0] = axis0Range[0]; + maxs[0] = axis0Range[1]; + mins[1] = axis1Range[0]; + maxs[1] = axis1Range[1]; radius = pRadius; - spacing0 = pSpacings[0]; - spacing1 = pSpacings[1]; + spacings[0] = pSpacings[0]; + spacings[1] = pSpacings[1]; CheckValidity(true); return isValid; } @@ -87,7 +117,7 @@ bool GridDefinition::Set(const char axesLetters[2], const float axis0Range[2], c // If the grid is valid then set up recipAxis0spacing and recipAxis1spacing void GridDefinition::CheckValidity(bool setNum0Num1) noexcept { - if (max0 - min0 < MinRange || spacing0 < MinSpacing || max1 - min1 < MinRange || spacing1 < MinSpacing) + if (max0 - min0 < MinRange || spacings[0] < MinSpacing || max1 - min1 < MinRange || spacings[1] < MinSpacing) { isValid = false; if (setNum0Num1) @@ -99,8 +129,8 @@ void GridDefinition::CheckValidity(bool setNum0Num1) noexcept { if (setNum0Num1) { - num0 = (uint32_t)((max0 - min0)/spacing0) + 1; - num1 = (uint32_t)((max1 - min1)/spacing1) + 1; + num0 = (uint32_t)((max0 - min0)/spacings[0]) + 1; + num1 = (uint32_t)((max1 - min1)/spacings[1]) + 1; } const size_t axis0NumForLetter = reprap.GetGCodes().GetAxisNumberForLetter(letter0); @@ -118,22 +148,12 @@ void GridDefinition::CheckValidity(bool setNum0Num1) noexcept { axis0Number = axis0NumForLetter; axis1Number = axis1NumForLetter; - recipAxis0spacing = 1.0/spacing0; - recipAxis1spacing = 1.0/spacing1; + recipAxis0spacing = 1.0/spacings[0]; + recipAxis1spacing = 1.0/spacings[1]; } } } -float GridDefinition::GetCoordinate0(unsigned int axis0Index) const noexcept -{ - return min0 + (axis0Index * spacing0); -} - -float GridDefinition::GetCoordinate1(unsigned int axis1Index) const noexcept -{ - return min1 + (axis1Index * spacing1); -} - bool GridDefinition::IsInRadius(float axis0, float y) const noexcept { return radius < 0.0 || fsquare(axis0) + fsquare(y) < fsquare(radius); @@ -143,14 +163,14 @@ bool GridDefinition::IsInRadius(float axis0, float y) const noexcept void GridDefinition::PrintParameters(const StringRef& s) const noexcept { s.catf("%c%.1f:%.1f, %c%.1f:%.1f, radius %.1f, %c spacing %.1f, %c spacing %.1f, %" PRIu32 " points", - letter0, (double)min0, (double)max0, letter1, (double)min1, (double)max1, (double)radius, letter0, (double)spacing0, letter1, (double)spacing1, NumPoints()); + letters[0], (double)mins[0], (double)maxs[0], letters[1], (double)mins[1], (double)maxs[1], (double)radius, letters[0], (double)spacings[0], letters[1], (double)spacings[1], NumPoints()); } // Write the parameter label line to a string void GridDefinition::WriteHeadingAndParameters(const StringRef& s) const noexcept { s.printf("%s\n%c,%c,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%" PRIi32 ",%" PRIi32 "\n", - HeightMapLabelLines[ARRAY_UPB(HeightMapLabelLines)], letter0, letter1, (double)min0, (double)max0, (double)min1, (double)max1, (double)radius, (double)spacing0, (double)spacing1, num0, num1); + HeightMapLabelLines[ARRAY_UPB(HeightMapLabelLines)], letters[0], letters[1], (double)mins[0], (double)maxs[0], (double)mins[1], (double)maxs[1], (double)radius, (double)spacings[0], (double)spacings[1], nums[0], nums[1]); } // Check the parameter label line, returning -1 if not recognised, else the version we found @@ -176,19 +196,19 @@ bool GridDefinition::ReadParameters(const StringRef& s, int version) noexcept if (version < 2) { - letter0 = 'X'; - letter1 = 'Y'; + letters[0] = 'X'; + letters[1] = 'Y'; } else { - letter0 = *p; + letters[0] = *p; ++p; if (*p != ',') { return false; } ++p; - letter1 = *p; + letters[1] = *p; ++p; if (*p != ',') { @@ -197,28 +217,28 @@ bool GridDefinition::ReadParameters(const StringRef& s, int version) noexcept ++p; } - min0 = SafeStrtof(p, &q); + mins[0] = SafeStrtof(p, &q); if (p == q || *q != ',') { return false; } p = q + 1; - max0 = SafeStrtof(p, &q); + maxs[0] = SafeStrtof(p, &q); if (p == q || *q != ',') { return false; } p = q + 1; - min1 = SafeStrtof(p, &q); + mins[1] = SafeStrtof(p, &q); if (p == q || *q != ',') { return false; } p = q + 1; - max1 = SafeStrtof(p, &q); + maxs[1] = SafeStrtof(p, &q); if (p == q || *q != ',') { return false; @@ -232,7 +252,7 @@ bool GridDefinition::ReadParameters(const StringRef& s, int version) noexcept } p = q + 1; - spacing0 = SafeStrtof(p, &q); + spacings[0] = SafeStrtof(p, &q); if (p == q || *q != ',') { return false; @@ -241,11 +261,11 @@ bool GridDefinition::ReadParameters(const StringRef& s, int version) noexcept if (version == 0) { - spacing1 = spacing0; + spacings[1] = spacings[0]; } else { - spacing1 = SafeStrtof(p, &q); + spacings[1] = SafeStrtof(p, &q); if (p == q || *q != ',') { return false; @@ -253,14 +273,14 @@ bool GridDefinition::ReadParameters(const StringRef& s, int version) noexcept p = q + 1; } - num0 = StrToU32(p, &q); + nums[0] = StrToU32(p, &q); if (p == q || *q != ',') { return false; } p = q + 1; - num1 = StrToU32(p, &q); + nums[1] = StrToU32(p, &q); if (p == q) { return false; @@ -273,20 +293,20 @@ bool GridDefinition::ReadParameters(const StringRef& s, int version) noexcept // Print what is wrong with the grid, appending it to the existing string void GridDefinition::PrintError(float originalAxis0range, float originalAxis1range, const StringRef& r) const noexcept { - if (spacing0 < MinSpacing || spacing1 < MinSpacing) + if (spacings[0] < MinSpacing || spacings[1] < MinSpacing) { r.cat("Spacing too small"); } - else if (num0 == 0) + else if (nums[0] == 0) { - r.cat("X range too small"); + r.catf("%c range too small", letters[0]); } - else if (num1 == 0) + else if (nums[1] == 0) { - r.cat("Y range too small"); + r.catf("%c range too small", letters[1]); } - else if ( num0 > MaxAxis0GridPoints - || num0 > MaxGridProbePoints || num1 > MaxGridProbePoints // check X and Y individually in case X*Y overflows + else if ( nums[0] > MaxAxis0GridPoints + || nums[0] > MaxGridProbePoints || nums[1] > MaxGridProbePoints // check X and Y individually in case X*Y overflows || NumPoints() > MaxGridProbePoints ) { @@ -327,7 +347,7 @@ void HeightMap::ClearGridHeights() noexcept // Set the height of a grid point void HeightMap::SetGridHeight(size_t axis0Index, size_t axis1Index, float height) noexcept { - SetGridHeight(axis1Index * def.num0 + axis0Index, height); + SetGridHeight(axis1Index * def.nums[0] + axis0Index, height); } void HeightMap::SetGridHeight(size_t index, float height) noexcept @@ -344,10 +364,10 @@ void HeightMap::SetGridHeight(size_t index, float height) noexcept unsigned int HeightMap::GetMinimumSegments(float deltaAxis0, float deltaAxis1) const noexcept { const float axis0Distance = fabsf(deltaAxis0); - unsigned int axis0Segments = (axis0Distance > 0.0) ? (unsigned int)(axis0Distance * def.recipAxis0spacing + 0.4) : 1; + unsigned int axis0Segments = (axis0Distance > 0.0) ? (unsigned int)(axis0Distance * def.recipAxisSpacings[0] + 0.4) : 1; const float axis1Distance = fabsf(deltaAxis1); - unsigned int axis1Segments = (axis1Distance > 0.0) ? (unsigned int)(axis1Distance * def.recipAxis1spacing + 0.4) : 1; + unsigned int axis1Segments = (axis1Distance > 0.0) ? (unsigned int)(axis1Distance * def.recipAxisSpacings[1] + 0.4) : 1; return max<unsigned int>(axis0Segments, axis1Segments); } @@ -388,10 +408,10 @@ bool HeightMap::SaveToFile(FileStore *f, const char *fname, float zOffset) noexc // Write the grid heights. We use a fixed field with of 6 characters to make is easier to view. uint32_t index = 0; - for (uint32_t i = 0; i < def.num1; ++i) + for (uint32_t i = 0; i < def.nums[1]; ++i) { buf.Clear(); - for (uint32_t j = 0; j < def.num0; ++j) + for (uint32_t j = 0; j < def.nums[0]; ++j) { if (j != 0) { @@ -461,7 +481,7 @@ bool HeightMap::LoadFromFile(FileStore *f, const char *fname, const StringRef& r else { SetGrid(newGrid); - for (uint32_t row = 0; row < def.num1; ++row) // read the grid a row at a time + for (uint32_t row = 0; row < def.nums[1]; ++row) // read the grid a row at a time { if (f->ReadLine(buffer, sizeof(buffer)) <= 0) { @@ -469,7 +489,7 @@ bool HeightMap::LoadFromFile(FileStore *f, const char *fname, const StringRef& r return true; // failed to read a line } const char *p = buffer; - for (uint32_t col = 0; col < def.num0; ++col) + for (uint32_t col = 0; col < def.nums[0]; ++col) { while (*p == ' ' || *p == '\t') { @@ -519,9 +539,9 @@ void HeightMap::SetFileName(const char *name) noexcept void HeightMap::SaveToArray(float *arr, float zOffset) const noexcept { size_t index = 0; - for (size_t i = 0; i < def.num1; ++i) + for (size_t i = 0; i < def.nums[1]; ++i) { - for (size_t j = 0; j < def.num0; ++j) + for (size_t j = 0; j < def.nums[0]; ++j) { arr[index] = gridHeightSet.IsBitSet(index) ? (gridHeights[index] + zOffset) : std::numeric_limits<float>::quiet_NaN(); index++; @@ -578,21 +598,21 @@ float HeightMap::GetInterpolatedHeightError(float axis0, float axis1) const noex } // Last grid point - const float xLast = def.min0 + (def.num0-1)*def.spacing0; - const float yLast = def.min1 + (def.num1-1)*def.spacing1; + const float xLast = def.mins[0] + (def.nums[0]-1)*def.spacings[0]; + const float yLast = def.mins[1] + (def.nums[1]-1)*def.spacings[1]; // Clamp to rectangle so InterpolateXY will always have valid parameters const float fEPSILON = 0.01; - if (axis0 < def.min0) { axis0 = def.min0; } - if (axis1 < def.min1) { axis1 = def.min1; } + if (axis0 < def.mins[0]) { axis0 = def.mins[0]; } + if (axis1 < def.mins[1]) { axis1 = def.mins[1]; } if (axis0 > xLast -fEPSILON) { axis0 = xLast -fEPSILON; } if (axis1 > yLast -fEPSILON) { axis1 = yLast -fEPSILON; } - const float xf = (axis0 - def.min0) * def.recipAxis0spacing; + const float xf = (axis0 - def.mins[0]) * def.recipAxisSpacings[0]; const float xFloor = floor(xf); const int32_t xIndex = (int32_t)xFloor; - const float yf = (axis1 - def.min1) * def.recipAxis1spacing; + const float yf = (axis1 - def.mins[1]) * def.recipAxisSpacings[1]; const float yFloor = floor(yf); const int32_t yIndex = (int32_t)yFloor; @@ -603,7 +623,7 @@ float HeightMap::InterpolateAxis0Axis1(uint32_t axis0Index, uint32_t axis1Index, { const uint32_t indexX0Y0 = GetMapIndex(axis0Index, axis1Index); // (X0,Y0) const uint32_t indexX1Y0 = indexX0Y0 + 1; // (X1,Y0) - const uint32_t indexX0Y1 = indexX0Y0 + def.num0; // (X0 Y1) + const uint32_t indexX0Y1 = indexX0Y0 + def.nums[0]; // (X0 Y1) const uint32_t indexX1Y1 = indexX0Y1 + 1; // (X1,Y1) const float xyFrac = axis0Frac * axis1Frac; @@ -621,15 +641,15 @@ void HeightMap::ExtrapolateMissing() noexcept //algorithm: http://www.ilikebigbits.com/blog/2015/3/2/plane-from-points float sumAxis0 = 0, sumAxis1 = 0, sumZ = 0; int n = 0; - for (uint32_t iAxis1 = 0; iAxis1 < def.num1; iAxis1++) + for (uint32_t iAxis1 = 0; iAxis1 < def.nums[1]; iAxis1++) { - for (uint32_t iAxis0 = 0; iAxis0 < def.num0; iAxis0++) + for (uint32_t iAxis0 = 0; iAxis0 < def.nums[0]; iAxis0++) { const uint32_t index = GetMapIndex(iAxis0, iAxis1); if (gridHeightSet.IsBitSet(index)) { - const float fAxis0 = (def.spacing0 * iAxis0) + def.min0; - const float fAxis1 = (def.spacing1 * iAxis1) + def.min1; + const float fAxis0 = (def.spacings[0] * iAxis0) + def.mins[0]; + const float fAxis1 = (def.spacings[1] * iAxis1) + def.mins[1]; const float fZ = gridHeights[index]; n++; @@ -645,15 +665,15 @@ void HeightMap::ExtrapolateMissing() noexcept float axis0Axis0 = 0.0; float axis0Axis1 = 0.0; float axis0z = 0.0; float axis1Axis1 = 0.0; float axis1z = 0.0; float zz = 0.0; - for (uint32_t iAxis1 = 0; iAxis1 < def.num1; iAxis1++) + for (uint32_t iAxis1 = 0; iAxis1 < def.nums[1]; iAxis1++) { - for (uint32_t iAxis0 = 0; iAxis0 < def.num0; iAxis0++) + for (uint32_t iAxis0 = 0; iAxis0 < def.nums[0]; iAxis0++) { const uint32_t index = GetMapIndex(iAxis0, iAxis1); if (gridHeightSet.IsBitSet(index)) { - const float fAxis0 = (def.spacing0 * iAxis0) + def.min0; - const float fAxis1 = (def.spacing1 * iAxis1) + def.min1; + const float fAxis0 = (def.spacings[0] * iAxis0) + def.mins[0]; + const float fAxis1 = (def.spacings[1] * iAxis1) + def.mins[1]; const float fZ = gridHeights[index]; const float rAxis0 = fAxis0 - centAxis0; @@ -688,15 +708,15 @@ void HeightMap::ExtrapolateMissing() noexcept const float d = centAxis0*a + centAxis1*b + centZ*c; // Fill in the blanks - for (uint32_t iAxis1 = 0; iAxis1 < def.num1; iAxis1++) + for (uint32_t iAxis1 = 0; iAxis1 < def.nums[1]; iAxis1++) { - for (uint32_t iAxis0 = 0; iAxis0 < def.num0; iAxis0++) + for (uint32_t iAxis0 = 0; iAxis0 < def.nums[0]; iAxis0++) { const uint32_t index = GetMapIndex(iAxis0, iAxis1); if (!gridHeightSet.IsBitSet(index)) { - const float fAxis0 = (def.spacing0 * iAxis0) + def.min0; - const float fAxis1 = (def.spacing1 * iAxis1) + def.min1; + const float fAxis0 = (def.spacings[0] * iAxis0) + def.mins[0]; + const float fAxis1 = (def.spacings[1] * iAxis1) + def.mins[1]; const float fZ = (d - (a * fAxis0 + b * fAxis1)) * invC; gridHeights[index] = fZ; // fill in Z but don't mark it as set so we can always differentiate between measured and extrapolated } diff --git a/src/Movement/BedProbing/Grid.h b/src/Movement/BedProbing/Grid.h index cf516833..aa4436c0 100644 --- a/src/Movement/BedProbing/Grid.h +++ b/src/Movement/BedProbing/Grid.h @@ -23,19 +23,19 @@ public: GridDefinition() noexcept; - uint32_t NumAxis0points() const noexcept { return num0; } - uint32_t NumAxis1points() const noexcept { return num1; } - uint32_t NumPoints() const noexcept { return num0 * num1; } - uint8_t GetLetter0() const noexcept { return letter0; } - uint8_t GetLetter1() const noexcept { return letter1; } - uint8_t GetNumber0() const noexcept { return axis0Number; } - uint8_t GetNumber1() const noexcept { return axis1Number; } - float GetCoordinate0(unsigned int axis0Index) const noexcept; - float GetCoordinate1(unsigned int axis1Index) const noexcept; + char GetAxisLetter(size_t axis) const noexcept pre(axis < 2) { return letters[axis]; } + uint8_t GetAxisNumber(size_t axis) const noexcept pre(axis < 2) { return axisNumbers[axis]; } + float GetMin(size_t axis) const noexcept pre(axis < 2) { return mins[axis]; } + float GetMax(size_t axis) const noexcept pre(axis < 2) { return maxs[axis]; } + float GetSpacing(size_t axis) const noexcept pre(axis < 2) { return spacings[axis]; } + + uint32_t NumAxisPoints(size_t axis) const noexcept pre(axis < 2) { return nums[axis]; } + uint32_t NumPoints() const noexcept { return nums[0] * nums[1]; } + float GetCoordinate(size_t axis, size_t coordinateIndex) pre(axis < 2) const noexcept { return mins[axis] + (coordinateIndex * spacings[axis]); } bool IsInRadius(float x, float y) const noexcept; bool IsValid() const noexcept { return isValid; } - bool Set(const char axesLetter[2], const float axis0Range[2], const float axis1Range[2], float pRadius, const float pSpacings[2]) noexcept; + bool Set(const char axisLetters[2], const float axis0Range[2], const float axis1Range[2], float pRadius, const float pSpacings[2]) noexcept; void PrintParameters(const StringRef& r) const noexcept; void WriteHeadingAndParameters(const StringRef& r) const noexcept; static int CheckHeading(const StringRef& s) noexcept; @@ -55,15 +55,15 @@ private: static const char * const HeightMapLabelLines[]; // The line we write to the height map file listing the parameter names // Primary parameters - char letter0, letter1; // Axes letters for this grid - float min0, max0, min1, max1; // The edges of the grid for G29 probing + char letters[2]; // Axis letters for this grid + float mins[2], maxs[2]; // The edges of the grid for G29 probing float radius; // The grid radius to probe - float spacing0, spacing1; // The spacing of the grid probe points + float spacings[2]; // The spacings of the grid probe points // Derived parameters - uint8_t axis0Number, axis1Number; // Axes numbers for this grid - uint32_t num0, num1; - float recipAxis0spacing, recipAxis1spacing; + uint8_t axisNumbers[2]; // Axis numbers for this grid + uint32_t nums[2]; // Number of probe points in each direction + float recipAxisSpacings[2]; // Reciprocals of the axis spacings bool isValid; }; @@ -117,7 +117,7 @@ private: #endif bool useMap; // True to do bed compensation - uint32_t GetMapIndex(uint32_t axis0Index, uint32_t axis1Index) const noexcept { return (axis1Index * def.NumAxis0points()) + axis0Index; } + uint32_t GetMapIndex(uint32_t axis0Index, uint32_t axis1Index) const noexcept { return (axis1Index * def.NumAxisPoints(0)) + axis0Index; } float InterpolateAxis0Axis1(uint32_t axis0Index, uint32_t axis1Index, float axis0Frac, float axis1Frac) const noexcept; }; diff --git a/src/Movement/Move.cpp b/src/Movement/Move.cpp index f18d7777..2e39943e 100644 --- a/src/Movement/Move.cpp +++ b/src/Movement/Move.cpp @@ -96,7 +96,7 @@ constexpr ObjectModelTableEntry Move::objectModelTable[] = { "travelAcceleration", OBJECT_MODEL_FUNC(self->maxTravelAcceleration, 1), ObjectModelEntryFlags::none }, { "virtualEPos", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetVirtualExtruderPosition(), 5), ObjectModelEntryFlags::live }, { "workplaceNumber", OBJECT_MODEL_FUNC_NOSELF((int32_t)reprap.GetGCodes().GetWorkplaceCoordinateSystemNumber() - 1), ObjectModelEntryFlags::none }, - { "workspaceNumber", OBJECT_MODEL_FUNC_NOSELF((int32_t)reprap.GetGCodes().GetWorkplaceCoordinateSystemNumber()), ObjectModelEntryFlags::none }, + { "workspaceNumber", OBJECT_MODEL_FUNC_NOSELF((int32_t)reprap.GetGCodes().GetWorkplaceCoordinateSystemNumber()), ObjectModelEntryFlags::obsolete }, // 1. Move.Idle members { "factor", OBJECT_MODEL_FUNC_NOSELF(reprap.GetPlatform().GetIdleCurrentFactor(), 1), ObjectModelEntryFlags::none }, @@ -601,10 +601,10 @@ void Move::BedTransform(float xyzPoint[MaxAxes], const Tool *tool) const noexcep float zCorrection = 0.0; unsigned int numCorrections = 0; const GridDefinition& grid = GetGrid(); - const AxesBitmap axis1Axes = Tool::GetAxisMapping(tool, grid.GetNumber1()); + const AxesBitmap axis1Axes = Tool::GetAxisMapping(tool, grid.GetAxisNumber(1)); // Transform the Z coordinate based on the average correction for each axis used as an X or Y axis. - Tool::GetAxisMapping(tool, grid.GetNumber0()) + Tool::GetAxisMapping(tool, grid.GetAxisNumber(0)) .Iterate([this, xyzPoint, tool, axis1Axes, &zCorrection, &numCorrections](unsigned int axis0Axis, unsigned int) { const float axis0Coord = xyzPoint[axis0Axis] + Tool::GetOffset(tool, axis0Axis); @@ -637,10 +637,10 @@ void Move::InverseBedTransform(float xyzPoint[MaxAxes], const Tool *tool) const float zCorrection = 0.0; unsigned int numCorrections = 0; const GridDefinition& grid = GetGrid(); - const AxesBitmap axis1Axes = Tool::GetAxisMapping(tool, grid.GetNumber1()); + const AxesBitmap axis1Axes = Tool::GetAxisMapping(tool, grid.GetAxisNumber(1)); // Transform the Z coordinate based on the average correction for each axis used as an X or Y axis. - Tool::GetAxisMapping(tool, grid.GetNumber0()) + Tool::GetAxisMapping(tool, grid.GetAxisNumber(0)) .Iterate([this, xyzPoint, tool, axis1Axes, &zCorrection, &numCorrections](unsigned int axis0Axis, unsigned int) { const float axis0Coord = xyzPoint[axis0Axis] + Tool::GetOffset(tool, axis0Axis); @@ -686,7 +686,7 @@ void Move::SetZeroHeightError(const float coords[MaxAxes]) noexcept memcpyf(tempCoords, coords, ARRAY_SIZE(tempCoords)); AxisTransform(tempCoords, nullptr); const GridDefinition& grid = GetGrid(); - zShift = -heightMap.GetInterpolatedHeightError(tempCoords[grid.GetNumber0()], tempCoords[grid.GetNumber1()]); + zShift = -heightMap.GetInterpolatedHeightError(tempCoords[grid.GetAxisNumber(0)], tempCoords[grid.GetAxisNumber(1)]); } else { |