Skip to content
This repository was archived by the owner on Jul 9, 2020. It is now read-only.

Commit 5bdc971

Browse files
committed
3.0RC1 final(?)
Fixed issue with G1 H1 moves when endstops are not already triggered. There is still an issue if a move involves only remote drivers and a main board endstop switch. Don't set up a default bed heater on Duet 3 Fixed issue when creating a switch endstop failed
1 parent 9ec73aa commit 5bdc971

File tree

7 files changed

+111
-30
lines changed

7 files changed

+111
-30
lines changed

src/CAN/CanMotion.cpp

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void CanMotion::FinishMovement(uint32_t moveStartTime)
112112
CanMessageBuffer *buf;
113113
while ((buf = movementBufferList) != nullptr)
114114
{
115-
boardsActiveInLastMove.SetBit(buf->id.Dst());
115+
boardsActiveInLastMove.SetBit(buf->id.Dst()); //TODO should we set this if there were no steps for drives on the board, just drives to be enabled?
116116
movementBufferList = buf->next;
117117
buf->msg.move.whenToExecute = moveStartTime;
118118
CanInterface::SendMotion(buf); // queues the buffer for sending and frees it when done
@@ -183,17 +183,45 @@ void CanMotion::InsertHiccup(uint32_t numClocks)
183183
CanInterface::WakeCanSender();
184184
}
185185

186-
void CanMotion::StopDriver(DriverId driver)
186+
void CanMotion::StopDriver(bool isBeingPrepared, DriverId driver)
187187
{
188-
driversToStop[driversToStopIndexBeingFilled].AddEntry(driver);
189-
CanInterface::WakeCanSender();
188+
if (isBeingPrepared)
189+
{
190+
// Search for the correct movement buffer
191+
CanMessageBuffer* buf = movementBufferList;
192+
while (buf != nullptr && buf->id.Dst() != driver.boardAddress)
193+
{
194+
buf = buf->next;
195+
}
196+
197+
if (buf != nullptr)
198+
{
199+
buf->msg.move.perDrive[driver.localDriver].steps = 0;
200+
}
201+
}
202+
else
203+
{
204+
driversToStop[driversToStopIndexBeingFilled].AddEntry(driver);
205+
CanInterface::WakeCanSender();
206+
}
190207
}
191208

192-
void CanMotion::StopAxis(size_t axis)
209+
void CanMotion::StopAxis(bool isBeingPrepared, size_t axis)
193210
{
194-
if (!stopAllFlag)
211+
const AxisDriversConfig& cfg = reprap.GetPlatform().GetAxisDriversConfig(axis);
212+
if (isBeingPrepared)
213+
{
214+
for (size_t i = 0; i < cfg.numDrivers; ++i)
215+
{
216+
const DriverId driver = cfg.driverNumbers[i];
217+
if (driver.IsRemote())
218+
{
219+
StopDriver(true, driver);
220+
}
221+
}
222+
}
223+
else if (!stopAllFlag)
195224
{
196-
const AxisDriversConfig& cfg = reprap.GetPlatform().GetAxisDriversConfig(axis);
197225
for (size_t i = 0; i < cfg.numDrivers; ++i)
198226
{
199227
const DriverId driver = cfg.driverNumbers[i];
@@ -206,10 +234,25 @@ void CanMotion::StopAxis(size_t axis)
206234
}
207235
}
208236

209-
void CanMotion::StopAll()
237+
void CanMotion::StopAll(bool isBeingPrepared)
210238
{
211-
stopAllFlag = true;
212-
CanInterface::WakeCanSender();
239+
if (isBeingPrepared)
240+
{
241+
// We still send the messages so that the drives get enabled, but we set the steps to zero
242+
for (CanMessageBuffer *buf = movementBufferList; buf != nullptr; buf = buf->next)
243+
{
244+
buf->msg.move.accelerationClocks = buf->msg.move.decelClocks = buf->msg.move.steadyClocks = 0;
245+
for (size_t drive = 0; drive < ARRAY_SIZE(buf->msg.move.perDrive); ++drive)
246+
{
247+
buf->msg.move.perDrive[drive].steps = 0;
248+
}
249+
}
250+
}
251+
else
252+
{
253+
stopAllFlag = true;
254+
CanInterface::WakeCanSender();
255+
}
213256
}
214257

215258
#endif

src/CAN/CanMotion.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ namespace CanMotion
2525

2626
// The next 4 functions may be called from the step ISR, so they can't send CAN messages directly
2727
void InsertHiccup(uint32_t numClocks);
28-
void StopDriver(DriverId driver);
29-
void StopAxis(size_t axis);
30-
void StopAll();
28+
void StopDriver(bool isBeingPrepared, DriverId driver);
29+
void StopAxis(bool isBeingPrepared, size_t axis);
30+
void StopAll(bool isBeingPrepared);
3131
}
3232

3333
#endif

