Skip to content

Commit

Permalink
Copy input shaping plan flags to CAN movement message
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Feb 4, 2023
1 parent da7d047 commit c5a4a73
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 204 deletions.
68 changes: 4 additions & 64 deletions src/CAN/CanMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ CanMessageBuffer *CanMotion::GetBuffer(const PrepParams& params, DriverId canDri

buf->next = movementBufferList;
movementBufferList = buf;

#if USE_REMOTE_INPUT_SHAPING
auto move = buf->SetupRequestMessage<CanMessageMovementLinearShaped>(0, CanId::MasterAddress, canDriver.boardAddress);
#else
auto move = buf->SetupRequestMessage<CanMessageMovementLinear>(0, CanInterface::GetCurrentMasterAddress(), canDriver.boardAddress);
#endif

// Common parameters
if (buf->next == nullptr)
Expand All @@ -136,86 +131,47 @@ CanMessageBuffer *CanMotion::GetBuffer(const PrepParams& params, DriverId canDri
else
{
// Save some maths by using the values from the previous buffer
#if USE_REMOTE_INPUT_SHAPING
move->accelerationClocks = buf->next->msg.moveLinearShaped.accelerationClocks;
move->steadyClocks = buf->next->msg.moveLinearShaped.steadyClocks;
move->decelClocks = buf->next->msg.moveLinearShaped.decelClocks;
#else
move->accelerationClocks = buf->next->msg.moveLinear.accelerationClocks;
move->steadyClocks = buf->next->msg.moveLinear.steadyClocks;
move->decelClocks = buf->next->msg.moveLinear.decelClocks;
#endif
}
move->initialSpeedFraction = params.initialSpeedFraction;
move->finalSpeedFraction = params.finalSpeedFraction;
#if USE_REMOTE_INPUT_SHAPING
move->numDriversMinusOne = canDriver.localDriver;
move->moveTypes = 0;
move->shaperAccelPhasesMinusOne = params.shapingPlan.accelSegments - 1;
move->shaperDecelPhasesMinusOne = params.shapingPlan.decelSegments - 1;
#else
move->pressureAdvanceDrives = 0;
move->numDrivers = canDriver.localDriver + 1;
move->zero = 0;
#endif

// Clear out the per-drive fields. Can't use a range-based FOR loop on a packed struct.
for (size_t drive = 0; drive < ARRAY_SIZE(move->perDrive); ++drive)
{
move->perDrive[drive].Init();
}
}
#if USE_REMOTE_INPUT_SHAPING
else if (canDriver.localDriver > buf->msg.moveLinearShaped.numDriversMinusOne)
{
buf->msg.moveLinearShaped.numDriversMinusOne = canDriver.localDriver;
}
#else
else if (canDriver.localDriver >= buf->msg.moveLinear.numDrivers)
{
buf->msg.moveLinear.numDrivers = canDriver.localDriver + 1;
}
#endif
return buf;
}

// This is called by DDA::Prepare for each active CAN DM in the move
#if USE_REMOTE_INPUT_SHAPING
void CanMotion::AddMovement(const PrepParams& params, DriverId canDriver, int32_t steps) noexcept
#else
void CanMotion::AddMovement(const PrepParams& params, DriverId canDriver, int32_t steps, bool usePressureAdvance) noexcept
#endif
{
CanMessageBuffer * const buf = GetBuffer(params, canDriver);
if (buf != nullptr)
{
#if USE_REMOTE_INPUT_SHAPING
buf->msg.moveLinearShaped.perDrive[canDriver.localDriver].iSteps = steps;
#else
buf->msg.moveLinear.perDrive[canDriver.localDriver].steps = steps;
if (usePressureAdvance)
{
buf->msg.moveLinear.pressureAdvanceDrives |= 1u << canDriver.localDriver;
}
#endif
}
}

#if USE_REMOTE_INPUT_SHAPING

