示例#1
0
        private void setCoordinateAScale(IDictionary <string, ParsedCmdGroup> block)
        {
            foreach (Axis axis in Enum.GetValues(typeof(Axis)))
            {
                if (block.ContainsKey(axis.ToString()))
                {
                    ParsedCmdGroup word = block[axis.ToString()];
                    switch (axis)
                    {
                    case Axis.X:
                        mbase.ScaleAt(new Vector3D(word.ValueAxis1, 1.0, 1.0), Ptc);
                        Ptc.X = mbase.OffsetX;
                        break;

                    case Axis.Y:
                        mbase.ScaleAt(new Vector3D(1.0, word.ValueAxis1, 1.0), Ptc);
                        Ptc.Y = mbase.OffsetY;
                        break;

                    case Axis.Z:
                        mbase.ScaleAt(new Vector3D(1.0, 1.0, word.ValueAxis1), Ptc);
                        Ptc.Z = mbase.OffsetZ;
                        break;
                    }
                }
            }
        }
示例#2
0
        private void setCoordinateScale(IDictionary <string, ParsedCmdGroup> block)
        {
            // Reset all transformations
            mbase.M11     = 1; mbase.M12 = 0; mbase.M13 = 0;               // x axis
            mbase.M21     = 0; mbase.M22 = 1; mbase.M23 = 0;               // y axis
            mbase.M31     = 0; mbase.M32 = 0; mbase.M33 = 1;               // z axis
            mbase.OffsetX = 0.0; mbase.OffsetY = 0.0; mbase.OffsetZ = 0.0; // offset
            Ptc.X         = 0.0; Ptc.Y = 0.0; Ptc.Z = 0.0;

            foreach (Axis axis in Enum.GetValues(typeof(Axis)))
            {
                if (block.ContainsKey(axis.ToString()))
                {
                    ParsedCmdGroup word = block[axis.ToString()];
                    switch (axis)
                    {
                    case Axis.X:
                        mbase.ScaleAt(new Vector3D(word.ValueAxis1, 1.0, 1.0), Ptc);
                        Ptc.X = mbase.OffsetX;
                        break;

                    case Axis.Y:
                        mbase.ScaleAt(new Vector3D(1.0, word.ValueAxis1, 1.0), Ptc);
                        Ptc.Y = mbase.OffsetY;
                        break;

                    case Axis.Z:
                        mbase.ScaleAt(new Vector3D(1.0, 1.0, word.ValueAxis1), Ptc);
                        Ptc.Z = mbase.OffsetZ;
                        break;
                    }
                }
            }
        }
示例#3
0
        private void setCoordinateRotate(IDictionary <string, ParsedCmdGroup> block)
        {
            // Reset all transformations
            mbase.M11     = 1; mbase.M12 = 0; mbase.M13 = 0;               // x axis
            mbase.M21     = 0; mbase.M22 = 1; mbase.M23 = 0;               // y axis
            mbase.M31     = 0; mbase.M32 = 0; mbase.M33 = 1;               // z axis
            mbase.OffsetX = 0.0; mbase.OffsetY = 0.0; mbase.OffsetZ = 0.0; // offset
            Ptc.X         = 0.0; Ptc.Y = 0.0; Ptc.Z = 0.0;                 // rotate center point

            foreach (Axis axis in Enum.GetValues(typeof(Axis)))
            {
                if (block.ContainsKey(axis.ToString()))
                {
                    ParsedCmdGroup word = block[axis.ToString()];
                    switch (axis)
                    {
                    case Axis.X:
                        mbase.RotateAt(new Quaternion(new Vector3D(mbase.M11, mbase.M12, mbase.M13), word.ValueAxis1), Ptc);
                        break;

                    case Axis.Y:
                        mbase.RotateAt(new Quaternion(new Vector3D(mbase.M21, mbase.M22, mbase.M23), word.ValueAxis1), Ptc);
                        break;

                    case Axis.Z:
                        mbase.RotateAt(new Quaternion(new Vector3D(mbase.M31, mbase.M32, mbase.M33), word.ValueAxis1), Ptc);
                        break;
                    }
                }
            }
        }
