MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / RunStateMachine

Method RunStateMachine

src/GCodes/GCodes4.cpp:43–2017  ·  view source on GitHub ↗

Execute a step of the state machine CAUTION: don't allocate any long strings or other large objects directly within this function. The reason is that this function calls FinishedBedProbing(), which on a delta calls DoAutoCalibration(), which uses lots of stack. So any large local objects allocated here increase the amount of MAIN stack size needed.

Source from the content-addressed store, hash-verified

41// The reason is that this function calls FinishedBedProbing(), which on a delta calls DoAutoCalibration(), which uses lots of stack.
42// So any large local objects allocated here increase the amount of MAIN stack size needed.
43void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
44{
45#if HAS_SBC_INTERFACE
46 // Wait for the G-code replies and abort requests to go before anything else is done in the state machine
47 if (reprap.UsingSbcInterface() && (gb.IsAbortRequested() || gb.IsAbortAllRequested()))
48 {
49 return;
50 }
51 bool reportPause = false;
52#endif
53
54 // Perform the next operation of the state machine for this gcode source
55 GCodeResult stateMachineResult = GCodeResult::ok;
56
57 MovementState& ms = GetMovementState(gb);
58 const GCodeState state = gb.GetState();
59 Move& move = reprap.GetMove();
60 switch (state)
61 {
62 case GCodeState::waitingForSpecialMoveToComplete:
63 if (WaitForEndstopOrProbingMoveToFinish(gb)) // movement should already be locked, but we need to wait for standstill and fetch the current position
64 {
65 // Check whether we need to action any endstops
66 if (ms.axesToHome.IsNonEmpty()) // check whether we made any G1 H1 moves and need to set axis positions
67 {
68 if (move.GetKinematics().GetHomingMode() == HomingMode::homeCartesianAxes)
69 {
70 // The call to LockCurrentMovementSystemAndWaitForStandstill has already converted the motor endpoints to machine coordinates,
71 // however it has applied the inverse axis transform. We want to set the position after axis transform. So re-apply the transform.
72 float ncoords[MaxAxes];
73 memcpyf(ncoords, ms.coords, ARRAY_SIZE(ncoords));
74 move.AxisAndBedTransform(ncoords, ms.currentTool, true);
75
76 // Now change the coordinates after axis transform corresponding to the endstops that triggered
77 const AxesBitmap axesToHome = ms.axesToHome & ms.endstopsTriggered;
78 axesToHome.Iterate([this, &move, &ncoords](unsigned int axis, unsigned int) noexcept
79 {
80 const EndStopPosition stopType = platform.GetEndstops().GetEndStopPosition(axis);
81 if (stopType == EndStopPosition::highEndStop)
82 {
83 ncoords[axis] = move.AxisMaximum(axis);
84 }
85 else if (stopType == EndStopPosition::lowEndStop)
86 {
87 ncoords[axis] = move.AxisMinimum(axis);
88 }
89 SetAxisIsHomed(axis);
90 }
91 );
92
93 // Update the endpoints and start coordinates
94 move.UpdateStartCoordinates(ms.GetNumber(), ncoords);
95 int32_t endpoints[MaxAxes];
96 move.CartesianToMotorSteps(ncoords, endpoints, false);
97 // Only pass axis (not extruder) drives in the following, we don't want to modify extruder positions
98 ms.ChangeEndpointsAfterHoming(ms.logicalDrivesOwned & LogicalDrivesBitmap::MakeLowestNBits(numTotalAxes), endpoints);
99
100 // Update the machine and user coordinates

Callers

nothing calls this directly

Calls 15

IsSimulatingFunction · 0.85
ParameterLettersToBitmapFunction · 0.85
ConvertSpeedFromMmPerMinFunction · 0.85
IsReadyFunction · 0.85
ConvertSpeedFromMmPerSecFunction · 0.85
ExtruderToLogicalDriveFunction · 0.85
UsingSbcInterfaceMethod · 0.80
AxisAndBedTransformMethod · 0.80
GetEndStopPositionMethod · 0.80
AxisMaximumMethod · 0.80
AxisMinimumMethod · 0.80

Tested by

no test coverage detected