fixed baby step stream to have the right offsets

refactoring for clarity
fixing warnings
issue: MatterHackers/MatterControl#4560
Cannot move up in z calibration wizard
This commit is contained in:
Lars Brubaker 2019-05-22 10:28:27 -07:00
parent bc76fec428
commit 6fbc87acf0
4 changed files with 36 additions and 41 deletions

View file

@ -307,7 +307,7 @@ namespace MatterHackers.MatterControl.Library.Export
if (levelingEnabled
&& !LevelingValidation.NeedsToBeRun(printer))
{
accumulatedStream = new PrintLevelingStream(printer, accumulatedStream, false);
accumulatedStream = new PrintLevelingStream(printer, accumulatedStream);
}
if (printer.Settings.GetValue<bool>(SettingsKey.emulate_endstops))

View file

@ -38,9 +38,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public class BabyStepsStream : GCodeStreamProxy
{
private int extruderIndex = 0;
private Vector3[] extruderOffsets = new Vector3[4];
private readonly Vector3[] extruderOffsets = new Vector3[4];
public PrinterMove lastDestination = PrinterMove.Unknown;
private PrinterMove lastInputDestination = PrinterMove.Unknown;
public Vector3 BabbyStepOffset { get; private set; } = Vector3.Zero;
@ -56,7 +56,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
ReadExtruderOffsets();
}
private void ReadExtruderOffsets()
{
for (int i = 0; i < 4; i++)
@ -69,36 +68,36 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
get
{
return $"Last Destination = {lastDestination}";
return $"Last Destination = {lastInputDestination}";
}
}
void Printer_SettingChanged(object s, StringEventArgs e)
private void Printer_SettingChanged(object s, StringEventArgs e)
{
if (e?.Data == SettingsKey.baby_step_z_offset)
{
var currentOffset = BabbyStepOffset.Z;
BabbyStepOffset = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset));
lastDestination.position.Z = lastDestination.position.Z - currentOffset + BabbyStepOffset.Z;
}
// if the offsets change update them (unless we are actively printing)
else if (e?.Data == SettingsKey.extruder_offset
&& !printer.Connection.Printing
&& !printer.Connection.Paused)
{
// if the offsets change update them (unless we are actively printing)
ReadExtruderOffsets();
}
}
public override void SetPrinterPosition(PrinterMove position)
{
this.lastDestination.CopyKnowSettings(position);
if (extruderIndex < 4)
{
lastDestination.position -= BabbyStepOffset;
lastDestination.position += extruderOffsets[extruderIndex];
}
internalStream.SetPrinterPosition(lastDestination);
lastInputDestination.CopyKnowSettings(position);
// calculate our offset to pass on to internal streams
var offestDestination = lastInputDestination;
offestDestination.position -= BabbyStepOffset;
offestDestination.position += extruderOffsets[Math.Min(extruderIndex, 4)];
internalStream.SetPrinterPosition(offestDestination);
}
public override void Dispose()
@ -131,20 +130,18 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
if (lineToSend != null
&& LineIsMovement(lineToSend))
{
PrinterMove currentMove = GetPosition(lineToSend, lastDestination);
PrinterMove currentMove = GetPosition(lineToSend, lastInputDestination);
PrinterMove moveToSend = currentMove;
if (extruderIndex < 4)
{
moveToSend.position += BabbyStepOffset;
moveToSend.position -= extruderOffsets[extruderIndex];
}
moveToSend.position += BabbyStepOffset;
moveToSend.position -= extruderOffsets[Math.Min(extruderIndex, 4)];
if (moveToSend.HaveAnyPosition)
{
lineToSend = CreateMovementLine(moveToSend, lastDestination);
lineToSend = CreateMovementLine(moveToSend, lastInputDestination);
}
lastDestination = currentMove;
lastInputDestination = currentMove;
return lineToSend;
}

View file

@ -35,34 +35,31 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
public class PrintLevelingStream : GCodeStreamProxy
{
private PrinterMove _lastDestination = PrinterMove.Unknown;
private bool activePrinting;
private LevelingFunctions currentLevelingFunctions = null;
private Vector3 currentProbeZOffset;
private bool wroteLevelingStatus = false;
private bool gcodeAlreadyLeveled = false;
public PrintLevelingStream(PrinterConfig printer, GCodeStream internalStream, bool activePrinting)
public PrintLevelingStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
// always reset this when we construct
AllowLeveling = true;
this.activePrinting = activePrinting;
}
public override string DebugInfo
{
get
{
return $"Last Destination = {LastDestination}";
return $"Last Destination = {lastUnleveledDestination}";
}
}
public bool AllowLeveling { get; set; }
public PrinterMove LastDestination => _lastDestination;
private PrinterMove lastUnleveledDestination = PrinterMove.Unknown;
bool LevelingActive
private bool LevelingActive
{
get
{
@ -74,7 +71,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public override string ReadLine()
{
if(!wroteLevelingStatus && LevelingActive)
if (!wroteLevelingStatus && LevelingActive)
{
wroteLevelingStatus = true;
return "; Software Leveling Applied";
@ -99,12 +96,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
if (LineIsMovement(lineToSend))
{
PrinterMove currentDestination = GetPosition(lineToSend, LastDestination);
var leveledLine = GetLeveledPosition(lineToSend, currentDestination);
PrinterMove currentUnleveledDestination = GetPosition(lineToSend, lastUnleveledDestination);
var leveledLine = GetLeveledPosition(lineToSend, currentUnleveledDestination);
// TODO: clamp to 0 - baby stepping - extruder z-offset, so we don't go below the bed (for the active extruder)
_lastDestination = currentDestination;
lastUnleveledDestination = currentUnleveledDestination;
return leveledLine;
}
@ -120,6 +117,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public override void SetPrinterPosition(PrinterMove position)
{
this.lastUnleveledDestination.CopyKnowSettings(position);
if (LevelingActive
&& position.PositionFullyKnown)
{
@ -129,17 +128,16 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
PrinterMove leveledDestination = GetPosition(leveledPosition, PrinterMove.Unknown);
PrinterMove deltaToLeveledPosition = leveledDestination - position;
PrinterMove withoutLevelingOffset = position - deltaToLeveledPosition;
PrinterMove withLevelingOffset = position - deltaToLeveledPosition;
_lastDestination = withoutLevelingOffset;
_lastDestination.extrusion = position.extrusion;
_lastDestination.feedRate = position.feedRate;
// clean up settings that we don't want to be subtracted
withLevelingOffset.extrusion = position.extrusion;
withLevelingOffset.feedRate = position.feedRate;
internalStream.SetPrinterPosition(_lastDestination);
internalStream.SetPrinterPosition(withLevelingOffset);
}
else
{
this._lastDestination.CopyKnowSettings(position);
internalStream.SetPrinterPosition(position);
}
}

View file

@ -2318,7 +2318,7 @@ You will then need to logout and log back in to the computer for the changes to
if (!LevelingValidation.NeedsToBeRun(Printer))
{
accumulatedStream = printLevelingStream = new PrintLevelingStream(Printer, accumulatedStream, true);
accumulatedStream = printLevelingStream = new PrintLevelingStream(Printer, accumulatedStream);
}
accumulatedStream = waitForTempStream = new WaitForTempStream(Printer, accumulatedStream);