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:
David Crocker 2014-01-29 15:30:58 +00:00
parent b578dd5bc4
commit 0c47fbc923
2 changed files with 63 additions and 16 deletions

View file

@ -84,6 +84,7 @@ void GCodes::Init()
active = true; active = true;
longWait = platform->Time(); longWait = platform->Time();
dwellTime = longWait; dwellTime = longWait;
axisIsHomed[0] = axisIsHomed[1] = axisIsHomed[2] = false;
} }
void GCodes::doFilePrint(GCodeBuffer* gb) void GCodes::doFilePrint(GCodeBuffer* gb)
@ -295,8 +296,9 @@ bool GCodes::Pop()
// Move expects all axis movements to be absolute, and all // Move expects all axis movements to be absolute, and all
// extruder drive moves to be relative. This function serves that. // 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; float absE;
@ -306,20 +308,38 @@ void GCodes::LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92)
{ {
if(gb->Seen(gCodeLetters[i])) if(gb->Seen(gCodeLetters[i]))
{ {
if(!axesRelative || doingG92) float moveArg = gb->GetFValue()*distanceScale;
moveBuffer[i] = gb->GetFValue()*distanceScale; if (axesRelative && !doingG92)
else {
moveBuffer[i] += gb->GetFValue()*distanceScale; 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 } else
{ {
if(gb->Seen(gCodeLetters[i])) if(gb->Seen(gCodeLetters[i]))
{ {
float moveArg = gb->GetFValue()*distanceScale;
if(drivesRelative || doingG92) if(drivesRelative || doingG92)
moveBuffer[i] = gb->GetFValue()*distanceScale; moveBuffer[i] = moveArg;
else else
{ {
absE = gb->GetFValue()*distanceScale; absE = moveArg;
moveBuffer[i] = absE - lastPos[i - AXES]; moveBuffer[i] = absE - lastPos[i - AXES];
lastPos[i - AXES] = absE; lastPos[i - AXES] = absE;
} }
@ -352,8 +372,6 @@ bool GCodes::SetUpMove(GCodeBuffer *gb)
if(!reprap.GetMove()->GetCurrentState(moveBuffer)) if(!reprap.GetMove()->GetCurrentState(moveBuffer))
return false; return false;
LoadMoveBufferFromGCode(gb, false);
checkEndStops = false; checkEndStops = false;
if(gb->Seen('S')) if(gb->Seen('S'))
{ {
@ -361,6 +379,8 @@ bool GCodes::SetUpMove(GCodeBuffer *gb)
checkEndStops = true; checkEndStops = true;
} }
LoadMoveBufferFromGCode(gb, false, !checkEndStops);
moveAvailable = true; moveAvailable = true;
return true; return true;
} }
@ -488,7 +508,7 @@ bool GCodes::SetPositions(GCodeBuffer *gb)
if(!AllMovesAreFinishedAndMoveBufferIsLoaded()) if(!AllMovesAreFinishedAndMoveBufferIsLoaded())
return false; return false;
LoadMoveBufferFromGCode(gb, true); LoadMoveBufferFromGCode(gb, true, false);
reprap.GetMove()->SetLiveCoordinates(moveBuffer); reprap.GetMove()->SetLiveCoordinates(moveBuffer);
reprap.GetMove()->SetPositions(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 // Home one or more of the axes. Which ones are decided by the
// booleans homeX, homeY and homeZ. // booleans homeX, homeY and homeZ.
// Returns true if completed, false if needs to be called again.
bool GCodes::DoHome() // '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) if(homeX && homeY && homeZ)
{ {
@ -565,6 +588,7 @@ bool GCodes::DoHome()
homeX = false; homeX = false;
homeY = false; homeY = false;
homeZ = false; homeZ = false;
axisIsHomed[0] = axisIsHomed[1] = axisIsHomed[2] = true;
return true; return true;
} }
return false; return false;
@ -576,6 +600,7 @@ bool GCodes::DoHome()
{ {
homeAxisMoveCount = 0; homeAxisMoveCount = 0;
homeX = false; homeX = false;
axisIsHomed[0] = true;
return NoHome(); return NoHome();
} }
return false; return false;
@ -588,6 +613,7 @@ bool GCodes::DoHome()
{ {
homeAxisMoveCount = 0; homeAxisMoveCount = 0;
homeY = false; homeY = false;
axisIsHomed[1] = true;
return NoHome(); return NoHome();
} }
return false; return false;
@ -596,10 +622,19 @@ bool GCodes::DoHome()
if(homeZ) 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)) if(DoFileCannedCycles(HOME_Z_G))
{ {
homeAxisMoveCount = 0; homeAxisMoveCount = 0;
homeZ = false; homeZ = false;
axisIsHomed[2] = true;
return NoHome(); return NoHome();
} }
return false; return false;
@ -1260,7 +1295,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
homeZ = true; homeZ = true;
} }
} }
result = DoHome(); result = DoHome(reply, error);
break; break;
case 30: // Z probe/manually set at a position and set that as point P 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; break;
case 32: // Probe Z at multiple positions and generate the bed transform case 32: // Probe Z at multiple positions and generate the bed transform
result = DoMultipleZProbe(); 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; break;
case 90: // Absolute coordinates case 90: // Absolute coordinates

View file

@ -80,6 +80,7 @@ class GCodes
bool PrintingAFile() const; bool PrintingAFile() const;
void Diagnostics(); void Diagnostics();
bool HaveIncomingData() const; bool HaveIncomingData() const;
bool GetAxisIsHomed(uint8_t axis) const { return axisIsHomed[axis]; }
private: private:
@ -91,7 +92,7 @@ class GCodes
bool ActOnGcode(GCodeBuffer* gb); bool ActOnGcode(GCodeBuffer* gb);
bool SetUpMove(GCodeBuffer* gb); bool SetUpMove(GCodeBuffer* gb);
bool DoDwell(GCodeBuffer *gb); bool DoDwell(GCodeBuffer *gb);
bool DoHome(); bool DoHome(char *reply, bool& error);
bool DoSingleZProbeAtPoint(); bool DoSingleZProbeAtPoint();
bool DoSingleZProbe(); bool DoSingleZProbe();
bool SetSingleZProbeAtAPosition(GCodeBuffer *gb); bool SetSingleZProbeAtAPosition(GCodeBuffer *gb);
@ -99,7 +100,7 @@ class GCodes
bool SetPrintZProbe(GCodeBuffer *gb, char *reply); bool SetPrintZProbe(GCodeBuffer *gb, char *reply);
bool SetOffsets(GCodeBuffer *gb); bool SetOffsets(GCodeBuffer *gb);
bool SetPositions(GCodeBuffer *gb); bool SetPositions(GCodeBuffer *gb);
void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92); void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92, bool applyLimits);
bool NoHome() const; bool NoHome() const;
bool Push(); bool Push();
bool Pop(); bool Pop();
@ -159,6 +160,7 @@ class GCodes
bool cannedCycleMoveQueued; bool cannedCycleMoveQueued;
bool zProbesSet; bool zProbesSet;
float longWait; float longWait;
bool axisIsHomed[3]; // these record which of the axes have been homed
}; };
//***************************************************************************************************** //*****************************************************************************************************