// Use this for initialization void Start() { /* * tryCreate = (GameObject)Resources.Load("EmptyObject"); * Instantiate(tryCreate); * tryCreate.transform.name = "tryCreate"; */ NCCodeFormat_Script = GameObject.Find("MainScript").GetComponent <NCCodeFormat>(); ProgramModule_Script = GameObject.Find("MainScript").GetComponent <ProgramModule>(); CooSystem_Script = GameObject.Find("MainScript").GetComponent <CooSystem>(); Main = GameObject.Find("MainScript").GetComponent <ControlPanel>(); Auto_Script = GameObject.Find("AutoMove").GetComponent <AutoMoveModule>(); Move_Script = GameObject.Find("move_control").GetComponent <MoveControl>(); SpindleControl_script = GameObject.Find("spindle_control").GetComponent <SpindleControl>(); PathLineDraw_Script = GameObject.Find("Main Camera").GetComponent <PathLineDraw>(); AutoToolChange_Script = GameObject.Find("ToolChange").GetComponent <AutoToolChangeModule>(); Warnning_Script = gameObject.GetComponent <Warnning>(); Softkey_Script = gameObject.GetComponent <SoftkeyModule>(); CooZeroPoint = new Vector3(0, 0, 0); singleStepEnd = 100; CurrentModal = new ModalCode_Fanuc_M(); // CurrentModal.RotateSpeed = 3000; GameObject ForCuttingWork = GameObject.Find("GameObject"); if (ForCuttingWork == null) { Debug.LogError("请添加空物体GameObject!"); return; } ForCuttingWork.name = "CuttingWork"; ForCuttingWork.AddComponent <CuttingWork>(); CuttingWork_Script = ForCuttingWork.GetComponent <CuttingWork>(); }
void CloneTest() { ModalCode_Fanuc_M original_class = new ModalCode_Fanuc_M(); Debug.Log( "original1: "+original_class.Modal_Code[10]); original_class.Modal_Code[10] = "G1111"; Debug.Log("original2: "+original_class.Modal_Code[10]); ModalCode_Fanuc_M copy1 = new ModalCode_Fanuc_M(original_class); Debug.Log("copy1: "+copy1.Modal_Code[10]); copy1.Modal_Code[10] = "copy"; Debug.Log("compare: " + original_class.Modal_Code[10] + copy1.Modal_Code[10]); }
/// <summary> /// 实现复制的初始化 <see cref="ModalCode_Fanuc_M"/> class. /// </summary> /// <param name='aim_class'> /// 复制的目标对象 /// </param> public ModalCode_Fanuc_M(ModalCode_Fanuc_M aim_class) { _modal_code = new string[] { "G00", "G94", "G80", "G17", "G21", "G98", "G90", "G40", "G50", "G22", "G49", "G67", "G97", "G54", "G64", "G69", "G15", "G40.1", "G25", "G160", "G13.1", "G50.1", "G54.2", "G80.5" }; Slash = aim_class.Slash; Feedrate = aim_class.Feedrate; RotateSpeed = aim_class.RotateSpeed; code_location = new Dictionary <string, int>(); LocationInitialize(); D_Value = aim_class.D_Value; H_Value = aim_class.H_Value; CooZero = aim_class.CooZero; ReferencePoint = aim_class.ReferencePoint; referenceFlag[0] = aim_class.referenceFlag[0]; referenceFlag[1] = aim_class.referenceFlag[1]; referenceFlag[2] = aim_class.referenceFlag[2]; for (int i = 0; i < aim_class.Modal_Code.Length; i++) { _modal_code[i] = aim_class.Modal_Code[i]; } }
public bool G_Check(string g_str, int row_index, ref DataStore step_compile_data, ref ModalCode_Fanuc_M modal_state) { _errorMessage = ""; if(satisfactoryG_T.IndexOf(g_str) == -1) { _errorMessage = "(Line:" + row_index + "): " + "系统中不存在该G指令: " + g_str; return false; } else return true; }
public bool G_Check(string g_str, int row_index, ref DataStore step_compile_data, ref ModalCode_Fanuc_M modal_state) { _errorMessage = ""; if(satisfactoryG_M.IndexOf(g_str) == -1) { _errorMessage = "(Line:" + row_index + "): " + "系统中不存在该G指令: " + g_str; return false; } else { try { float g_value = (float)Convert.ToDouble(g_str.Trim('G')); if(g_value < 10f) g_str = "G0" + g_value.ToString(); } catch { _errorMessage = "(Line:" + row_index + "): " + "系统中不存在该G指令: " + g_str; return false; } int modal_index = modal_state.ModalIndex(g_str); //立即执行G代码(非模态G代码) if(modal_index == -1) { switch(g_str) { case "G04": case "G28": step_compile_data.immediate_execution.Add(g_str); break; default: //Todo: 有很多未完成的功能 _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持该G代码: " + g_str; return false; } } //模态代码 else {//1 level switch(modal_index) { case 0: step_compile_data.motion_string = g_str; break; case 1: if(g_str != "G94") { _errorMessage = "(Line:" + row_index + "): " + "目前系统只支持G94(每分钟进给),暂不支持" + g_str; return false; } break; case 2: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持09组G代码"; return false; case 3: if(g_str != "G17") { _errorMessage = "(Line:" + row_index + "): " + "目前系统只支持G17(XY平面选择),暂不支持" + g_str; return false; } break; case 4: if(g_str != "G21") { _errorMessage = "(Line:" + row_index + "): " + "目前系统只支持G21(公制输入),暂不支持" + g_str; return false; } break; case 5: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持10组固定循环G代码"; return false; case 6: //G90、G91 绝对、增量 //Todo: break; case 7: //G40, G41, G42 刀具半径补偿 //Todo: 坐标会发生一些变化 step_compile_data.immediate_execution.Add(g_str); break; case 8: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持11组比例缩放G代码"; return false; case 9: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持04组存储形成检测功能G代码"; return false; case 10: //G43, G44, G49 刀具长度补偿 //Todo: 坐标会发生一些变化 step_compile_data.immediate_execution.Add(g_str); break; case 11: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持12组宏模态调用G代码"; return false; case 12: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持13组周速恒定控制G代码"; return false; case 13: //G54, G54.1, G55, G56, G57, G58, G59 //Todo: 坐标会发生一些变化 step_compile_data.immediate_execution.Add(g_str); break; case 14: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持15组G代码"; return false; case 15: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持16组坐标旋转方式G代码"; return false; case 16: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持17组极坐标指令G代码"; return false; case 17: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持18组法线方向控制G代码"; return false; case 18: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G25代码"; return false; case 19: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持20组横向进磨控制(磨床用)G代码"; return false; case 20: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G13.1代码"; return false; case 21: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持22组可编程镜像G代码"; return false; case 22: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G54.2代码"; return false; case 23: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G80.5代码"; return false; default: break; } //模态代码改变 if(modal_state.Modal_Code[modal_index] != g_str) { step_compile_data.modal_index.Add(modal_index); step_compile_data.modal_string.Add(g_str); modal_state.SetModalCode(g_str, modal_index); } step_compile_data.G_code.Add(g_str); }//1 level return true; } }
private bool G_Check(string code_str, int row_index, ref DataStore step_compile_data, ref ModalCode_Fanuc_M modal_state) { _errorMessage = ""; bool temp_flag = this.g_code_check.G_Check(code_str, row_index, ref step_compile_data, ref modal_state); _errorMessage = this.g_code_check.ErrorMessage; return temp_flag; }
/// <summary> /// 克隆当前系统中的模态信息 /// </summary> /// <param name='current_modal'> /// 当前系统中的模态信息 /// </param> public void ModalClone(ModalCode_Fanuc_M current_modal) { for(int i = 0; i < current_modal.Modal_Code.Length; i++) { ModalState.Modal_Code[i] = current_modal.Modal_Code[i]; } }
public LexicalCheck() { _errorMessage = ""; _compileInfo = new List<string>(); ModalState = new ModalCode_Fanuc_M(); /* CheckFunc = new Dictionary<int, Func<string, int, bool>>(); CheckFunc.Add((int)FuncSelect.G_Check, G_Check); CheckFunc.Add((int)FuncSelect.M_Check, M_Check); CheckFunc.Add((int)FuncSelect.F_Check, F_Check); CheckFunc.Add((int)FuncSelect.I_Check, I_Check); CheckFunc.Add((int)FuncSelect.Slash_Check, Slash_Check); */ }
public bool G_Check(string g_str, int row_index, ref DataStore step_compile_data, ref ModalCode_Fanuc_M modal_state) { _errorMessage = ""; if(satisfactoryG_M.IndexOf(g_str) == -1) { _errorMessage = "(Line:" + row_index + "): " + "系统中不存在该G指令: " + g_str; return false; } else { try { float g_value = (float)Convert.ToDouble(g_str.Trim('G')); if(g_value < 10f) g_str = "G0" + g_value.ToString(); } catch { _errorMessage = "(Line:" + row_index + "): " + "系统中不存在该G指令: " + g_str; return false; } int modal_index = modal_state.ModalIndex(g_str); //立即执行G代码(非模态G代码) if(modal_index == -1) { switch(g_str) { case "G04": step_compile_data.ImmediateAdd((char)ImmediateMotionType.Pause); break; case "G28": step_compile_data.ImmediateAdd((char)ImmediateMotionType.AutoReturnRP); break; default: //Todo: 有很多未完成的功能 _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持该G代码: " + g_str; return false; } } //模态代码 else {//1 level switch(modal_index) { case 0: if(g_str == "G00") step_compile_data.motion_type = (int)MotionType.DryRunning; else if(g_str == "G01") step_compile_data.motion_type = (int)MotionType.Line; else if(g_str == "G02") step_compile_data.motion_type = (int)MotionType.Circular02; else step_compile_data.motion_type = (int)MotionType.Circular03; break; case 1: if(g_str != "G94") { _errorMessage = "(Line:" + row_index + "): " + "目前系统只支持G94(每分钟进给),暂不支持" + g_str; return false; } break; case 2: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持09组G代码"; return false; case 3: if(g_str != "G17") { _errorMessage = "(Line:" + row_index + "): " + "目前系统只支持G17(XY平面选择),暂不支持" + g_str; return false; } break; case 4: if(g_str != "G21") { _errorMessage = "(Line:" + row_index + "): " + "目前系统只支持G21(公制输入),暂不支持" + g_str; return false; } break; case 5: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持10组固定循环G代码"; return false; case 6: //G90、G91 绝对、增量 //Todo: break; case 7: //G40, G41, G42 刀具半径补偿 //Todo: 坐标会发生一些变化 if(g_str == "G40") step_compile_data.ImmediateAdd((char)ImmediateMotionType.RadiusCompensationCancel); else if(g_str == "G41") step_compile_data.ImmediateAdd((char)ImmediateMotionType.RadiusCompensationLeft); else step_compile_data.ImmediateAdd((char)ImmediateMotionType.RadiusCompensationRight); break; case 8: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持11组比例缩放G代码"; return false; case 9: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持04组存储形成检测功能G代码"; return false; case 10: //G43, G44, G49 刀具长度补偿 //Todo: 坐标会发生一些变化 if(g_str == "G43") step_compile_data.ImmediateAdd((char)ImmediateMotionType.LengthCompensationPositive); else if(g_str == "G44") step_compile_data.ImmediateAdd((char)ImmediateMotionType.LengthCompensationNegative); else step_compile_data.ImmediateAdd((char)ImmediateMotionType.LengthCompensationCancel); break; case 11: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持12组宏模态调用G代码"; return false; case 12: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持13组周速恒定控制G代码"; return false; case 13: //G54, G54.1, G55, G56, G57, G58, G59 //Todo: 坐标会发生一些变化 if(g_str == "G54.1") { _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G54.1追加工件坐标系功能"; return false; } else if(g_str == "G54") step_compile_data.ImmediateAdd((char)ImmediateMotionType.G54); else if(g_str == "G55") step_compile_data.ImmediateAdd((char)ImmediateMotionType.G55); else if(g_str == "G56") step_compile_data.ImmediateAdd((char)ImmediateMotionType.G56); else if(g_str == "G57") step_compile_data.ImmediateAdd((char)ImmediateMotionType.G57); else if(g_str == "G58") step_compile_data.ImmediateAdd((char)ImmediateMotionType.G58); else step_compile_data.ImmediateAdd((char)ImmediateMotionType.G59); break; case 14: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持15组G代码"; return false; case 15: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持16组坐标旋转方式G代码"; return false; case 16: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持17组极坐标指令G代码"; return false; case 17: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持18组法线方向控制G代码"; return false; case 18: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G25代码"; return false; case 19: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持20组横向进磨控制(磨床用)G代码"; return false; case 20: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G13.1代码"; return false; case 21: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持22组可编程镜像G代码"; return false; case 22: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G54.2代码"; return false; case 23: _errorMessage = "(Line:" + row_index + "): " + "目前系统暂不支持G80.5代码"; return false; default: break; } //模态代码改变 if(modal_state.Modal_Code[modal_index] != g_str) { step_compile_data.modal_index.Add(modal_index); step_compile_data.modal_string.Add(g_str); modal_state.SetModalCode(g_str, modal_index); } step_compile_data.G_code.Add(g_str); }//1 level return true; } }
/// <summary> /// 实现复制的初始化 <see cref="ModalCode_Fanuc_M"/> class. /// </summary> /// <param name='aim_class'> /// 复制的目标对象 /// </param> public ModalCode_Fanuc_M(ModalCode_Fanuc_M aim_class) { _modal_code = new string[]{"G00", "G94", "G80", "G17", "G21", "G98", "G90", "G40", "G50", "G22", "G49", "G67", "G97", "G54", "G64", "G69", "G15", "G40.1", "G25", "G160", "G13.1", "G50.1", "G54.2", "G80.5"}; code_location = new Dictionary<string, int>(); LocationInitialize(); for(int i = 0; i < aim_class.Modal_Code.Length; i++) { _modal_code[i] = aim_class.Modal_Code[i]; } }
public int CircleArguJudge(ref string error_string, ModalCode_Fanuc_M modal_state, ref Vector3 ijk_coo, ref float rValue) { //终点坐标在原地 if (xyz_state[0] == false && xyz_state[1] == false && xyz_state[2] == false) { //若R有赋值,返回0停在原地 if (ijk_state[3]) { return(0); } //若R和IJK都没有赋值,返回0停在原地 else if (ijk_state[0] == false && ijk_state[1] == false && ijk_state[2] == false) { return(0); } else { //三种平面下的判断及圆心增量坐标获取,如果返回1则为整圆情况 switch (modal_state.PlaneCheck()) { case (int)CheckInformation.XYPlane: if (ijk_state[2]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { ijk_coo = new Vector3(i_value, j_value, 0); return(1); } case (int)CheckInformation.ZXPlane: if (ijk_state[1]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { ijk_coo = new Vector3(i_value, 0, k_value); return(1); } case (int)CheckInformation.YZPlane: if (ijk_state[0]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { ijk_coo = new Vector3(0, j_value, k_value); return(1); } default: error_string = "平面选择错误,不存在这样的平面"; return(-1); } } } //有终点坐标 else { //三种平面下的判断及圆心增量坐标和Display坐标(增量或最终值),如果返回2则为IJK,返回3则为R switch (modal_state.PlaneCheck()) { case (int)CheckInformation.XYPlane: if (xyz_state[2]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { //有R在 if (ijk_state[3]) { rValue = r_value; return(3); } //没有R else { if (ijk_state[2]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { ijk_coo = new Vector3(i_value, j_value, 0); return(2); } } } case (int)CheckInformation.ZXPlane: if (xyz_state[1]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { //有R在 if (ijk_state[3]) { rValue = r_value; return(3); } //没有R else { if (ijk_state[1]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { ijk_coo = new Vector3(i_value, 0, k_value); return(2); } } } case (int)CheckInformation.YZPlane: if (xyz_state[0]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { //有R在 if (ijk_state[3]) { rValue = r_value; return(3); } //没有R else { if (ijk_state[0]) { error_string = "平面选择与输入坐标不符"; return(-1); } else { ijk_coo = new Vector3(0, j_value, k_value); return(2); } } } default: error_string = "平面选择错误,不存在这样的平面"; return(-1); } } }
public int CircleArguJudge(ref string error_string, ModalCode_Fanuc_M modal_state, ref Vector3 ijk_coo, ref Vector3 xyz_coo, ref float rValue) { //终点坐标在原地 if(xyz_state[0] == false && xyz_state[1] == false && xyz_state[2] == false) { //若R有赋值,返回0停在原地 if(ijk_state[3]) return 0; //若R和IJK都没有赋值,返回0停在原地 else if(ijk_state[0] == false && ijk_state[1] == false && ijk_state[2] == false) return 0; else { //三种平面下的判断及圆心增量坐标获取,如果返回1则为整圆情况 switch(modal_state.Modal_Code[3]) { case "G17": if(ijk_state[2]) { error_string = "平面选择与输入坐标不符"; return -1; } else { ijk_coo = new Vector3(i_value, j_value, 0); return 1; } case "G18": if(ijk_state[1]) { error_string = "平面选择与输入坐标不符"; return -1; } else { ijk_coo = new Vector3(i_value, 0, k_value); return 1; } case "G19": if(ijk_state[0]) { error_string = "平面选择与输入坐标不符"; return -1; } else { ijk_coo = new Vector3(0, j_value, k_value); return 1; } default: error_string = "平面选择错误,不存在这样的平面"; return -1; } } } //有终点坐标 else { //三种平面下的判断及圆心增量坐标和Display坐标(增量或最终值),如果返回2则为IJK,返回3则为R switch(modal_state.Modal_Code[3]) { case "G17": if(xyz_state[2]) { error_string = "平面选择与输入坐标不符"; return -1; } else { xyz_coo = new Vector3(x_value, y_value, 0); //有R在 if(ijk_state[3]) { rValue = r_value; return 3; } //没有R else { if(ijk_state[2]) { error_string = "平面选择与输入坐标不符"; return -1; } else { ijk_coo = new Vector3(i_value, j_value, 0); return 2; } } } case "G18": if(xyz_state[1]) { error_string = "平面选择与输入坐标不符"; return -1; } else { xyz_coo = new Vector3(x_value, 0, z_value); //有R在 if(ijk_state[3]) { rValue = r_value; return 3; } //没有R else { if(ijk_state[1]) { error_string = "平面选择与输入坐标不符"; return -1; } else { ijk_coo = new Vector3(i_value, 0, k_value); return 2; } } } case "G19": if(xyz_state[0]) { error_string = "平面选择与输入坐标不符"; return -1; } else { xyz_coo = new Vector3(0, y_value, z_value); //有R在 if(ijk_state[3]) { rValue = r_value; return 3; } //没有R else { if(ijk_state[0]) { error_string = "平面选择与输入坐标不符"; return -1; } else { ijk_coo = new Vector3(0, j_value, k_value); return 2; } } } default: error_string = "平面选择错误,不存在这样的平面"; return -1; } } }