Skip to content

Commit 9710f9c

Browse files
author
Sven Erb
committed
Updated GCodeState.
1 parent 8ce1d0d commit 9710f9c

2 files changed

Lines changed: 78 additions & 47 deletions

File tree

GCodeReaderWriter/GCodeCommand.cs

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,6 @@ public enum GCodeType
7979

8080
internal class GCodeState
8181
{
82-
// This class contains a gcode command
83-
// When a new object of this class is created, the gcode command is parsed from the input string
84-
// If an object of gcodestate already exists, the new instance compares the gcode command with the existing one
85-
// If the command is similar, the new command is filled with the missing parameters, which already exist in the old command
86-
// The command is then added to the existing vectorblock
87-
// If the existing command is dissimilar this can be noted through a new vectorblock and/or marikingParam set
88-
89-
/* Potentially not needed
90-
public readonly VectorBlock.VectorDataOneofCase ovfVectordataType;
91-
public GCodeType gCodeType;
92-
93-
// Movement parameters
94-
public readonly Vector3 position;
95-
public readonly float feedRate;
96-
public readonly float acceleration;
97-
98-
// Linear movement parameters
99-
public readonly bool isOperation;
100-
101-
//Circular movement parameters
102-
public readonly Vector3 centerRel;
103-
public readonly float angle;
104-
105-
// Pause patameters
106-
public readonly float pauseDuration;
107-
public readonly bool isManualPause;
108-
*/
109-
110-
//Hier Klassen der GCodes behalten und dem GCodeCommand eine entsprechenede Klasse zuweisen. Hier
11182
private readonly Dictionary<int, Type> _gCodeTranslations = new Dictionary<int, Type>
11283
{
11384
{0, typeof(LinearInterpolationCmd)},
@@ -117,6 +88,37 @@ internal class GCodeState
11788
{4, typeof(PauseCommand)},
11889
};
11990

91+
internal class GCodeMarkingParams
92+
{
93+
// Marking parameters
94+
internal float workSpeed = 0;
95+
internal float travelSpeed = 0;
96+
internal float acceleration = 0;
97+
98+
// Pause parameters
99+
internal float pauseDuration = 0;
100+
101+
// Other parameters
102+
internal ToolParams toolParams;
103+
104+
Dictionary<string, float> miscParameters = new Dictionary<string, float>();
105+
106+
internal GCodeMarkingParams()
107+
{
108+
109+
}
110+
}
111+
112+
internal class GCodePositions
113+
{
114+
internal Vector3 position;
115+
internal Vector2 centerRel;
116+
internal GCodePositions()
117+
{
118+
119+
}
120+
}
121+
120122
private Dictionary<int, GCodeType> _mCodeTranslations = new Dictionary<int, GCodeType>();
121123

122124
private Dictionary<int, GCodeType> _tCodeTranslations = new Dictionary<int, GCodeType>();
@@ -173,7 +175,7 @@ public bool[] Update(string serializedCmdLine)
173175
GCodeCommand previousGCodeCommand = this.gCodeCommand;
174176
GCodeCommand currentGCodeCommand = ParseToGCodeCommand(serializedCmdLine);
175177

176-
bool workingPlaneChanged = false;
178+
bool workPlaneChanged = false;
177179
bool markingParamsChanged = false;
178180
bool vectorBlockChanged = false;
179181

@@ -182,28 +184,23 @@ public bool[] Update(string serializedCmdLine)
182184
vectorBlockChanged = true;
183185
}
184186
markingParamsChanged = UpdateParameters();
185-
workingPlaneChanged = updatePosition();
187+
workPlaneChanged = updatePosition();
186188

187189
bool UpdateParameters()
188190
{
189191
bool parametersChanged = false;
190-
bool positionChanged = false;
191-
foreach (var property in previousGCodeCommand.GetType().GetProperties().Where(p => p.Name != "xPosition" && p.Name != "yPosition" && p.Name != "zPosition"))
192+
foreach (var property in previousGCodeCommand.GetType().GetProperties())
192193
{
193194
var previousValue = property.GetValue(previousGCodeCommand);
194195
var currentValue = property.GetValue(currentGCodeCommand);
195196

196197
if (!Equals(previousValue, currentValue))
197198
{
198199
property.SetValue(currentGCodeCommand, previousValue);
199-
parametersChanged = true;
200+
parametersChanged = (property.Name != "xPosition" && property.Name != "yPosition" && property.Name != "zPosition");
200201
}
201202
}
202-
if (positionChanged)
203-
{
204-
MovementCommand movementCmd = currentGCodeCommand as MovementCommand;
205-
position = new Vector3(movementCmd.xPosition ?? 0, movementCmd.yPosition ?? 0, movementCmd.zPosition ?? 0);
206-
}
203+
207204
return parametersChanged;
208205
}
209206