示例#4
0
        private void setCoordinateATrans(IDictionary <string, ParsedCmdGroup> block)
        {
            foreach (Axis axis in Enum.GetValues(typeof(Axis)))
            {
                if (block.ContainsKey(axis.ToString()))
                {
                    ParsedCmdGroup word = block[axis.ToString()];
                    switch (axis)
                    {
                    case Axis.X:
                        Ptc.X = word.ValueAxis1;
                        mbase.TranslatePrepend(new Vector3D(Ptc.X, 0.0, 0.0));
                        Ptc.X = mbase.OffsetX;
                        Ptc.Y = mbase.OffsetY;
                        Ptc.Z = mbase.OffsetZ;
                        break;

                    case Axis.Y:
                        Ptc.Y = word.ValueAxis1;
                        mbase.TranslatePrepend(new Vector3D(0.0, Ptc.Y, 0.0));
                        Ptc.X = mbase.OffsetX;
                        Ptc.Y = mbase.OffsetY;
                        Ptc.Z = mbase.OffsetZ;
                        break;

                    case Axis.Z:
                        Ptc.Z = word.ValueAxis1;
                        mbase.TranslatePrepend(new Vector3D(0.0, 0.0, Ptc.Z));
                        Ptc.X = mbase.OffsetX;
                        Ptc.Y = mbase.OffsetY;
                        Ptc.Z = mbase.OffsetZ;
                        break;
                    }
                    //			machineOffsets[axis] = word.value ;
                }
            }
            //	Console.WriteLine("OFFSET" + " " + mbase.OffsetX + " " + mbase.OffsetY + " " + mbase.OffsetZ) ;
        }
示例#5
0
        private void setCoordinateARotate(IDictionary <string, ParsedCmdGroup> block)
        {
            foreach (Axis axis in Enum.GetValues(typeof(Axis)))
            {
                if (block.ContainsKey(axis.ToString()))
                {
                    ParsedCmdGroup word = block[axis.ToString()];
                    switch (axis)
                    {
                    case Axis.X:
                        mbase.RotateAt(new Quaternion(new Vector3D(mbase.M11, mbase.M12, mbase.M13), word.ValueAxis1), Ptc);
                        break;

                    case Axis.Y:
                        mbase.RotateAt(new Quaternion(new Vector3D(mbase.M21, mbase.M22, mbase.M23), word.ValueAxis1), Ptc);
                        break;

                    case Axis.Z:
                        mbase.RotateAt(new Quaternion(new Vector3D(mbase.M31, mbase.M32, mbase.M33), word.ValueAxis1), Ptc);
                        break;
                    }
                }
            }
        }
