public void CodeCompile(List <string> CodeOfAll) { try { coo_machine_current = MoveControl_script.MachineCoo; if (motionCode.Count == 0) { coo_machine_togo = new Vector3(0, 0, 0); } else { coo_machine_togo = new Vector3(motionCode[motionCode.Count - 1].x_value, motionCode[motionCode.Count - 1].y_value, motionCode[motionCode.Count - 1].z_value); } for (int i = 0; i < CodeOfAll.Count; i++) { temp_code_info = new CodeClass(); temp_code_info.index = i; if (CodeOfAll[i] == "") { temp_code_info.move_flag = false; motionCode.Add(temp_code_info); continue; } if (CodeOfAll[i].StartsWith("%") || CodeOfAll[i].StartsWith("O")) { temp_code_info.move_flag = false; motionCode.Add(temp_code_info); continue; } bool SpaceFlag = false; List <string> CalStr = new List <string>(); Regex rule = new Regex(@"([A-Z]+[^A-Z^\s]+)+"); Match match = rule.Match(CodeOfAll[i]); if (match.Groups.Count > 1) { for (int j = 0; j < match.Groups[1].Captures.Count; j++) { CalStr.Add(match.Groups[1].Captures[j].Value); } } for (int j = 0; j < CalStr.Count; j++) { SpaceFlag = false; switch (CalStr[j]) { case "G17": system_initial_para.plane_choose = 0; SpaceFlag = true; break; case "G18": system_initial_para.plane_choose = 1; SpaceFlag = true; break; case "G19": system_initial_para.plane_choose = 2; SpaceFlag = true; break; case "G20": system_initial_para.unitmode = false; SpaceFlag = true; break; case "G21": system_initial_para.unitmode = true; SpaceFlag = true; break; case "G40": system_initial_para.makeup_right_left = 0; SpaceFlag = true; break; case "G41": system_initial_para.makeup_right_left = 1; SpaceFlag = true; break; case "G42": system_initial_para.makeup_right_left = 2; SpaceFlag = true; break; case "G43": system_initial_para.makeup_positive_negative = 1; SpaceFlag = true; break; case "G44": system_initial_para.makeup_positive_negative = 2; SpaceFlag = true; break; case "G49": system_initial_para.makeup_positive_negative = 0; SpaceFlag = true; break; case "G54": CooSystem_script.workpiece_flag = 1; CooSystem_script.Workpiece_Change(); SpaceFlag = true; break; case "G55": CooSystem_script.workpiece_flag = 2; CooSystem_script.Workpiece_Change(); SpaceFlag = true; break; case "G56": CooSystem_script.workpiece_flag = 3; CooSystem_script.Workpiece_Change(); SpaceFlag = true; break; case "G57": CooSystem_script.workpiece_flag = 4; CooSystem_script.Workpiece_Change(); SpaceFlag = true; break; case "G58": CooSystem_script.workpiece_flag = 5; CooSystem_script.Workpiece_Change(); SpaceFlag = true; break; case "G59": CooSystem_script.workpiece_flag = 6; CooSystem_script.Workpiece_Change(); SpaceFlag = true; break; case "G90": system_initial_para.absolute_relative = true; SpaceFlag = true; break; case "G91": system_initial_para.absolute_relative = false; SpaceFlag = true; break; default: break; } if (SpaceFlag) { CalStr.RemoveAt(j); j--; continue; } char[] codefield = CalStr[j].ToCharArray(); switch (codefield[0]) { case 'G': Gcode_Compile(CalStr[j], ref temp_code_info); break; case 'M': Mcode_Compile(CalStr, CalStr[j], ref temp_code_info); break; case 'F': string f_num = ""; for (int k = 1; k < codefield.Length; k++) { f_num += codefield[k]; } if (NumFormatCheck(f_num) == false || float.Parse(f_num) < 0) { Debug.Log("Number format is not correct. Please check your code on Line: " + "\"" + (i + (int)1) + "\""); return; } temp_code_info.f_value = float.Parse(f_num); system_initial_para.feed_rate = float.Parse(f_num); break; case 'S': string s_num = ""; for (int k = 1; k < codefield.Length; k++) { s_num += codefield[k]; } if (NumFormatCheck(s_num) == false || float.Parse(s_num) < 0) { Debug.Log("Number format is not correct. Please check your code on Line: " + "\"" + (i + (int)1) + "\""); return; } temp_code_info.s_value = float.Parse(s_num); system_initial_para.rotate_speed = float.Parse(s_num); break; case 'T': temp_code_info.im_execution.Add(CalStr[j]); system_initial_para.tool_num = CalStr[j]; temp_code_info.t_value = CalStr[j]; break; case 'X': string x_num = ""; for (int k = 1; k < codefield.Length; k++) { x_num += codefield[k]; } if (NumFormatCheck(x_num) == false) { Debug.Log("Number format is not correct. Please check your code on Line: " + "\"" + (i + (int)1) + "\""); return; } XYZ_Compile(CalStr, j, i + 1, x_num, 'X', ref temp_code_info); break; case 'Y': string y_num = ""; for (int k = 1; k < codefield.Length; k++) { y_num += codefield[k]; } if (NumFormatCheck(y_num) == false) { Debug.Log("Number format is not correct. Please check your code on Line: " + "\"" + (i + (int)1) + "\""); return; } XYZ_Compile(CalStr, j, i + 1, y_num, 'Y', ref temp_code_info); break; case 'Z': string z_num = ""; for (int k = 1; k < codefield.Length; k++) { z_num += codefield[k]; } if (NumFormatCheck(z_num) == false) { Debug.Log("Number format is not correct. Please check your code on Line: " + "\"" + (i + (int)1) + "\""); return; } XYZ_Compile(CalStr, j, i + 1, z_num, 'Z', ref temp_code_info); break; case 'I': //yo break; case 'J': //yo break; case 'K': //yo break; case 'H': //yo break; case 'D': //yo break; case 'P': //yo break; case 'R': //yo break; case 'L': //yo break; case 'N': break; default: Debug.Log(CalStr[j]); Debug.Log(CodeOfAll[i]); break; } } temp_code_info.s_value = system_initial_para.rotate_speed; temp_code_info.t_value = system_initial_para.tool_num; if (temp_code_info.move_flag) { if (temp_code_info.motion_str == "G00") { temp_code_info.f_value = G00_Move_speed; } else { temp_code_info.f_value = system_initial_para.feed_rate; } if (temp_code_info.s_value == 0 && temp_code_info.motion_str != "G00") { Debug.Log("Wrong! Tool rotate speed is not specified on code line: " + "\"" + (i + (int)1) + "\""); } if (temp_code_info.f_value == 0) { Debug.Log("Wrong! Feed Rate is not specified on code line: " + "\"" + (i + (int)1) + "\""); } } //代码解析 /* * if(move_mode == -1) * temp_code_info.movemode = motionCode[motionCode.Count - 1].movemode; * else * temp_code_info.movemode = move_mode; */ Debug.Log("end: " + i); motionCode.Add(temp_code_info); } } catch { Debug.Log("Exception"); } finally { Debug.Log("ok"); } }
// public void EmergencyCall() // { // motion_info_list.Clear(); // } public IEnumerator MotionStart() { CooZeroPoint = CooSystem_Script.AbsoluteZero; //获取当前绝对坐标系零点 // Main.AutoRunning_flag = true; if (Main.AutoRunning_flag) { DisplayStart(); } Main.CycleTimeH = 0; Main.CycleTimeM = 0; Main.CycleTimeS = 0; Auto_Script.cycling_time = 0; Auto_Script.runningH = Main.RunningTimeH; Auto_Script.runningM = Main.RunningTimeM; for (int index = 0; index < motion_info_list.Count; index++) { //1level Debug.Log(index + " >>> " + motion_info_list[index].index); //黄色光标跳转 // Main.autoSelecedProgRow = motion_info_list[index].index; if (Main.AutoRunning_flag) { Main.AutoDisplayFindRows(motion_info_list[index].index, Main.autoDisplayNormal); } if (Main.MDI_RunningFlag) { Main.MDIDisplayFindRows(motion_info_list[index].index); } Main.RunningSpeed = 0; Main.T_Value = Main.ToolNo; Main.D_value = motion_info_list[index].D_Value; Main.H_value = motion_info_list[index].H_Value; //判断是否内容为空 if (motion_info_list[index].NotEmpty()) { //2level //画面变化 if (Main.AutoRunning_flag) { //G_Display ProgramModule_Script.CurrentCodeDisplay(motion_info_list[index].G_Display, motion_info_list[index].G_Address, motion_info_list[index].Address_Value, motion_info_list[index].G_Display2, motion_info_list[index].G_Address2, motion_info_list[index].Address_Value2); //ModalIndex, ModalString ProgramModule_Script.SetModalState(motion_info_list[index].ModalIndex, motion_info_list[index].ModalString); //运动坐标信息 } //如果跳过功能启用,判断是否要跳过当前行 if (Slash_on) { if (motion_info_list[index].Slash > 0) { continue; } } //立即执行的功能 if (motion_info_list[index].Immediate_Motion != "") { for (int i = 0; i < motion_info_list[index].Immediate_Motion.Length; i++) { switch ((char)motion_info_list[index].Immediate_Motion[i]) { // case (char)ImmediateMotionType.ToolChanging: // Main.ToolNo = motion_info_list[index].Tool_Number; // break; case (char)ImmediateMotionType.M00: Auto_Script.SetPause(); Main.AutoPause_flag = true; break; case (char)ImmediateMotionType.M01: if (Main.OSP_On) { Auto_Script.SetPause(); Main.AutoPause_flag = true; } break; case (char)ImmediateMotionType.M02: Auto_Script.EmergencyCall(); Auto_Script.StopAllCoroutines(); Main.SpindleStop(); Main.AutoRunning_flag = false; Main.RunningSpeed = 0; break; case (char)ImmediateMotionType.M03: CurrentModal.RotateSpeed = motion_info_list[index].SpindleSpeed; Main.SpindleCW(CurrentModal.RotateSpeed); Main.SpindleSpeed = (int)CurrentModal.RotateSpeed; break; case (char)ImmediateMotionType.M04: CurrentModal.RotateSpeed = motion_info_list[index].SpindleSpeed; Main.SpindleCCW(CurrentModal.RotateSpeed); Main.SpindleSpeed = (int)CurrentModal.RotateSpeed; break; case (char)ImmediateMotionType.M05: Main.SpindleStop(); Main.SpindleSpeed = 0; break; // case (char)ImmediateMotionType.M06: // //更换刀具的过程 // break; case (char)ImmediateMotionType.M07: case (char)ImmediateMotionType.M08: case (char)ImmediateMotionType.M09: break; case (char)ImmediateMotionType.M30: Auto_Script.EmergencyCall(); Auto_Script.StopAllCoroutines(); Main.SpindleStop(); Main.AutoRunning_flag = false; Main.RunningSpeed = 0; if (Main.AutoRunning_flag) { Main.AutoDisplayFindRows(0, Main.autoDisplayNormal); } if (Main.MDI_RunningFlag) { Main.MDIDisplayFindRows(0); } // Main.autoSelecedProgRow = 0; break; case (char)ImmediateMotionType.M98: case (char)ImmediateMotionType.M99: break; case (char)ImmediateMotionType.G52: //局部坐标系变换 if (motion_info_list[index].CooTransformation.x == 0) { CooSystem_Script.AbsoluteZero.x = CooZeroPoint.x; } else { CooSystem_Script.AbsoluteZero.x = CooZeroPoint.x - motion_info_list[index].CooTransformation.x; } if (motion_info_list[index].CooTransformation.y == 0) { CooSystem_Script.AbsoluteZero.y = CooZeroPoint.y; } else { CooSystem_Script.AbsoluteZero.y = CooZeroPoint.y - motion_info_list[index].CooTransformation.y; } if (motion_info_list[index].CooTransformation.z == 0) { CooSystem_Script.AbsoluteZero.z = CooZeroPoint.z; } else { CooSystem_Script.AbsoluteZero.z = CooZeroPoint.z - motion_info_list[index].CooTransformation.z; } break; case (char)ImmediateMotionType.G53: //已经作为一种运动方式处理,这里直接跳过,去下面的流程中. break; case (char)ImmediateMotionType.G54: //工件坐标系设定 CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G54; CooSystem_Script.Workpiece_Change(); CooZeroPoint = CooSystem_Script.AbsoluteZero; CurrentModal.SetModalCode("G54", 13); break; case (char)ImmediateMotionType.G55: CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G55; CooSystem_Script.Workpiece_Change(); CooZeroPoint = CooSystem_Script.AbsoluteZero; CurrentModal.SetModalCode("G55", 13); break; case (char)ImmediateMotionType.G56: CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G56; CooSystem_Script.Workpiece_Change(); CooZeroPoint = CooSystem_Script.AbsoluteZero; CurrentModal.SetModalCode("G56", 13); break; case (char)ImmediateMotionType.G57: CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G57; CooSystem_Script.Workpiece_Change(); CooZeroPoint = CooSystem_Script.AbsoluteZero; CurrentModal.SetModalCode("G57", 13); break; case (char)ImmediateMotionType.G58: CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G58; CooSystem_Script.Workpiece_Change(); CooZeroPoint = CooSystem_Script.AbsoluteZero; CurrentModal.SetModalCode("G58", 13); break; case (char)ImmediateMotionType.G59: CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G59; CooSystem_Script.Workpiece_Change(); CooZeroPoint = CooSystem_Script.AbsoluteZero; CurrentModal.SetModalCode("G59", 13); break; case (char)ImmediateMotionType.G92: if (motion_info_list[index].CooState[0]) { CooSystem_Script.AbsoluteZero.x = motion_info_list[index].CooTransformation.x - Move_Script.MachineCoo.x; CooZeroPoint.x = CooSystem_Script.AbsoluteZero.x; CooSystem_Script.RelativeZero.x = CooSystem_Script.AbsoluteZero.x; } if (motion_info_list[index].CooState[1]) { CooSystem_Script.AbsoluteZero.y = motion_info_list[index].CooTransformation.y - Move_Script.MachineCoo.y; CooZeroPoint.y = CooSystem_Script.AbsoluteZero.y; CooSystem_Script.RelativeZero.y = CooSystem_Script.AbsoluteZero.y; } if (motion_info_list[index].CooState[2]) { CooSystem_Script.AbsoluteZero.z = motion_info_list[index].CooTransformation.z - Move_Script.MachineCoo.z; CooZeroPoint.z = CooSystem_Script.AbsoluteZero.z; CooSystem_Script.RelativeZero.z = CooSystem_Script.AbsoluteZero.z; } break; case (char)ImmediateMotionType.Pause: //已经作为一种运动方式处理,这里直接跳过,去下面的流程中. break; case (char)ImmediateMotionType.AutoReturnRP: //已经作为一种运动方式处理,这里直接跳过,去下面的流程中. break; case (char)ImmediateMotionType.BackFromRP: //已经作为一种运动方式处理,这里直接跳过,去下面的流程中. break; case (char)ImmediateMotionType.RadiusCompensationCancel: case (char)ImmediateMotionType.RadiusCompensationLeft: case (char)ImmediateMotionType.RadiusCompensationRight: case (char)ImmediateMotionType.LengthCompensationCancel: case (char)ImmediateMotionType.LengthCompensationNegative: case (char)ImmediateMotionType.LengthCompensationPositive: break; case (char)ImmediateMotionType.RotateSpeed: CurrentModal.RotateSpeed = motion_info_list[index].Rotate_Speed; break; default: break; } } } //常规运动 if (motion_info_list[index].Motion_Type != -1) { Main.RunningSpeed = (int)(motion_info_list[index].Velocity * Main.move_rate); SpeedNow = (int)motion_info_list[index].Velocity; Main.M_value = motion_info_list[index].M_Code; switch (motion_info_list[index].Motion_Type) { case (int)MotionType.DryRunning: // CurrentModal.SetModalCode("G00", 0); yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 0))); break; case (int)MotionType.MachineCooSys: yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 0))); break; case (int)MotionType.Line: // CurrentModal.SetModalCode("G01", 0); yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 0))); break; case (int)MotionType.Circular02: // CurrentModal.SetModalCode("G02", 0); yield return(StartCoroutine(Auto_Script.CircularMovement(motion_info_list[index].Direction, motion_info_list[index].VirtualTarget, motion_info_list[index].DisplayTarget, motion_info_list[index].DisplayStart, motion_info_list[index].Time_Value, motion_info_list[index].Center_Point, motion_info_list[index].Rotate_Speed, true, motion_info_list[index].Current_Plane, index, motion_info_list[index].Slices))); break; case (int)MotionType.Circular03: // CurrentModal.SetModalCode("G03", 0); yield return(StartCoroutine(Auto_Script.CircularMovement(motion_info_list[index].Direction, motion_info_list[index].VirtualTarget, motion_info_list[index].DisplayTarget, motion_info_list[index].DisplayStart, motion_info_list[index].Time_Value, motion_info_list[index].Center_Point, motion_info_list[index].Rotate_Speed, false, motion_info_list[index].Current_Plane, index, motion_info_list[index].Slices))); break; case (int)MotionType.AutoReturnRP: case (int)MotionType.BackFromRP: yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 1))); yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction2, motion_info_list[index].Time_Value2, motion_info_list[index].VirtualTarget2, index, 2))); break; case (int)MotionType.Pause: Auto_Script.SetPause(); yield return(StartCoroutine(Auto_Script.PauseTimer(motion_info_list[index].Time_Value))); break; default: Debug.Log("未知常规运动!"); break; } } } //2level //Todo:解决换刀过程不能被紧急停止的功能 for (int i = 0; i < motion_info_list[index].ToolChange_Motion.Length; i++) { switch (motion_info_list[index].ToolChange_Motion[i]) { case (char)ToolChange.T: yield return(StartCoroutine(AutoToolChange_Script.ChooseTool(motion_info_list[index].Tool_Number))); break; case (char)ToolChange.M: if (tool_motion_list[0].TimeValue > 0) { yield return(StartCoroutine(Auto_Script.LineMovement(tool_motion_list[0].Direction, tool_motion_list[0].TimeValue, tool_motion_list[0].VirtualTarget, motion_info_list.Count + tool_motion_list.Count, 0))); } tool_motion_list.RemoveAt(0); yield return(StartCoroutine(AutoToolChange_Script.ChangeToolProcess())); break; default: break; } } //单步运行 Main.RunningSpeed = 0; SpeedNow = 0; Main.M_value = 0; if (Main.SingleStep) { singleStepEnd = 100; yield return(StartCoroutine(SingleStepTimer())); } } //1level ProgramModule_Script.SetModalState(new List <int>(), new List <string>()); //模态变化的蓝色光标清空 if (Main.MDI_RunningFlag) { MDIStop(); } Main.AutoRunning_flag = false; Main.Compile_flag = false; Main.MDI_RunningFlag = false; Main.MDI_CompileFlag = false; Main.PartsNum++; //加工零件数+1 DisplayEnd(); Main.SpindleSpeed = 0; Main.T_Value = 0; Main.D_value = 0; Main.H_value = 0; ProgramModule_Script.CurrentCodeDisplay(new List <string>(), new List <string>(), new List <float>(), new List <string>(), new List <string>(), new List <float>()); //当前段和下一段显示清空 }