Add movement limits
Remember whether each axis has been homed. Don't allow z-homing or G31 procedure unless X and Y have been homed. If axes have been homed, limit travel to size of bed.
This commit is contained in:
parent
b578dd5bc4
commit
0c47fbc923
2 changed files with 63 additions and 16 deletions
71
GCodes.cpp
71
GCodes.cpp
|
@ -84,6 +84,7 @@ void GCodes::Init()
|
|||
active = true;
|
||||
longWait = platform->Time();
|
||||
dwellTime = longWait;
|
||||
axisIsHomed[0] = axisIsHomed[1] = axisIsHomed[2] = false;
|
||||
}
|
||||
|
||||
void GCodes::doFilePrint(GCodeBuffer* gb)
|
||||
|
@ -295,8 +296,9 @@ bool GCodes::Pop()
|
|||
|
||||
// Move expects all axis movements to be absolute, and all
|
||||
// extruder drive moves to be relative. This function serves that.
|
||||
// If applyLimits is true and we have homed the relevant axes, then we don't allow movement beyond the bed.
|
||||
|
||||
void GCodes::LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92)
|
||||
void GCodes::LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92, bool applyLimits)
|
||||
{
|
||||
float absE;
|
||||
|
||||
|
@ -306,20 +308,38 @@ void GCodes::LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92)
|
|||
{
|
||||
if(gb->Seen(gCodeLetters[i]))
|
||||
{
|
||||
if(!axesRelative || doingG92)
|
||||
moveBuffer[i] = gb->GetFValue()*distanceScale;
|
||||
else
|
||||
moveBuffer[i] += gb->GetFValue()*distanceScale;
|
||||
float moveArg = gb->GetFValue()*distanceScale;
|
||||
if (axesRelative && !doingG92)
|
||||
{
|
||||
moveArg += moveBuffer[i];
|
||||
}
|
||||
if (applyLimits && axisIsHomed[i] & !doingG92)
|
||||
{
|
||||
if (moveArg < (i == 2 ? -5.0 : 0.0)) // limits are 0 for X, Y and -5mm for Z
|
||||
{
|
||||
moveArg = 0.0;
|
||||
}
|
||||
else if (moveArg > platform->AxisLength(i))
|
||||
{
|
||||
moveArg = platform->AxisLength(i);
|
||||
}
|
||||
}
|
||||
moveBuffer[i] = moveArg;
|
||||
if (doingG92)
|
||||
{
|
||||
axisIsHomed[i] = true; // doing a G92 is equivalent to homing the axis
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if(gb->Seen(gCodeLetters[i]))
|
||||
{
|
||||
float moveArg = gb->GetFValue()*distanceScale;
|
||||
if(drivesRelative || doingG92)
|
||||
moveBuffer[i] = gb->GetFValue()*distanceScale;
|
||||
moveBuffer[i] = moveArg;
|
||||
else
|
||||
{
|
||||
absE = gb->GetFValue()*distanceScale;
|
||||
absE = moveArg;
|
||||
moveBuffer[i] = absE - lastPos[i - AXES];
|
||||
lastPos[i - AXES] = absE;
|
||||
}
|
||||
|
@ -352,8 +372,6 @@ bool GCodes::SetUpMove(GCodeBuffer *gb)
|
|||
if(!reprap.GetMove()->GetCurrentState(moveBuffer))
|
||||
return false;
|
||||
|
||||
LoadMoveBufferFromGCode(gb, false);
|
||||
|
||||
checkEndStops = false;
|
||||
if(gb->Seen('S'))
|
||||
{
|
||||
|
@ -361,6 +379,8 @@ bool GCodes::SetUpMove(GCodeBuffer *gb)
|
|||
checkEndStops = true;
|
||||
}
|
||||
|
||||
LoadMoveBufferFromGCode(gb, false, !checkEndStops);
|
||||
|
||||
moveAvailable = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -488,7 +508,7 @@ bool GCodes::SetPositions(GCodeBuffer *gb)
|
|||
if(!AllMovesAreFinishedAndMoveBufferIsLoaded())
|
||||
return false;
|
||||
|
||||
LoadMoveBufferFromGCode(gb, true);
|
||||
LoadMoveBufferFromGCode(gb, true, false);
|
||||
reprap.GetMove()->SetLiveCoordinates(moveBuffer);
|
||||
reprap.GetMove()->SetPositions(moveBuffer);
|
||||
|
||||
|
@ -554,8 +574,11 @@ bool GCodes::OffsetAxes(GCodeBuffer* gb)
|
|||
|
||||
// Home one or more of the axes. Which ones are decided by the
|
||||
// booleans homeX, homeY and homeZ.
|
||||
|
||||
bool GCodes::DoHome()
|
||||
// Returns true if completed, false if needs to be called again.
|
||||
// 'reply' is only written if there is an error.
|
||||
// 'error' is false on entry, gets changed to true iff there is an error.
|
||||
bool GCodes::DoHome(char* reply, bool& error)
|
||||
//pre(reply.upb == STRING_LENGTH)
|
||||
{
|
||||
if(homeX && homeY && homeZ)
|
||||
{
|
||||
|
@ -565,6 +588,7 @@ bool GCodes::DoHome()
|
|||
homeX = false;
|
||||
homeY = false;
|
||||
homeZ = false;
|
||||
axisIsHomed[0] = axisIsHomed[1] = axisIsHomed[2] = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -576,6 +600,7 @@ bool GCodes::DoHome()
|
|||
{
|
||||
homeAxisMoveCount = 0;
|
||||
homeX = false;
|
||||
axisIsHomed[0] = true;
|
||||
return NoHome();
|
||||
}
|
||||
return false;
|
||||
|
@ -588,6 +613,7 @@ bool GCodes::DoHome()
|
|||
{
|
||||
homeAxisMoveCount = 0;
|
||||
homeY = false;
|
||||
axisIsHomed[1] = true;
|
||||
return NoHome();
|
||||
}
|
||||
return false;
|
||||
|
@ -596,10 +622,19 @@ bool GCodes::DoHome()
|
|||
|
||||
if(homeZ)
|
||||
{
|
||||
if (!(axisIsHomed[0] && axisIsHomed[1]))
|
||||
{
|
||||
// We can only home Z if X and Y have already been homed. Possibly this should only be if we are using an IR probe.
|
||||
strncpy(reply, "Must home X and Y before homing Z", STRING_LENGTH);
|
||||
error = true;
|
||||
homeZ = false;
|
||||
return true;
|
||||
}
|
||||
if(DoFileCannedCycles(HOME_Z_G))
|
||||
{
|
||||
homeAxisMoveCount = 0;
|
||||
homeZ = false;
|
||||
axisIsHomed[2] = true;
|
||||
return NoHome();
|
||||
}
|
||||
return false;
|
||||
|
@ -1260,7 +1295,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
|
|||
homeZ = true;
|
||||
}
|
||||
}
|
||||
result = DoHome();
|
||||
result = DoHome(reply, error);
|
||||
break;
|
||||
|
||||
case 30: // Z probe/manually set at a position and set that as point P
|
||||
|
@ -1272,7 +1307,17 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
|
|||
break;
|
||||
|
||||
case 32: // Probe Z at multiple positions and generate the bed transform
|
||||
if (!(axisIsHomed[0] && axisIsHomed[1]))
|
||||
{
|
||||
// We can only do a Z probe if X and Y have already been homed
|
||||
strncpy(reply, "Must home X and Y before bed probing", STRING_LENGTH);
|
||||
error = true;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = DoMultipleZProbe();
|
||||
}
|
||||
break;
|
||||
|
||||
case 90: // Absolute coordinates
|
||||
|
|
6
GCodes.h
6
GCodes.h
|
@ -80,6 +80,7 @@ class GCodes
|
|||
bool PrintingAFile() const;
|
||||
void Diagnostics();
|
||||
bool HaveIncomingData() const;
|
||||
bool GetAxisIsHomed(uint8_t axis) const { return axisIsHomed[axis]; }
|
||||
|
||||
private:
|
||||
|
||||
|
@ -91,7 +92,7 @@ class GCodes
|
|||
bool ActOnGcode(GCodeBuffer* gb);
|
||||
bool SetUpMove(GCodeBuffer* gb);
|
||||
bool DoDwell(GCodeBuffer *gb);
|
||||
bool DoHome();
|
||||
bool DoHome(char *reply, bool& error);
|
||||
bool DoSingleZProbeAtPoint();
|
||||
bool DoSingleZProbe();
|
||||
bool SetSingleZProbeAtAPosition(GCodeBuffer *gb);
|
||||
|
@ -99,7 +100,7 @@ class GCodes
|
|||
bool SetPrintZProbe(GCodeBuffer *gb, char *reply);
|
||||
bool SetOffsets(GCodeBuffer *gb);
|
||||
bool SetPositions(GCodeBuffer *gb);
|
||||
void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92);
|
||||
void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92, bool applyLimits);
|
||||
bool NoHome() const;
|
||||
bool Push();
|
||||
bool Pop();
|
||||
|
@ -159,6 +160,7 @@ class GCodes
|
|||
bool cannedCycleMoveQueued;
|
||||
bool zProbesSet;
|
||||
float longWait;
|
||||
bool axisIsHomed[3]; // these record which of the axes have been homed
|
||||
};
|
||||
|
||||
//*****************************************************************************************************
|
||||
|
|
Reference in a new issue