示例#6
0
        private void parseLine()
        {
            // Remove comments between () and all comments after ;
            StringBuilder parsedLine = new StringBuilder(currentLine);
            Match         g4         = G04.Match(parsedLine.ToString());
            Match         comment1   = COMMENTS1.Match(parsedLine.ToString());
            Match         comment2   = COMMENTS2.Match(parsedLine.ToString());

            if (g4.Success)
            {
//					currentLine.Replace(g4.Value, "") ;
            }
            if (comment1.Success && (MachineType == "Fanuc" || MachineType == "Okuma" || MachineType == "Mayak"))
            {
                parsedLine.Remove(comment1.Index, comment1.Length);                          // for Fanuc, Okuma, Haas
            }
            if (comment2.Success)
            {
                parsedLine.Remove(comment2.Index, comment2.Length);                          // for Sinumerik
            }

            ISet <string> wordcmd = new HashSet <string>();
            String        parsedWords;

            if ((parsedWords = findWords(parsedLine)) != null)
            {
                wordcmd.Add(parsedWords);
            }

            //      Console.WriteLine("currentPosition: " + "X:"+ machineStatus.newPosition[MachineStatus.Axis.X].Value + "Y:"+ machineStatus.newPosition[MachineStatus.Axis.Y].Value + "Z:"+ machineStatus.newPosition[MachineStatus.Axis.Z].Value ) ;
            //		Console.WriteLine(machineStatus.newLine) ;
            // A map that holds all parsed codes
            IDictionary <string, ParsedWord>     block    = new Dictionary <string, ParsedWord>(10);
            IDictionary <string, ParsedCmdGroup> CmdBlock = new Dictionary <string, ParsedCmdGroup>();
            // Hold's the current parsed word
            ParsedWord     thisWord;
            ParsedWord     addWord;
            ParsedCmdGroup thisCmdGroup;


//			while ((addWord = findWordInBlock(machineStatus.newLine)) != null)
//			{
//					int pos = machineStatus.newLine.ToString().IndexOf(addWord.asRead);
//					machineStatus.newLine.Remove(pos, pos + addWord.asRead.Length - pos).Insert(pos, "");
//
//					string blockKey = addWord.word;
//					block.Add(blockKey, addWord);
//			}


            while ((thisWord = findWordInBlock(parsedLine)) != null)
            {
                // Devide string by block
                int pos = parsedLine.ToString().IndexOf(thisWord.asRead);
                parsedLine.Remove(pos, pos + thisWord.asRead.Length - pos).Insert(pos, "");


                // We can have multiple G/M words within a block, so we move them to the 'key'
                string blockKey    = thisWord.word;
                string CmdBlockKey = "";

                if (blockKey.Equals("G") || blockKey.Equals("M"))
                {
                    blockKey = thisWord.parsed.Replace('.', '_');                     // Store gwords with a . as _ Example G33.1
                }
                if (blockKey.Contains("TRANS") || blockKey.Contains("ROT") || blockKey.Contains("SCALE") || blockKey.Contains("MIRROR"))
                {
                    string Block      = parsedLine.ToString();
                    Match  CmdMatcher = Gcodepattern.Match(Block);

                    while (CmdMatcher.Success)
                    {
                        string g0 = CmdMatcher.Groups[0].ToString();
                        string g1 = CmdMatcher.Groups[1].ToString();
                        string g3 = CmdMatcher.Groups[3].ToString().Replace('.', ',');
                        if (g3 != "")
                        {
                            double v     = Convert.ToDouble(g3);
                            string value = String.Format("{0:}", v);
                            thisCmdGroup = new ParsedCmdGroup(blockKey, g1, v, g1 + value, g0);
                            CmdBlockKey  = thisCmdGroup.AxisName1;
                            CmdBlock.Add(CmdBlockKey, thisCmdGroup);
                        }

                        CmdMatcher = CmdMatcher.NextMatch();
                    }

                    parsedLine.Clear();
                }


                if (block.ContainsKey(blockKey))
                {
                    throw new SimValidationException("Multiple " + thisWord.word + " words on one line.");
                }
                else
                {
                    block.Add(blockKey, thisWord);
                }
            }


            foreach (KeyValuePair <string, ParsedWord> pair in block)
            {
//				Console.WriteLine("Key : " + pair.Key + " " + "Value : " + pair.Value) ;
            }

            // First verify if the block itself is valid before we process it
            if (machineValidator != null)
            {
                machineValidator.preVerify(block);
            }

            // Copy to intermediate status to ensure our machine status is always valid
            intermediateStatus.copyFrom(machineStatus);
            // Notify the controller that we are about to start a new block, the block itself is valid, for example there we be no G1's and G0 on one line
            foreach (IMachineController controller in this.machineController)
            {
                controller.startBlock(this, intermediateStatus, block);
            }
            intermediateStatus.startBlock();

            // Copy the block to the machine
            intermediateStatus.setWord(wordcmd);
            intermediateStatus.setCommandBlk(CmdBlock, block);
            intermediateStatus.setBlock(block);

            // Block en, no more data will come in for this block
            intermediateStatus.endBlock();

            // Verify machine's state, for example if a R was found, do we also have a valid G to accompany with it?
            if (machineValidator != null)
            {
                machineValidator.postVerify(intermediateStatus);
            }

            // Notify the controller that everything was ok, now teh controller start 'running' the data
            foreach (IMachineController controller in this.machineController)
            {
                controller.endBlock(this, intermediateStatus, block);
            }


            // setup new and valid machine status
            machineStatus.copyFrom(intermediateStatus);
        }