示例#1
0
    public void ReadCommandList()
    {
        foreach (string commandLine in commandList)
        {
            String[] cmds = commandLine.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            if (cmds.Length == 0)
            {
                continue;
            }
            foreach (string cmd in cmds)
            {
                ReadCommand(cmd);
            }

            if (modalGroupQueue.Count == 0)
            {
                SendCNCInstruction(CNCInstruction.GCode2ModalGroup(gCode));
            }
            while (modalGroupQueue.Count != 0)
            {
                SendCNCInstruction(modalGroupQueue.Dequeue());
            }
            ResetNonModal();
        }
    }
示例#2
0
    protected void ReadGroup1(CNCInstruction baseInstr)
    {
        if (isStartingTask)
        {
            CNCInstructionMotion instr = (CNCInstructionMotion)baseInstr;
            scaleVector = Vector3.one * instr.prefixModifier;
            target      = pieceOriginTransform.TransformPoint(Vector3.Scale(instr.TargetPos, scaleVector));

            if (gCode == 2 || gCode == 3)
            {
                InitializeG02_03(instr);

                // Spiral Checking
                float currentRadius = (TargetKnife.transform.position - pivot).magnitude;
                float targetRadius  = (target - pivot).magnitude;
                if (!CheckRadiusMatched(currentRadius, targetRadius) && AllowSpiral)
                {
                    PrintError("Warning: Radius Error, motion might be spiral.\n");
                }
            }
        }

        switch (gCode)
        {
        case 0:
            LinearTraverseTo(target, maxDistanceRapid);
            break;

        case 1:
            LinearTraverseTo(target, maxDistanceFeed);
            break;

        case 2:
            CircularTraverseTo(target, pivot, maxDistanceFeed, angleDiff, radiusDiff);
            if (IsAtTargetCrude(target))
            {
                isFinishedTask = true;
            }
            break;

        case 3:
            CircularTraverseTo(target, pivot, maxDistanceFeed, angleDiff, radiusDiff);
            if (IsAtTargetCrude(target))
            {
                isFinishedTask = true;
            }
            break;

        default:
            PrintError("Unknown G Code falling into ReadGroup1\n");
            break;
        }

        if (IsAtTarget(target))
        {
            isFinishedTask = true;
        }
    }
示例#3
0
    private void SendCNCInstruction(int modalGroup)
    {
        CNCInstruction instr;

        switch (modalGroup)
        {
        case 1:
            instr = new CNCInstructionMotion {
                G              = gCodeForEachGroup[1],
                Group          = modalGroup,
                prefixModifier = this.prefixModifier,
                FeedRate       = this.feedRate,
                SpindleSpeed   = this.spindleSpeed,
                Tool           = this.tool,
                MiscFunc       = this.miscFunc,
                posX           = this.posX,
                posY           = this.posY,
                posZ           = this.posZ,
                posI           = this.posI,
                posJ           = this.posJ,
                posK           = this.posK
            };
            break;

        default:
            instr = new CNCInstruction
            {
                G              = this.gCode,
                Group          = modalGroup,
                prefixModifier = this.prefixModifier,
                FeedRate       = this.feedRate,
                SpindleSpeed   = this.spindleSpeed,
                Tool           = this.tool,
                MiscFunc       = this.miscFunc
            };
            print("Invalid modal group Found");
            if (DebugVR != null)
            {
                DebugVR.Println("Invalid modal group found");
            }
            break;
        }

        TargetInstrList.AddLast(instr);
    }
示例#4
0
    protected void ReadInstruction(CNCInstruction instr)
    {
        gCode            = instr.G;
        FeedMoveSpeed    = instr.FeedRate * instr.prefixModifier;
        maxDistanceRapid = RapidMoveSpeed * Time.deltaTime;
        maxDistanceFeed  = FeedMoveSpeed * Time.deltaTime;
        switch (instr.Group)
        {
        case 1:
            ReadGroup1(instr);
            break;

        default:
            PrintError("Unimplemented G-Code found, cannot read instruction. Proceed to skip.\n");
            isFinishedTask = true;
            break;
        }
    }
示例#5
0
    // Update is called once per frame
    protected virtual void Update()
    {
        if (InstructionListIn.Count != 0)
        {
            Vector3 homeRel = pieceOriginTransform.InverseTransformPoint(Home.transform.position);
            CheckInstructionListIn(homeRel.x, homeRel.y, homeRel.z);
        }

        if (isTurnedOn)
        {
            PlayMachineSound();
            TurnOnLight();
            if (InstructionList.Count != 0 && isReady)
            {
                CNCInstruction instr = InstructionList.First.Value;
                if (isStartingTask)
                {
                    PrintInstruction();
                    if (NeedsCuttingFX(instr.G))
                    {
                        PlayCuttingSound();
                        PlayParticlesFX();
                    }
                }

                ReadInstruction(instr);

                isStartingTask = false;
                if (isFinishedTask)
                {
                    InstructionList.RemoveFirst();
                    isFinishedTask = false;
                    isStartingTask = true;

                    if (InstructionList.Count != 0)
                    {
                        if (!NeedsCuttingFX(InstructionList.First.Value.G))
                        {
                            StopCuttingSound();
                            StopParticlesFX();
                        }
                    }
                    else
                    {
                        StopCuttingSound();
                        StopParticlesFX();
                    }
                }
            }
            else
            {
                StopCuttingSound();
                StopParticlesFX();
            }
        }
        else
        {
            StopMachineSound();
            TurnOffLight();
        }
    }
示例#6
0
    private void ReadCommand(string cmd)
    {
        if (cmd.Length == 0)
        {
            return;
        }
        switch (cmd[0])
        {
        case 'N':
            if (isFirstCommand)
            {
                line++;
                isFirstCommand = false;
                break;
            }
            int num = int.Parse(cmd.Substring(1));
            if (++line != num)
            {
                print("Expected line number (N" + line + ") mismatched with the input line number (" + cmd + "), changed line number to " + cmd);
                line = num;
            }
            break;

        case 'G':
            gCode = int.Parse(cmd.Substring(1));
            int group = CNCInstruction.GCode2ModalGroup(gCode);
            modalGroupQueue.Enqueue(group);
            gCodeForEachGroup[group] = gCode;
            break;

        case 'F':
            feedRate = float.Parse(cmd.Substring(1));
            break;

        case 'S':
            spindleSpeed = float.Parse(cmd.Substring(1));
            break;

        case 'T':
            tool = int.Parse(cmd.Substring(1));
            break;

        case 'M':
            miscFunc = int.Parse(cmd.Substring(1));
            break;

        case 'X':
            posX = float.Parse(cmd.Substring(1));
            break;

        case 'Y':
            posY = float.Parse(cmd.Substring(1));
            break;

        case 'Z':
            posZ = float.Parse(cmd.Substring(1));
            break;

        case 'I':
            posI = float.Parse(cmd.Substring(1));
            break;

        case 'J':
            posJ = float.Parse(cmd.Substring(1));
            break;

        case 'K':
            posK = float.Parse(cmd.Substring(1));
            break;

        default:
            print("Unknown '" + cmd + "' command at line " + line + ", skipped this command.");
            if (DebugVR != null)
            {
                DebugVR.Println("Unknown '" + cmd + "' command at line " + line + ", skipped this command.");
            }
            break;
        }
    }