/// <summary> /// Execute RepRap G92 command. /// </summary> /// <param name="repRapLine"></param> public void ProcessG92Command(string[] repRapLine) { //Read through the GCode line and parse coordinate values. for (int phrase = 1; phrase < repRapLine.Length; phrase++) { switch (repRapLine[phrase][0]) { case 'X': _parametersModel.XCoord.NewCoord(GCodeStringParsing.ParseDouble(repRapLine[phrase])); break; case 'Y': _parametersModel.YCoord.NewCoord(GCodeStringParsing.ParseDouble(repRapLine[phrase])); break; case 'Z': _parametersModel.ZCoord.NewCoord(GCodeStringParsing.ParseDouble(repRapLine[phrase])); break; case 'E': _parametersModel.ERepRapCoord.NewCoord(GCodeStringParsing.ParseDouble(repRapLine[phrase])); break; } } }
/// <summary> /// Retrieve a list of T commands from RepRap g-code. /// </summary> /// <returns></returns> public void UpdateRepRapIDList() { //Return parameter. _printViewModel.AvailibleRepRapIDList = new ObservableCollection <string>(); //Delimit the g-code string by lines then spaces. string[][] repRapGCodeArr = GCodeStringParsing.GCodeTo2DArr(_gCodeFileManagerModel.UploadedGCodeModel.GCodeStr); //Move through each g-code line. if (repRapGCodeArr != null) { for (int line = 0; (line < repRapGCodeArr.Length) && (repRapGCodeArr != null); line++) { if (repRapGCodeArr[line] != null && !String.IsNullOrWhiteSpace(repRapGCodeArr[line][0])) { //Remove comments from the g-code line. string[] uncommentedRepRapLine = GCodeStringParsing.RemoveGCodeComments(repRapGCodeArr[line]); if ((uncommentedRepRapLine != null) && (uncommentedRepRapLine.Length != 0) && (!String.IsNullOrWhiteSpace(uncommentedRepRapLine[0])) && (uncommentedRepRapLine[0][0] == 'T')) { _printViewModel.AvailibleRepRapIDList.Add(uncommentedRepRapLine[0]); } } } } _printViewModel.RepRapIDCount = _printViewModel.AvailibleRepRapIDList.Count; _printViewModel.UpdateAvailibleRepRapIDList(); }
/// <summary> /// Reads the coordinate values in a movement or print command. /// </summary> /// <param name="convertedGCodeLine"></param> /// <param name="gCodeIndex"></param> /// <param name="materialModel"></param> /// <returns></returns> private MovementModel ReadCoord(string convertedGCodeLine, int gCodeIndex, MaterialModel materialModel) { //G Commands from Converted GCode are in relative positions. string[] gCodePhrases = GCodeStringParsing.GCodeTo2DArr(convertedGCodeLine)[0]; double xDistance = 0; double yDistance = 0; double zDistance = 0; double eDistance = 0; //Read the coordinates from the GCode. for (int phrase = 1; phrase < gCodePhrases.Length; phrase++) { switch (gCodePhrases[phrase][0]) { case 'X': int xSteps = (int)GCodeStringParsing.ParseDouble(gCodePhrases[phrase]); AxisModel xAxisModel = _printerModel.AxisModelList[0]; xDistance = G00Calculator.StepsToDistance(xSteps, xAxisModel.MmPerStep, xAxisModel.IsDirectionInverted); break; case 'Y': int ySteps = (int)GCodeStringParsing.ParseDouble(gCodePhrases[phrase]); AxisModel yAxisModel = _printerModel.AxisModelList[1]; yDistance = G00Calculator.StepsToDistance(ySteps, yAxisModel.MmPerStep, yAxisModel.IsDirectionInverted); break; case 'Z': int zSteps = (int)GCodeStringParsing.ParseDouble(gCodePhrases[phrase]); AxisModel zAxisModel = _printerModel.FindAxis(materialModel.PrintheadModel.AttachedZAxisModel.Name); zDistance = G00Calculator.StepsToDistance(zSteps, zAxisModel.MmPerStep, zAxisModel.IsDirectionInverted); break; case 'E': int eSteps = (int)GCodeStringParsing.ParseDouble(gCodePhrases[phrase]); MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)materialModel.PrintheadModel.PrintheadTypeModel; eDistance = G00Calculator.StepsToDistance(eSteps, motorizedPrintheadTypeModel.MmPerStep, motorizedPrintheadTypeModel.IsDirectionInverted); break; default: //Do nothing. break; } } MovementModel movementModel = new MovementModel(xDistance, yDistance, zDistance, eDistance, gCodeIndex, materialModel, _printerModel); return(movementModel); }
/// <summary> /// Interpret a command series and return an array of commands /// </summary> /// <param name="commandSeries"></param> /// <returns></returns> public List <string> InterpretCommandSet(string commandSet) { //Remove comments before processing. commandSet = GCodeStringParsing.RemoveGCodeComments(commandSet); //The first character of the command set is reserved for the command set serial character. if ((commandSet.Length >= 7) && (commandSet.Substring(1, 6) == "Center")) { return(InterpretCenterAxes(commandSet)); } else if ((commandSet.Length >= 7) && (commandSet.Substring(1, 6) == "Origin")) { return(InterpretSetOrigin(commandSet)); } else if ((commandSet.Length >= 13) && (commandSet.Substring(1, 12) == "SetMinMaxPos")) { return(InterpretSetMinMaxPosition(commandSet)); } else if ((commandSet.Length >= 9) && (commandSet.Substring(1, 8) == "RetractZ")) { return(InterpretRetractZ(commandSet)); } else if ((commandSet.Length >= 6) && (commandSet.Substring(1, 5) == "Pause")) { return(InterpretPause(commandSet)); } else if ((commandSet.Length >= 11) && (commandSet.Substring(1, 10) == "PrintPause")) { return(InterpretPrintPause(commandSet)); } else if ((commandSet.Length >= 15) && (commandSet.Substring(1, 14) == "SwitchMaterial")) { return(InterpretSwitchMaterial(commandSet)); } return(null); }
/// <summary> /// Interpret a center axes command set and return an array of commands. /// </summary> /// <param name="commandSet"></param> /// <returns></returns> private List <string> InterpretCenterAxes(string commandSet) { //Command set to be returned. List <string> returnCommands = new List <string>(); AxisModel xAxisModel = _printerModel.AxisModelList[0]; AxisModel yAxisModel = _printerModel.AxisModelList[1]; RealTimeStatusAxisModel xRealTimeStatusAxisModel = _realTimeStatusDataModel.XRealTimeStatusAxisModel; RealTimeStatusAxisModel yRealTimeStatusAxisModel = _realTimeStatusDataModel.YRealTimeStatusAxisModel; double xNewPosition = xRealTimeStatusAxisModel.Position; double yNewPosition = yRealTimeStatusAxisModel.Position; //mmPerStep for each actuator. double xmmPerStep = 0; double ymmPerStep = 0; //InvertDirection for each actuator. bool xInvertDirection = (xAxisModel.IsDirectionInverted == false) ? false : true; bool yInvertDirection = (yAxisModel.IsDirectionInverted == false) ? false : true; //Distances from the center. double xDistanceFromCenter = 0; double yDistanceFromCenter = 0; string[] gCodePhrases = GCodeStringParsing.GCodeTo2DArr(commandSet)[0]; foreach (string phrase in gCodePhrases) { switch (phrase[0]) { case 'X': xDistanceFromCenter = GCodeStringParsing.ParseDouble(phrase); break; case 'Y': yDistanceFromCenter = GCodeStringParsing.ParseDouble(phrase); break; default: //Do nothing. break; } } //Centering the actuator involves: // 1. Finding the median position directly in the center of the max and min position. // 2. Finding the distance between median position and the current position. // 3. Executing that difference worth of movement. if (commandSet.Contains("X")) { xNewPosition = (xAxisModel.MaxPosition - xAxisModel.MinPosition) / 2 + xAxisModel.MinPosition + xDistanceFromCenter; xmmPerStep = xAxisModel.MmPerStep; } if (commandSet.Contains("Y")) { yNewPosition = (yAxisModel.MaxPosition - yAxisModel.MinPosition) / 2 + yAxisModel.MinPosition + yDistanceFromCenter; ymmPerStep = yAxisModel.MmPerStep; } double unused = 0; returnCommands.Add(GCodeLinesConverter.GCodeLinesListToString( WriteG00.WriteAxesMovement( xmmPerStep, ymmPerStep, 0, xNewPosition - xRealTimeStatusAxisModel.Position, yNewPosition - yRealTimeStatusAxisModel.Position, 0, xInvertDirection, yInvertDirection, false, ref unused, ref unused, ref unused))); return(returnCommands); }