Beispiel #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Converts the excellon line into a GCode line and returns it
        /// </summary>
        /// <param name="stateMachine">the state machine with the configuration</param>
        /// <param name="gcLineList">a list of the equivalent gcode line object. This can be
        /// empty if there is no direct conversion</param>
        /// <returns>z success, nz fail</returns>
        public override int GetGCodeCmd(ExcellonFileStateMachine stateMachine, out List <GCodeCmd> gcLineList)
        {
            GCodeCmd_Comment coLine = null;

            gcLineList = new List <GCodeCmd>();

            coLine = new GCodeCmd_Comment("ToolTable: Tool " + toolNumber.ToString() + ", Dia= " + drillDiameter.ToString());
            gcLineList.Add(coLine);

            return(0);
        }
Beispiel #2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Generates the gcode to mill a pocket in the surface. We use this for
        /// BedFlattening
        /// </summary>
        /// <remarks>the gcode file is assumed to have been populated with the standard headers.
        /// We just add our lines onto the end.</remarks>
        /// <param name="lX">low x coord</param>
        /// <param name="lY">low y coord</param>
        /// <param name="hX">high x coord</param>
        /// <param name="hY">high y coord</param>
        /// <param name="millWidth">the diameter of the mill doing the pocketing</param>
        /// <param name="overlapScaleFactor">the amount of overlap we require. Expressed as decimal fraction. 0.25 =25%</param>
        /// <param name="errStr">the error string</param>
        public int GeneratePocketGCode(float isoPlotPointsPerAppUnit, float lX, float lY, float hX, float hY, float millWidth, float overlapScaleFactor, ref string errStr)
        {
            int                i      = 0;
            GCodeCmd_ZMove     zLine  = null;
            GCodeCmd_RapidMove rmLine = null;
            GCodeCmd_Line      gcLine = null;
            GCodeCmd_Comment   coLine = null;

            errStr = "";
            float centerX;
            float centerY;
            float lXCutCoord;
            float lYCutCoord;
            float hXCutCoord;
            float hYCutCoord;
            float lastXCoord;
            float lastYCoord;

            // test these
            if (isoPlotPointsPerAppUnit <= 0)
            {
                LogMessage("GeneratePocketGCode: isoPlotPointsPerAppUnit<=0");
                errStr = "isoPlotPointsPerAppUnit is invalid.";
                return(1023);
            }

            if ((lX == float.MaxValue) ||
                (lY == float.MaxValue) ||
                (hX == float.MinValue) ||
                (hY == float.MinValue))
            {
                LogMessage("GeneratePocketGCode: One or more of the lX,lY,hXor hY coordinates are invalid.");
                errStr = "The X and Y coordinates of the pocket rectangle are invalid.";
                return(1024);
            }
            // do we enclose an area?
            if ((lX == hX) || (lY == hY))
            {
                LogMessage("GeneratePocketGCode: The lX,lY,hXor hY coordinates do not enclose an area.");
                errStr = "The X and Y coordinates of the pocket rectangle do not enclose an area.";
                return(1025);
            }
            // are we inverted
            if ((lX > hX) || (lY > hY))
            {
                LogMessage("GeneratePocketGCode: The lX,lY,hXor hY coordinates are inverted.");
                errStr = "The X and Y coordinates of the pocket rectangle are inverted.";
                return(1026);
            }
            // more checks
            if (millWidth < 0)
            {
                LogMessage("GeneratePocketGCode: The millWidth is invalid.");
                errStr = "The millWidth is invalid.";
                return(1027);
            }
            // more checks
            if ((overlapScaleFactor > 1) || (overlapScaleFactor < 0))
            {
                LogMessage("GeneratePocketGCode: The overlapScaleFactor is invalid.");
                errStr = "The overlapScaleFactor is invalid.";
                return(1028);
            }
            if (StateMachine.CurrentZFeedrate <= 0)
            {
                LogMessage("GeneratePocketGCode: The zFeedRate is invalid.");
                errStr = "The zFeedRate is invalid.";
                return(1029);
            }
            if (StateMachine.CurrentXYFeedrate <= 0)
            {
                LogMessage("GeneratePocketGCode: The xyFeedRate is invalid.");
                errStr = "The xyFeedRate is invalid.";
                return(1030);
            }
            if (StateMachine.ZCoordForCut > StateMachine.ZCoordForClear)
            {
                LogMessage("GeneratePocketGCode: The zCutLevel > zClearLevel. This cannot be correct.");
                errStr = "The zCutLevel > zClearLevel. This cannot be correct.";
                return(1031);
            }
            // test to see if the pocket can be cut with this mill
            if ((millWidth >= (hX - lX)) || (millWidth >= (hY - lY)))
            {
                LogMessage("GeneratePocketGCode: The mill diameter is bigger than the pocket area.");
                errStr = "The mill diameter is bigger than the pocket area. Pocket cannot be cut with this mill.";
                return(1031);
            }

            // calculate the center point
            centerX = (((hX - lX) / 2f) + lX) * isoPlotPointsPerAppUnit;
            centerY = (((hY - lY) / 2f) + lY) * isoPlotPointsPerAppUnit;

            // the first offset distance is the millWidth, after that we adjust by
            float incrementalDistance = (millWidth * overlapScaleFactor) * isoPlotPointsPerAppUnit;

            coLine = new GCodeCmd_Comment("... start ...");
            this.AddLine(coLine);

            // figure out the new corner coordinates - compensating for milling
            // bit diameter
            lXCutCoord = (lX + (millWidth / 2)) * isoPlotPointsPerAppUnit;
            lYCutCoord = (lY + (millWidth / 2)) * isoPlotPointsPerAppUnit;
            hXCutCoord = (hX - (millWidth / 2)) * isoPlotPointsPerAppUnit;
            hYCutCoord = (hY - (millWidth / 2)) * isoPlotPointsPerAppUnit;

            // G00 rapid move tool head to the destX,destY
            rmLine = new GCodeCmd_RapidMove((int)hXCutCoord, (int)hYCutCoord);
            this.AddLine(rmLine);

            // G01 - put the bit into the work piece
            zLine = new GCodeCmd_ZMove(GCodeCmd_ZMove.GCodeZMoveHeightEnum.GCodeZMoveHeight_ZCoordForCut);
            zLine.WantLinearMove = true;
            this.AddLine(zLine);

            // do the vertical down leg
            gcLine = new GCodeCmd_Line((int)hXCutCoord, (int)hYCutCoord, (int)hXCutCoord, (int)lYCutCoord);
            this.AddLine(gcLine);

            // do the low horizontal leg
            gcLine = new GCodeCmd_Line((int)hXCutCoord, (int)lYCutCoord, (int)lXCutCoord, (int)lYCutCoord);
            this.AddLine(gcLine);

            // do the vertical up leg
            gcLine = new GCodeCmd_Line((int)lXCutCoord, (int)lYCutCoord, (int)lXCutCoord, (int)hYCutCoord);
            this.AddLine(gcLine);

            // do the high horizontal leg
            gcLine = new GCodeCmd_Line((int)lXCutCoord, (int)hYCutCoord, (int)hXCutCoord, (int)hYCutCoord);
            this.AddLine(gcLine);
            lastXCoord = hXCutCoord;
            lastYCoord = hYCutCoord;

            // now do the rest of the pocket passes. This is encoded as a for loop
            // because I do not like endless loops. MAX_POCKETING_PASSES should be
            // pretty high so that it is not reached unless the finish tests fail
            for (i = 0; i < MAX_POCKETING_PASSES; i++)
            {
                // figure out the new corner coordinates - compensating for milling
                // bit diameter
                lXCutCoord = lXCutCoord + incrementalDistance;
                lYCutCoord = lYCutCoord + incrementalDistance;
                hXCutCoord = hXCutCoord - incrementalDistance;
                hYCutCoord = hYCutCoord - incrementalDistance;

                // perform tests
                if ((lXCutCoord >= centerX) || (lYCutCoord >= centerY) || (hXCutCoord <= centerX) || (hYCutCoord <= centerY))
                {
                    // we are on the last cut - just figure out which is the longer dimension
                    // and run a single cut down that
                    if ((lX - lY) > (hX - hY))
                    {
                        // we have to move to the new start position
                        gcLine = new GCodeCmd_Line((int)lastXCoord, (int)lastYCoord, (int)hXCutCoord, (int)lYCutCoord);
                        this.AddLine(gcLine);
                        // vertical is the longer dimension, hold X constant, run down Y
                        gcLine = new GCodeCmd_Line((int)hXCutCoord, (int)hYCutCoord, (int)hXCutCoord, (int)lYCutCoord);
                        this.AddLine(gcLine);
                        lastXCoord = hXCutCoord;
                        lastYCoord = hYCutCoord;
                    }
                    else
                    {
                        // we have to move to the new start position
                        gcLine = new GCodeCmd_Line((int)lastXCoord, (int)lastYCoord, (int)hXCutCoord, (int)hYCutCoord);
                        this.AddLine(gcLine);
                        // horizontal is the longer dimension, hold Y constant, run down X
                        gcLine = new GCodeCmd_Line((int)hXCutCoord, (int)hYCutCoord, (int)lXCutCoord, (int)hYCutCoord);
                        this.AddLine(gcLine);
                        lastXCoord = hXCutCoord;
                        lastYCoord = hYCutCoord;
                    }
                    // leave now
                    break;
                }

                coLine = new GCodeCmd_Comment("... pass ...");
                this.AddLine(coLine);

                // we have to move to the new start position
                gcLine = new GCodeCmd_Line((int)lastXCoord, (int)lastYCoord, (int)hXCutCoord, (int)hYCutCoord);
                this.AddLine(gcLine);

                // do the vertical down leg, this will also move it to (hXCutCoord, hYCutCoord)
                gcLine = new GCodeCmd_Line((int)hXCutCoord, (int)hYCutCoord, (int)hXCutCoord, (int)lYCutCoord);
                this.AddLine(gcLine);

                // do the low horizontal leg
                gcLine = new GCodeCmd_Line((int)hXCutCoord, (int)lYCutCoord, (int)lXCutCoord, (int)lYCutCoord);
                this.AddLine(gcLine);

                // do the vertical up leg
                gcLine = new GCodeCmd_Line((int)lXCutCoord, (int)lYCutCoord, (int)lXCutCoord, (int)hYCutCoord);
                this.AddLine(gcLine);

                // do the high horizontal leg
                gcLine = new GCodeCmd_Line((int)lXCutCoord, (int)hYCutCoord, (int)hXCutCoord, (int)hYCutCoord);
                this.AddLine(gcLine);
                lastXCoord = hXCutCoord;
                lastYCoord = hYCutCoord;
            }

            // one last test
            if (i >= MAX_POCKETING_PASSES)
            {
                LogMessage("GeneratePocketGCode: The the maximum number of pocketing passes was reached.");
                errStr = "The the maximum number of pocketing passes was reached. The gcode file is not correct. Please see the logs.";
                return(1036);
            }
            coLine = new GCodeCmd_Comment("... end ...");
            this.AddLine(coLine);

            return(0);
        }