Skip to content

Commit 8d38213

Browse files
committed
Fixed a bug in analyzer requests. Ensured failures are properly marked in printer operations.
1 parent 76fe727 commit 8d38213

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

Ares.Core/Analyzing/RemoteAnalyzer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public override async Task<Analysis> Analyze(AresStruct inputs, RequestMetadata
3535
var analysisRequest = new AnalysisRequest
3636
{
3737
Inputs = inputs,
38-
Settings = Settings
38+
Settings = Settings,
39+
Metadata = metadata
3940
};
4041
var analysis = await client.AnalyzeAsync(analysisRequest, cancellationToken: cancellationToken);
4142

@@ -57,7 +58,8 @@ public override Task<Analysis> Analyze(AresStruct inputs, AresStruct settings, R
5758
var analysisRequest = new AnalysisRequest
5859
{
5960
Inputs = inputs,
60-
Settings = mergedSettings
61+
Settings = mergedSettings,
62+
Metadata = metadata
6163
};
6264
return client.AnalyzeAsync(analysisRequest, cancellationToken: cancellationToken).ResponseAsync;
6365
}

PrusaMK4S/Handlers/GCodeHandler.cs

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class GCodeHandler : IGcodeHandler
77
{
88
private const int _printBedHeight = 210;
99
private const int _printBedWidth = 190;
10+
private const int _distanceBetweenPurgeLines = 5;
1011
private static string[] _movementCommands = [ "G0", "G1", "G2", "G3" ];
1112

1213
public GCodeHandler(byte[] original_data)
@@ -31,6 +32,7 @@ public async Task<byte[]> ApplyPlanningParameters(int bedTemperature,
3132
byte[] gcode)
3233
{
3334
var data = await ConvertGCodeToStrings(gcode);
35+
//data = UpdateBedLeveling(data, 0);
3436
DetermineModificationIndex(data);
3537

3638
// The G-Code associated with the user defined main object
@@ -52,7 +54,7 @@ public async Task<byte[]> ApplyPlanningParameters(int bedTemperature,
5254
if(speedMod > 0)
5355
main_print_gcode = UpdateMovementSpeed(speedMod, main_print_gcode);
5456

55-
if(retractionLength > -1)
57+
if(retractionLength > 0)
5658
main_print_gcode = UpdateRetractionLength(retractionLength, main_print_gcode);
5759

5860
if(accelerationMod > 0)
@@ -543,18 +545,21 @@ private async Task<byte[]> GenerateFirstPrintData()
543545

544546
private List<string> ShiftInitialPurgeLine(List<string> gcode)
545547
{
546-
var updatedGcode = new List<string>();
548+
var updatedGcode = new List<string>();
547549
var shouldEdit = false;
548550

549551
foreach(var line in gcode)
550552
{
551-
if(line.Contains("; probe near purge place"))
552-
updatedGcode.Add(ApplyPurgeXOffset(line.Split(), 200));
553+
//if(line.Contains("; probe near purge place"))
554+
// updatedGcode.Add(ApplyPurgeXOffset(line.Split(), 200));
553555

554556
if(line.StartsWith("; prepare for purge"))
557+
{
555558
shouldEdit = true;
559+
updatedGcode.Add(line);
560+
}
556561

557-
if(line.StartsWith("G") && shouldEdit)
562+
else if(line.StartsWith("G") && shouldEdit)
558563
updatedGcode.Add(ApplyPurgeXOffset(line.Split(), 200));
559564

560565
else
@@ -591,19 +596,22 @@ private string ApplyPurgeXOffset(string[] splitLine, int shift)
591596

592597
private List<string> ShiftIterationPurgeLine(List<string> gcode, int iteration)
593598
{
594-
var yShift = iteration * 5;
599+
var yShift = iteration * _distanceBetweenPurgeLines;
595600
var updatedGcode = new List<string>();
596601
var shouldEdit = false;
597602

598603
foreach(var line in gcode)
599604
{
600-
if(line.Contains("; probe near purge place"))
601-
updatedGcode.Add(ApplyPurgeYOffset(line.Split(), yShift));
605+
//if(line.Contains("; probe near purge place"))
606+
//updatedGcode.Add(ApplyPurgeYOffset(line.Split(), yShift));
602607

603608
if(line.StartsWith("; prepare for purge"))
609+
{
604610
shouldEdit = true;
611+
updatedGcode.Add(line);
612+
}
605613

606-
if(line.StartsWith("G") && shouldEdit)
614+
else if(line.StartsWith("G") && shouldEdit)
607615
updatedGcode.Add(ApplyPurgeYOffset(line.Split(), yShift));
608616

609617
else
@@ -616,6 +624,17 @@ private List<string> ShiftIterationPurgeLine(List<string> gcode, int iteration)
616624
private string ApplyPurgeYOffset(string[] splitLine, int shift)
617625
{
618626
var y = splitLine.FirstOrDefault(e => e.StartsWith("Y"));
627+
//var height = splitLine.FirstOrDefault(e => e.StartsWith("H"));
628+
//var width = splitLine.FirstOrDefault(e => e.StartsWith("W"));
629+
630+
//if(splitLine[0] == "G29")
631+
//{
632+
//var height_index = splitLine.IndexOf(height);
633+
//var width_index = splitLine.IndexOf(width);
634+
635+
//splitLine[height_index] = "H25";
636+
//splitLine[width_index] = "W25";
637+
//}
619638

620639
if(y is null)
621640
{
@@ -626,6 +645,7 @@ private string ApplyPurgeYOffset(string[] splitLine, int shift)
626645
else
627646
{
628647
var index = splitLine.IndexOf(y);
648+
629649
var parsed = float.TryParse(y.Substring(1), out var yFloat);
630650

631651
if(!parsed)
@@ -644,26 +664,20 @@ private List<string> UpdateBedLeveling(List<string> gcode, int printIteration)
644664

645665
foreach(var line in gcode)
646666
{
647-
if(line.StartsWith("M555"))
667+
if(line.StartsWith("G29 P1"))
648668
{
649-
//M555 X0 Y0 W0 H0
650-
var splitLine = line.Split();
651-
652-
if(splitLine.Length < 5)
669+
if(line.Contains("purge"))
653670
{
654671
updated_gcode.Add(line);
655-
continue;
656672
}
657673

658-
splitLine[1] = "X0";
659-
splitLine[2] = "Y0";
660-
splitLine[3] = $"W25";
661-
splitLine[4] = $"H25";
662-
663-
var newLevelAreaCmd = string.Join(" ", splitLine);
664-
665-
updated_gcode.Add(newLevelAreaCmd);
666-
continue;
674+
else
675+
{
676+
var x_center = LatestXShift + (0.5 * ItemWidth);
677+
var y_center = _printBedHeight + LatestYShift - (0.5 * ItemHeight);
678+
var newLevelCommand = $"G29 P1 X{x_center} Y{y_center} W{ItemWidth} H{ItemHeight} ; Level the ares determined by ARES";
679+
updated_gcode.Add(newLevelCommand);
680+
}
667681
}
668682

669683
else

PrusaMK4S/PrusaMK4s.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public async Task<MK4SRequestResponse> Print(byte[] gcode, int nozzleTemp, int b
9292
{
9393
if(_httpClient is null || Address is null)
9494
{
95+
response.Success = false;
9596
response.ErrorString = "Printer HTTP client was null, cannot send commands!";
9697
return response;
9798
}
@@ -116,6 +117,7 @@ public async Task<MK4SRequestResponse> Print(byte[] gcode, int nozzleTemp, int b
116117

117118
if(!parsed)
118119
{
120+
response.Success = false;
119121
response.ErrorString = "Printer couldn't determine iteration number for smart print, unable to complete print!";
120122
return response;
121123
}
@@ -131,6 +133,7 @@ public async Task<MK4SRequestResponse> Print(byte[] gcode, int nozzleTemp, int b
131133

132134
if(!httpResponse.IsSuccessStatusCode)
133135
{
136+
response.Success = false;
134137
response.ErrorString = httpResponse.ReasonPhrase;
135138
return response;
136139
}

0 commit comments

Comments
 (0)