Skip to content

Commit

Permalink
Fixed bug in previous change; added debug check on segment length
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Feb 21, 2024
1 parent 4d6cd6e commit 5a0fe4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/Movement/AxisShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ void AxisShaper::PlanShaping(DDA& dda, PrepParams& params, bool shapingEnabled)
(double)dda.startSpeed, (double)dda.endSpeed, (double)dda.topSpeed, (double)newTopSpeed, (double)dda.acceleration, (double)dda.deceleration,
(double)dda.totalDistance, (double)(proposedAccelPlan.distance + proposedDecelPlan.distance - dda.totalDistance), (double)params.accelDistance);
}

params.topSpeed = newTopSpeed;
params.modified = true;
if (newTopSpeed > dda.startSpeed)
Expand Down Expand Up @@ -612,18 +613,7 @@ void AxisShaper::PlanShaping(DDA& dda, PrepParams& params, bool shapingEnabled)
MoveSegment * const decelSegs = GetDecelerationSegments(dda, params);
dda.segments = FinishShapedSegments(dda, params, accelSegs, decelSegs);
#if 1 //debug
// Check that the calculated distance of each segment agrees with its length
unsigned int n = 0;
for (const MoveSegment *seg = dda.segments; seg != nullptr; seg = seg->GetNext())
{
const float diff = seg->GetCalculatedDistance() - seg->GetSegmentLength();
if (fabsf(diff) * 1000 > seg->GetSegmentLength())
{
debugPrintf("Seg length diff %.2e at %u\n", (double)diff, n);
MoveSegment::DebugPrintList('S', dda.segments);
}
++n;
}
MoveSegment::DebugCheckSegments(dda.segments);
#endif
}
else
Expand Down Expand Up @@ -891,7 +881,7 @@ void AxisShaper::ProposeShapeDecelBoth(const DDA& dda, const PrepParams& params,
}
else
{
const float extraDecelDistance = GetExtraDecelStartDistance(dda.topSpeed, params.deceleration) + GetExtraDecelEndDistance(dda.endSpeed, params.deceleration);
const float extraDecelDistance = GetExtraDecelStartDistance(params.topSpeed, params.deceleration) + GetExtraDecelEndDistance(dda.endSpeed, params.deceleration);
proposal.distance = dda.totalDistance - params.decelStartDistance + extraDecelDistance;
proposal.clocks = params.decelClocks + extraClocksAtStart + extraClocksAtEnd;
proposal.acceleration = params.deceleration;
Expand Down Expand Up @@ -1062,11 +1052,11 @@ MoveSegment *AxisShaper::GetDecelerationSegments(const DDA& dda, PrepParams& par
endDecelSegs = MoveSegment::Allocate(endDecelSegs);
const float deceleration = params.deceleration * (1.0 - coefficients[i]);
const float segTime = durations[i];
const float speedDecreasee = deceleration * segTime;
segStartSpeed += speedDecreasee;
const float speedDecrease = deceleration * segTime;
segStartSpeed += speedDecrease;
const float b = segStartSpeed/deceleration;
const float c = -2.0/deceleration;
const float segLen = (segStartSpeed + (-0.5 * speedDecreasee)) * segTime;
const float segLen = (segStartSpeed - (0.5 * speedDecrease)) * segTime;
endDecelSegs->SetNonLinear(segLen, segTime, b, c, -deceleration);
endDistance -= segLen;
}
Expand Down
17 changes: 17 additions & 0 deletions src/Movement/MoveSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ void MoveSegment::DebugPrint(char ch) const noexcept
}
}

// Check that the calculated distance of each segment agrees with its length
/*static*/ void MoveSegment::DebugCheckSegments(const MoveSegment *segs) noexcept
{
unsigned int n = 0;
while (segs != nullptr)
{
const float diff = segs->GetCalculatedDistance() - segs->GetSegmentLength();
if (fabsf(diff) * 1000 > segs->GetSegmentLength())
{
debugPrintf("Seg length diff %.2e at %u\n", (double)diff, n);
MoveSegment::DebugPrintList('S', segs);
}
++n;
segs = segs->GetNext();
}
}

// End
1 change: 1 addition & 0 deletions src/Movement/MoveSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class MoveSegment
void AddToTail(MoveSegment *tail) noexcept;
void DebugPrint(char ch) const noexcept;
static void DebugPrintList(char ch, const MoveSegment *segs) noexcept;
static void DebugCheckSegments(const MoveSegment *segs) noexcept;

// Allocate a MoveSegment, clearing the flags
static MoveSegment *Allocate(MoveSegment *next) noexcept;
Expand Down

0 comments on commit 5a0fe4f

Please sign in to comment.