src/Endstops/EndstopsManager.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,14 @@ GCodeResult EndstopsManager::HandleM574(GCodeBuffer& gb, const StringRef& reply,
293293
axisEndstops[lastAxisSeen] = nullptr;
294294
SwitchEndstop * const sw = new SwitchEndstop(lastAxisSeen, lastPosSeen);
295295
const GCodeResult rslt = sw->Configure(gb, reply);
296-
axisEndstops[lastAxisSeen] = sw;
296+
if (rslt == GCodeResult::ok)
297+
{
298+
axisEndstops[lastAxisSeen] = sw;
299+
}
300+
else
301+
{
302+
delete sw;
303+
}
297304
return rslt;
298305
}
299306

src/Heating/Heat.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ Heat::Heat() noexcept
9595
{
9696
h = -1;
9797
}
98+
#if !DUET3
9899
bedHeaters[0] = DefaultBedHeater;
100+
#endif
101+
99102
for (int8_t& h : chamberHeaters)
100103
{
101104
h = -1;

src/Movement/DDA.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
12681268
const AxisDriversConfig& config = platform.GetAxisDriversConfig(Z_AXIS);
12691269
if (drive < config.numDrivers)
12701270
{
1271-
const int32_t delta = lrintf(directionVector[drive] * totalDistance * reprap.GetPlatform().DriveStepsPerUnit(Z_AXIS));
1271+
const int32_t delta = lrintf(directionVector[drive] * totalDistance * platform.DriveStepsPerUnit(Z_AXIS));
12721272
const DriverId driver = config.driverNumbers[drive];
12731273
#if SUPPORT_CAN_EXPANSION
12741274
if (driver.IsRemote())
@@ -1308,7 +1308,7 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
13081308
const int32_t delta = endPoint[drive] - prev->endPoint[drive];
13091309
if (platform.GetDriversBitmap(drive) != 0) // if any of the drives is local
13101310
{
1311-
reprap.GetPlatform().EnableLocalDrivers(drive);
1311+
platform.EnableLocalDrivers(drive);
13121312
DriveMovement* const pdm = DriveMovement::Allocate(drive, DMState::moving);
13131313
pdm->totalSteps = labs(delta);
13141314
pdm->direction = (delta >= 0);
@@ -1352,7 +1352,7 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
13521352
if (flags.continuousRotationShortcut && reprap.GetMove().GetKinematics().IsContinuousRotationAxis(drive))
13531353
{
13541354
// This is a continuous rotation axis, so we may have adjusted the move to cross the 180 degrees position
1355-
const int32_t stepsPerRotation = lrintf(360.0 * reprap.GetPlatform().DriveStepsPerUnit(drive));
1355+
const int32_t stepsPerRotation = lrintf(360.0 * platform.DriveStepsPerUnit(drive));
13561356
if (delta > stepsPerRotation/2)
13571357
{
13581358
delta -= stepsPerRotation;
@@ -1436,7 +1436,7 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
14361436
{
14371437
DriveMovement* const pdm = DriveMovement::Allocate(drive, DMState::moving);
14381438
const bool stepsToDo = pdm->PrepareExtruder(*this, params, extrusionPending[extruder], speedChange, flags.usePressureAdvance);
1439-
reprap.GetPlatform().EnableLocalDrivers(drive);
1439+
platform.EnableLocalDrivers(drive);
14401440

14411441
if (stepsToDo)
14421442
{
@@ -1475,7 +1475,7 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
14751475
ClearBit(additionalAxisMotorsToEnable, drive);
14761476
if (platform.GetDriversBitmap(drive) != 0) // if any of the connected axis drives is local
14771477
{
1478-
reprap.GetPlatform().EnableLocalDrivers(drive);
1478+
platform.EnableLocalDrivers(drive);
14791479
}
14801480
#if SUPPORT_CAN_EXPANSION
14811481
const AxisDriversConfig& config = platform.GetAxisDriversConfig(drive);
@@ -1493,9 +1493,18 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
14931493

14941494
const DDAState st = prev->state;
14951495
afterPrepare.moveStartTime = (st == DDAState::executing || st == DDAState::frozen)
1496-
? prev->afterPrepare.moveStartTime + prev->clocksNeeded // this move will follow the previous one, so calculate the start time assuming no more hiccups
1496+
? prev->afterPrepare.moveStartTime + prev->clocksNeeded // this move will follow the previous one, so calculate the start time assuming no more hiccups
14971497
: StepTimer::GetTimerTicks() + MovementStartDelayClocks; // else this move is the first so start it after a short delay
14981498

1499+
if (flags.checkEndstops)
1500+
{
1501+
// Before we send movement commands to remote drives, if any endstop switches we are monitoring are already set, make sure we don't start the motors concerned.
1502+
// This is especially important when using CAN-connected motors or endstops, because we rely on receiving "endstop changed" messages.
1503+
// Moves that check endstops are always run as isolated moves, so there can be no move in progress and the endstops must already be primed.
1504+
platform.EnableAllSteppingDrivers();
1505+
CheckEndstops(platform); // this may modify pending CAN moves, and may set status 'completed'
1506+
}
1507+
14991508
#if SUPPORT_CAN_EXPANSION
15001509
CanMotion::FinishMovement(afterPrepare.moveStartTime);
15011510
#endif
@@ -1520,7 +1529,10 @@ void DDA::Prepare(uint8_t simMode, float extrusionPending[]) noexcept
15201529
#endif
15211530
}
15221531

1523-
state = frozen; // must do this last so that the ISR doesn't start executing it before we have finished setting it up
1532+
if (state != completed)
1533+
{
1534+
state = frozen; // must do this last so that the ISR doesn't start executing it before we have finished setting it up
1535+
}
15241536
}
15251537

15261538
// Take a unit positive-hyperquadrant vector, and return the factor needed to obtain
@@ -1625,8 +1637,11 @@ float DDA::NormaliseXYZ() noexcept
16251637
}
16261638
}
16271639

1640+
// Check the endstops, given that we know that this move checks endstops.
1641+
// Either this move is currently executing (DDARing.currentDDA == this) and the state is 'executing', or we have almost finished preparing it and the state is 'provisional'.
16281642
void DDA::CheckEndstops(Platform& platform) noexcept
16291643
{
1644+
const bool fromPrepare = (state == DDAState::provisional); // determine this before anything sets the state to 'completed'
16301645
for (;;)
16311646
{
16321647
const EndstopHitDetails hitDetails = platform.GetEndstops().CheckEndstops(flags.goingSlow);
@@ -1635,7 +1650,7 @@ void DDA::CheckEndstops(Platform& platform) noexcept
16351650
case EndstopHitAction::stopAll:
16361651
MoveAborted(); // set the state to completed and recalculate the endpoints
16371652
#if SUPPORT_CAN_EXPANSION
1638-
CanMotion::StopAll();
1653+
CanMotion::StopAll(fromPrepare);
16391654
#endif
16401655
if (hitDetails.isZProbe)
16411656
{
@@ -1658,11 +1673,11 @@ void DDA::CheckEndstops(Platform& platform) noexcept
16581673
#if SUPPORT_CAN_EXPANSION
16591674
if (state == completed) // if the call to StopDrive flagged the move as completed
16601675
{
1661-
CanMotion::StopAll();
1676+
CanMotion::StopAll(fromPrepare);
16621677
}
16631678
else
16641679
{
1665-
CanMotion::StopAxis(hitDetails.axis);
1680+
CanMotion::StopAxis(fromPrepare, hitDetails.axis);
16661681
}
16671682
#endif
16681683
if (hitDetails.setAxisLow)
@@ -1681,7 +1696,7 @@ void DDA::CheckEndstops(Platform& platform) noexcept
16811696
#if SUPPORT_CAN_EXPANSION
16821697
if (hitDetails.driver.IsRemote())
16831698
{
1684-
CanMotion::StopDriver(hitDetails.driver);
1699+
CanMotion::StopDriver(fromPrepare, hitDetails.driver);
16851700
}
16861701
else
16871702
#endif
@@ -1761,9 +1776,12 @@ pre(state == frozen)
17611776

17621777
if (activeDMs != nullptr)
17631778
{
1764-
p.EnableAllSteppingDrivers(); // make sure that all drivers are enabled
1779+
if (!flags.checkEndstops)
1780+
{
1781+
p.EnableAllSteppingDrivers(); // make sure that all drivers are enabled
1782+
}
17651783
const size_t numTotalAxes = reprap.GetGCodes().GetTotalAxes();
1766-
unsigned int extrusions = 0, retractions = 0; // bitmaps of extruding and retracting drives
1784+
unsigned int extrusions = 0, retractions = 0; // bitmaps of extruding and retracting drives
17671785
for (const DriveMovement* pdm = activeDMs; pdm != nullptr; pdm = pdm->nextDM)
17681786
{
17691787
const size_t drive = pdm->drive;

src/Movement/DDARing.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,18 @@ void DDARing::Spin(uint8_t simulationMode, bool shouldStartMove) noexcept
204204
// No DDA is executing, so start executing a new one if possible
205205
if (shouldStartMove || !CanAddMove())
206206
{
207-
PrepareMoves(getPointer, 0, 0, simulationMode);
208-
DDA * const dda = getPointer; // capture volatile variable
207+
DDA * dda = getPointer; // capture volatile variable
208+
if (dda->GetState() == DDA::provisional)
209+
{
210+
PrepareMoves(dda, 0, 0, simulationMode);
211+
while (dda->GetState() == DDA::completed)
212+
{
213+
// We prepared the move but found there was nothing to do because endstops are already triggered
214+
getPointer = dda = dda->GetNext();
215+
completedMoves++;
216+
}
217+
}
218+
209219
if (dda->GetState() == DDA::frozen)
210220
{
211221
if (simulationMode != 0)

src/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#endif
2121

2222
#ifndef DATE
23-
# define DATE "2019-12-16b3"
23+
# define DATE "2019-12-16b7"
2424
#endif
2525

2626
#define AUTHORS "reprappro, dc42, chrishamm, t3p3, dnewman, printm3d"

0 commit comments

Comments
 (0)