Lock movement and wait for pending moves to finish. Return true if successful, false if we need to try again later. As a side-effect it updates the user coordinates from the machine coordinates.
| 1769 | // Return true if successful, false if we need to try again later. |
| 1770 | // As a side-effect it updates the user coordinates from the machine coordinates. |
| 1771 | bool GCodes::LockMovementSystemAndWaitForStandstill(GCodeBuffer& gb, MovementSystemNumber msNumber) noexcept |
| 1772 | { |
| 1773 | // Lock movement to stop another source adding moves to the queue |
| 1774 | if (!LockResource(gb, MoveResourceBase + msNumber)) |
| 1775 | { |
| 1776 | return false; |
| 1777 | } |
| 1778 | |
| 1779 | MovementState& ms = moveStates[msNumber]; |
| 1780 | if (ms.segmentsLeft != 0) // has the last move generated been fully transferred to the movement queue? |
| 1781 | { |
| 1782 | return false; // if no |
| 1783 | } |
| 1784 | |
| 1785 | Move& move = reprap.GetMove(); |
| 1786 | switch (gb.GetChannel().ToBaseType()) |
| 1787 | { |
| 1788 | case GCodeChannel::Queue: |
| 1789 | case GCodeChannel::Queue2: |
| 1790 | break; |
| 1791 | |
| 1792 | default: |
| 1793 | if (!move.WaitingForAllMovesFinished(msNumber |
| 1794 | #if SUPPORT_ASYNC_MOVES |
| 1795 | , ms.logicalDrivesOwned |
| 1796 | #endif |
| 1797 | ) |
| 1798 | ) |
| 1799 | { |
| 1800 | return false; |
| 1801 | } |
| 1802 | |
| 1803 | if (!( |
| 1804 | #if SUPPORT_ASYNC_MOVES |
| 1805 | ((msNumber == 1) ? Queue2GCode() : QueuedGCode()) |
| 1806 | #else |
| 1807 | QueuedGCode() |
| 1808 | #endif |
| 1809 | ->IsIdle() && ms.codeQueue->IsIdle())) |
| 1810 | { |
| 1811 | return false; |
| 1812 | } |
| 1813 | break; |
| 1814 | } |
| 1815 | |
| 1816 | gb.MotionStopped(); // must do this after we have finished waiting, so that we don't stop waiting when executing G4 |
| 1817 | |
| 1818 | // Get the current positions. These may not be the same as the ones we remembered from last time if we just did a special move. |
| 1819 | //TODO we only need to do most of this if we did a special move |
| 1820 | ms.UpdateOwnedDriveEndpointsFromMotors(); // need to do this is the move was stopped prematurely e.g. due to an endstop switch or a Z probe |
| 1821 | move.MotorStepsToCartesian(MovementState::GetLastKnownEndpoints(), numVisibleAxes, numTotalAxes, ms.coords); |
| 1822 | move.UpdateStartCoordinates(ms.GetNumber(), ms.coords); |
| 1823 | move.InverseAxisAndBedTransform(ms.coords, ms.currentTool); |
| 1824 | UpdateUserPositionFromMachinePosition(gb, ms); |
| 1825 | |
| 1826 | #if SUPPORT_ASYNC_MOVES |
| 1827 | collisionChecker.ResetPositions(ms.coords, ms.GetAxesAndExtrudersOwned()); |
| 1828 |
nothing calls this directly
no test coverage detected