@@ -222,15 +219,15 @@ bool updatePosition()
222219
}
223220
catch (Exception e)
224221
{
225-
throw new ArgumentException($"Unable to update position in line '{serializedCmdLine}'. Creating a Vector3 object from command was not possible.");
222+
throw new ArgumentException($"Unable to update position in line '{serializedCmdLine}'. Creating a Vector object from command was not possible.");
226223
}
227224
}
228225
return zChange;
229226
}
230227

231228
this.gCodeCommand = currentGCodeCommand;
232229

233-
return new bool [] { workingPlaneChanged, markingParamsChanged, vectorBlockChanged};
230+
return new bool [] { workPlaneChanged, markingParamsChanged, vectorBlockChanged};
234231
}
235232
}
236233

@@ -340,7 +337,7 @@ public override string ToString()
340337

341338
internal class LinearInterpolationCmd : MovementCommand
342339
{
343-
private bool isOperation;
340+
internal bool isOperation;
344341

345342
public LinearInterpolationCmd(PrepCode prepCode, int codeNumber, Dictionary<char, float> commandParams = null) : base(prepCode, codeNumber)
346343
{
@@ -380,11 +377,8 @@ public override string ToString()
380377

381378
internal class CircularInterpolationCmd : MovementCommand
382379
{
383-
internal float? xStartPos;
384-
internal float? yStartPos;
385380
internal float? xCenterRel;
386381
internal float? yCenterRel;
387-
internal float? angle;
388382

389383
internal bool isClockwise;
390384

GCodeReaderWriter/GCodeReader.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,53 @@ private void ParseGCodeFile()
173173
foreach (string commandLine in commandLines.Skip(1))
174174
{
175175
bool[] objectUpdates = gCodeState.Update(commandLine);
176-
bool workingPlaneChanged = objectUpdates[0], markingParamsChanged = objectUpdates[1], vectorBlockChanged = objectUpdates[2];
176+
bool workPlaneChanged = objectUpdates[0], markingParamsChanged = objectUpdates[1], vectorBlockChanged = objectUpdates[2];
177177

178-
if (workingPlaneChanged)
178+
if (markingParamsChanged)
179+
{
180+
GCodeCommand gCodeCommand = gCodeState.gCodeCommand;
181+
//check if markingParams are already in the map
182+
foreach (var markingParams in CompleteJob.MarkingParamsMap.Values)
183+
{
184+
object[] relevantParams = new object[] { markingParams.LaserSpeedInMmPerS, markingParams.JumpSpeedInMmS, };
185+
if (gCodeCommand is LinearInterpolationCmd linearCmd &&linearCmd.isOperation)
186+
{
187+
if(markingParams.LaserSpeedInMmPerS == linearCmd.feedRate)
188+
{
189+
markingParamsChanged = false;
190+
}
191+
}
192+
foreach (var markingParam in markingParams.GetType().GetProperties().Where<>)
193+
{
194+
switch (markingParam.Name)
195+
{
196+
case "LaserSpeedInMmPerS":
197+
if (markingParam.GetValue(markingParams) != gCodeState.gCodeCommand.)
198+
{
199+
markingParamsChanged = true;
200+
}
201+
break;
202+
203+
}
204+
}
205+
206+
}
207+
if (workPlaneChanged)
179208
{
180209
_workPlane = new WorkPlane
181210
{
182211
WorkPlaneNumber = _workPlane.WorkPlaneNumber + 1,
183212
ZPosInMm = gCodeState.position.Z
184213
};
214+
NewVectorBlock();
215+
vectorBlockChanged = false;
185216
}
217+
if (vectorBlockChanged)
218+
{
219+
NewVectorBlock();
220+
}
221+
// Add coordinates to the current vector block, clculate angles and centers from positions of arcs
222+
186223
}
187224
_cacheState = CacheState.CompleteJobCached;
188225

0 commit comments

Comments
 (0)