void CanMotion::AddExtruderMovement(const PrepParams& params, DriverId canDriver, float extrusion, bool usePressureAdvance) noexcept
{
CanMessageBuffer * const buf = GetBuffer(params, canDriver);
if (buf != nullptr)
{
buf->msg.moveLinearShaped.perDrive[canDriver.localDriver].fDist = extrusion;
const auto mt = (usePressureAdvance) ? CanMessageMovementLinearShaped::MoveType::extruderWithPa : CanMessageMovementLinearShaped::MoveType::extruderNoPa;
buf->msg.moveLinearShaped.ChangeMoveTypeFromDefault(canDriver.localDriver, mt);
buf->msg.moveLinear.shapeAccelStart = params.shapingPlan.shapeAccelStart;
buf->msg.moveLinear.shapeAccelEnd = params.shapingPlan.shapeAccelEnd;
buf->msg.moveLinear.shapeDecelStart = params.shapingPlan.shapeDecelStart;
buf->msg.moveLinear.shapeDecelEnd = params.shapingPlan.shapeDecelEnd;
}
}

#endif

// This is called by DDA::Prepare when all DMs for CAN drives have been processed. Return the calculated move time in steps, or 0 if there are no CAN moves
uint32_t CanMotion::FinishMovement(const DDA& dda, uint32_t moveStartTime, bool simulating) noexcept
{
Expand All @@ -233,11 +189,7 @@ uint32_t CanMotion::FinishMovement(const DDA& dda, uint32_t moveStartTime, bool
do
{
CanMessageBuffer * const nextBuffer = buf->next; // must get this before sending the buffer, because sending the buffer releases it
#if USE_REMOTE_INPUT_SHAPING
CanMessageMovementLinear& msg = buf->msg.moveLinearShaped;
#else
CanMessageMovementLinear& msg = buf->msg.moveLinear;
#endif
if (msg.HasMotion())
{
msg.whenToExecute = moveStartTime;
Expand Down Expand Up @@ -363,11 +315,7 @@ void CanMotion::InternalStopDriverWhenProvisional(DriverId driver) noexcept

if (buf != nullptr)
{
#if USE_REMOTE_INPUT_SHAPING
buf->msg.moveLinearShaped.perDrive[driver.localDriver].steps = 0;
#else
buf->msg.moveLinear.perDrive[driver.localDriver].steps = 0;
#endif
}
}

Expand Down Expand Up @@ -467,19 +415,11 @@ void CanMotion::StopAll(const DDA& dda) noexcept
// We still send the messages so that the drives get enabled, but we set the steps to zero
for (CanMessageBuffer *buf = movementBufferList; buf != nullptr; buf = buf->next)
{
#if USE_REMOTE_INPUT_SHAPING
buf->msg.moveLinearShaped.accelerationClocks = buf->msg.moveLinearShaped.decelClocks = buf->msg.moveLinearShaped.steadyClocks = 0;
for (size_t drive = 0; drive < ARRAY_SIZE(buf->msg.moveLinearShaped.perDrive); ++drive)
{
buf->msg.moveLinearShaped.perDrive[drive].steps = 0;
}
#else
buf->msg.moveLinear.accelerationClocks = buf->msg.moveLinear.decelClocks = buf->msg.moveLinear.steadyClocks = 0;
for (size_t drive = 0; drive < ARRAY_SIZE(buf->msg.moveLinear.perDrive); ++drive)
{
buf->msg.moveLinear.perDrive[drive].steps = 0;
}
#endif
}
}
else if (stopList != nullptr)
Expand Down
5 changes: 0 additions & 5 deletions src/CAN/CanMotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ namespace CanMotion
{
void Init() noexcept;
void StartMovement() noexcept;
#if USE_REMOTE_INPUT_SHAPING
void AddMovement(const PrepParams& params, DriverId canDriver, int32_t steps) noexcept;
void AddExtruderMovement(const PrepParams& params, DriverId canDriver, float extrusion, bool usePressureAdvance) noexcept;
#else
void AddMovement(const PrepParams& params, DriverId canDriver, int32_t steps, bool usePressureAdvance) noexcept;
#endif
uint32_t FinishMovement(const DDA& dda, uint32_t moveStartTime, bool simulating) noexcept;
bool CanPrepareMove() noexcept;
CanMessageBuffer *GetUrgentMessage() noexcept;
Expand Down
6 changes: 0 additions & 6 deletions src/CAN/CommandProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,6 @@ void CommandProcessor::ProcessReceivedMessage(CanMessageBuffer *buf) noexcept
reprap.GetMove().AddMoveFromRemote(buf->msg.moveLinear);
return; // no reply needed

# if USE_REMOTE_INPUT_SHAPING
case CanMessageType::movementLinearShaped:
reprap.GetMove().AddShapedMoveFromRemote(buf->msg.moveLinearShaped);
return; // no reply needed
# endif

case CanMessageType::stopMovement:
reprap.GetMove().StopDrivers(buf->msg.stopMovement.whichDrives);
return; // no reply needed
Expand Down
94 changes: 0 additions & 94 deletions src/Movement/DDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,19 +685,13 @@ bool DDA::InitAsyncMove(DDARing& ring, const AsyncMove& nextMove) noexcept
// Set up a remote move. Return true if it represents real movement, else false.
// All values have already been converted to step clocks and the total distance has been normalised to 1.0.
//TODO pass the input shaping plan in the message. For now we don't use input shaping.
# if USE_REMOTE_INPUT_SHAPING
bool DDA::InitShapedFromRemote(const CanMessageMovementLinearShaped& msg) noexcept
# else
bool DDA::InitFromRemote(const CanMessageMovementLinear& msg) noexcept
#endif
{
afterPrepare.moveStartTime = StepTimer::ConvertToLocalTime(msg.whenToExecute);
clocksNeeded = msg.accelerationClocks + msg.steadyClocks + msg.decelClocks;
flags.all = 0;
flags.isRemote = true;
# if !USE_REMOTE_INPUT_SHAPING
flags.isPrintingMove = (msg.pressureAdvanceDrives != 0);
# endif

// Normalise the move to unit distance and convert time units from step clocks to seconds
totalDistance = 1.0;
Expand All @@ -723,97 +717,10 @@ bool DDA::InitFromRemote(const CanMessageMovementLinear& msg) noexcept
activeDMs = completedDMs = nullptr;
afterPrepare.drivesMoving.Clear();

# if USE_REMOTE_INPUT_SHAPING
const size_t numDrivers = min<size_t>(msg.numDriversMinusOne + 1, min<size_t>(NumDirectDrivers, MaxLinearDriversPerCanSlave));
# else
const size_t numDrivers = min<size_t>(msg.numDrivers, min<size_t>(NumDirectDrivers, MaxLinearDriversPerCanSlave));
# endif
for (size_t drive = 0; drive < numDrivers; drive++)
{
endPoint[drive] = prev->endPoint[drive]; // the steps for this move will be added later
# if USE_REMOTE_INPUT_SHAPING
switch (msg.GetMoveType(drive))
{
case CanMessageMovementLinearShaped::shapedAxis:
// Note, drivers that are not moving are set to shapedAxis, so we need to check that the driver really is moving
{
const int32_t delta = msg.perDrive[drive].iSteps;
if (delta != 0)
{
if (shapedSegments == nullptr)
{
// Calculate the segments needed for axis movement
//TODO the message will include input shaping info
shapedSegments = AxisShaper::GetUnshapedSegments(*this, params);
}

DriveMovement* const pdm = DriveMovement::Allocate(drive, DMState::idle);
pdm->totalSteps = labs(delta); // for now this is the number of net steps, but gets adjusted later if there is a reverse in direction
pdm->direction = (delta >= 0); // for now this is the direction of net movement, but gets adjusted later if it is a delta movement

reprap.GetPlatform().EnableDrivers(drive);
const bool stepsToDo = pdm->PrepareCartesianAxis(*this, params);
if (stepsToDo)
{
pdm->directionChanged = false;
InsertDM(pdm);
const uint32_t netSteps = (pdm->reverseStartStep < pdm->totalSteps) ? (2 * pdm->reverseStartStep) - pdm->totalSteps : pdm->totalSteps;
if (pdm->direction)
{
endPoint[drive] += netSteps;
}
else
{
endPoint[drive] -= netSteps;
}

// Check for sensible values, print them if they look dubious
if (reprap.Debug(moduleDda) && pdm->totalSteps > 1000000)
{
DebugPrintAll("rem");
}
}
else
{
DriveMovement::Release(pdm);
}
}
}
break;

case CanMessageMovementLinearShaped::shapedDelta:
{
if (shapedSegments == nullptr)
{
// Calculate the segments needed for axis movement
//TODO the message will include input shaping info
shapedSegments = AxisShaper::GetUnshapedSegments(*this, params);
}

//TODO
}
break;

case CanMessageMovementLinearShaped::extruderWithPa:
flags.usePressureAdvance = true; // either all extruder use pressure advance, or none do
// no break
case CanMessageMovementLinearShaped::MoveType::extruderNoPa:
{
if (unshapedSegments != nullptr)
{
unshapedSegments = AxisShaper::GetUnshapedSegments(*this, params);
}
if (unshapedSegments != nullptr)
{
DriveMovement* const pdm = DriveMovement::Allocate(drive, DMState::idle);
pdm->PrepareExtruder(*this, params);
InsertDM(pdm);
}
}
break;
}
}
# else
const int32_t delta = msg.perDrive[drive].steps;
if (delta != 0)
{
Expand Down Expand Up @@ -854,7 +761,6 @@ bool DDA::InitFromRemote(const CanMessageMovementLinear& msg) noexcept
}
}
}
# endif

// 2. Throw it away if there's no real movement.
if (activeDMs == nullptr)
Expand Down
4 changes: 0 additions & 4 deletions src/Movement/DDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ class DDA
#endif

#if SUPPORT_REMOTE_COMMANDS
# if USE_REMOTE_INPUT_SHAPING
bool InitShapedFromRemote(const CanMessageMovementLinearShaped& msg) noexcept;
# else
bool InitFromRemote(const CanMessageMovementLinear& msg) noexcept;
# endif
void StopDrivers(uint16_t whichDrives) noexcept;
#endif

Expand Down
19 changes: 0 additions & 19 deletions src/Movement/DDARing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,23 +1018,6 @@ uint32_t DDARing::ManageLaserPower() const noexcept

#if SUPPORT_REMOTE_COMMANDS

# if USE_REMOTE_INPUT_SHAPING

// Add a move from the ATE to the movement queue
void DDARing::AddShapedMoveFromRemote(const CanMessageMovementLinearShaped& msg) noexcept
{
if (addPointer->GetState() == DDA::empty)
{
if (addPointer->InitShapedFromRemote(msg))
{
addPointer = addPointer->GetNext();
scheduledMoves++;
}
}
}

# else

// Add a move from the ATE to the movement queue
void DDARing::AddMoveFromRemote(const CanMessageMovementLinear& msg) noexcept
{
Expand All @@ -1048,8 +1031,6 @@ void DDARing::AddMoveFromRemote(const CanMessageMovementLinear& msg) noexcept
}
}

# endif

void DDARing::StopDrivers(uint16_t whichDrives) noexcept
{
const uint32_t oldPrio = ChangeBasePriority(NvicPriorityStep);
Expand Down
4 changes: 0 additions & 4 deletions src/Movement/DDARing.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ class DDARing INHERIT_OBJECT_MODEL
GCodeResult ConfigureMovementQueue(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);

#if SUPPORT_REMOTE_COMMANDS
# if USE_REMOTE_INPUT_SHAPING
void AddShapedMoveFromRemote(const CanMessageMovementLinearShaped& msg) noexcept; // add a move from the ATE to the movement queue
# else
void AddMoveFromRemote(const CanMessageMovementLinear& msg) noexcept; // add a move from the ATE to the movement queue
# endif
void StopDrivers(uint16_t whichDrives) noexcept;
#endif

Expand Down
8 changes: 0 additions & 8 deletions src/Movement/Move.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,11 @@ class Move INHERIT_OBJECT_MODEL
static const TaskBase *GetMoveTaskHandle() noexcept { return &moveTask; }

#if SUPPORT_REMOTE_COMMANDS
# if USE_REMOTE_INPUT_SHAPING
void AddShapeddMoveFromRemote(const CanMessageMovementLinearShaped& msg) noexcept // add a move from the ATE to the movement queue
{
rings[0].AddMoveFromRemote(msg);
MoveAvailable();
}
# else
void AddMoveFromRemote(const CanMessageMovementLinear& msg) noexcept // add a move from the ATE to the movement queue
{
rings[0].AddMoveFromRemote(msg);
MoveAvailable();
}
# endif

void StopDrivers(uint16_t whichDrives) noexcept
{
Expand Down

0 comments on commit c5a4a73

Please sign in to comment.