Exemple #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Generates the gcode for a pad touchdown or drill
        /// </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="x0">x coord</param>
        /// <param name="y0">y coord</param>
        /// <param name="cutLevel">the cut level we drill to</param>
        /// <param name="drillDwellTime">drill dwell time at bottom of hole</param>
        /// <param name="drillWidth">the drill width. This is mostly used for plotting</param>
        /// <param name="errStr">the error string</param>
        public int AddPadTouchDownOrDrillLine(int x0, int y0, GCodeCmd_ZMove.GCodeZMoveHeightEnum cutLevel, float drillWidth, float drillDwellTime, ref string errStr)
        {
            GCodeCmd_ZMove     zLine  = null;
            GCodeCmd_RapidMove rmLine = null;
            GCodeCmd_Dwell     dwLine = null;

            errStr = "";

            // test these
            if ((x0 == int.MaxValue) ||
                (y0 == int.MaxValue) ||
                (x0 == int.MinValue) ||
                (y0 == int.MinValue))
            {
                LogMessage("AddDrillCodeLines: One or more of the x0,y0 coordinates are invalid.");
                errStr = "The X and Y coordinates of the drill target are invalid.";
                return(1024);
            }

            if (StateMachine.CurrentZFeedrate <= 0)
            {
                LogMessage("AddDrillCodeLines: The zFeedRate is invalid.");
                errStr = "The zFeedRate is invalid.";
                return(1029);
            }
            if (StateMachine.CurrentXYFeedrate <= 0)
            {
                LogMessage("AddDrillCodeLines: The xyFeedRate is invalid.");
                errStr = "The xyFeedRate is invalid.";
                return(1030);
            }

            // we do not display a non sensible value here
            if (drillWidth <= 0)
            {
                drillWidth = 0.125f;
            }

            // G00 rapid move tool head to the x0, y0
            rmLine = new GCodeCmd_RapidMove(x0, y0);
            this.AddLine(rmLine);

            // G00 - put the bit into the work piece
            zLine = new GCodeCmd_ZMove(cutLevel);
            zLine.SetGCodePlotDrillValues(x0, y0, drillWidth);
            zLine.WantLinearMove = true;
            this.AddLine(zLine);

            // dwell at the bottom
            dwLine = new GCodeCmd_Dwell(drillDwellTime);
            this.AddLine(dwLine);

            // G00 - pull the bit out of the work piece
            zLine = new GCodeCmd_ZMove(GCodeCmd_ZMove.GCodeZMoveHeightEnum.GCodeZMoveHeight_ZCoordForClear);
            zLine.SetGCodePlotDrillValues(x0, y0, drillWidth);
            this.AddLine(zLine);
            return(0);
        }
Exemple #2
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)
        {
            gcLineList = null;
            GCodeCmd_ZMove     zLine  = null;
            GCodeCmd_RapidMove rmLine = null;

            gcLineList = new List <GCodeCmd>();
            int workingXCoord;
            int workingYCoord;
            int workingXOffset;
            int workingYOffset;

            if (RepeatCount < 0)
            {
                LogMessage("GetGCodeCmd (R) invalid repeat count of " + RepeatCount.ToString() + " on line " + LineNumber.ToString());
                return(101);
            }

            // setup our offsets now
            workingXOffset = GetOffsetInPlotCoords_X(stateMachine);
            workingYOffset = GetOffsetInPlotCoords_Y(stateMachine);

            // now put out our loop
            for (int i = 0; i < RepeatCount; i++)
            {
                workingXCoord = stateMachine.LastPlotXCoord;
                workingYCoord = stateMachine.LastPlotYCoord;

                // calculate the new coordinate now
                workingXCoord += workingXOffset;
                workingYCoord += workingYOffset;

                // G00 rapid move tool head to the xOffset, yCoord
                rmLine = new GCodeCmd_RapidMove(workingXCoord, workingYCoord);
                gcLineList.Add(rmLine);
                stateMachine.LastXCoord = workingXCoord;
                stateMachine.LastYCoord = workingYCoord;

                // set the drill width
                float workingDrillWidth = stateMachine.LastDrillWidth * stateMachine.IsoPlotPointsPerAppUnit;

                // G00 - put the bit into the work piece
                zLine = new GCodeCmd_ZMove(GCodeCmd_ZMove.GCodeZMoveHeightEnum.GCodeZMoveHeight_ZCoordForCut);
                zLine.SetGCodePlotDrillValues(workingXCoord, workingYCoord, workingDrillWidth);
                gcLineList.Add(zLine);

                // G00 - pull the bit out of the work piece
                zLine = new GCodeCmd_ZMove(GCodeCmd_ZMove.GCodeZMoveHeightEnum.GCodeZMoveHeight_ZCoordForClear);
                zLine.SetGCodePlotDrillValues(workingXCoord, workingYCoord, workingDrillWidth);
                gcLineList.Add(zLine);
            }
            return(0);
        }
Exemple #3
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)
        {
            gcLineList = null;

            GCodeCmd_ZMove     zLine  = null;
            GCodeCmd_RapidMove rmLine = null;

            gcLineList = new List <GCodeCmd>();

            int x0 = GetIsoPlotCoordOriginCompensated_X(stateMachine);
            int y0 = GetIsoPlotCoordOriginCompensated_Y(stateMachine);

            // G00 rapid move tool head to the xCoord, yCoord
            rmLine = new GCodeCmd_RapidMove(x0, y0);
            gcLineList.Add(rmLine);
            stateMachine.LastXCoord     = XCoord;
            stateMachine.LastYCoord     = YCoord;
            stateMachine.LastPlotXCoord = x0;
            stateMachine.LastPlotYCoord = y0;
            // record locally
            lastPlotXCoordEnd = x0;
            lastPlotYCoordEnd = y0;

            // set the drill width
            float workingDrillWidth = stateMachine.LastDrillWidth * stateMachine.IsoPlotPointsPerAppUnit;

            // remember this
            LastDrillWidth = stateMachine.LastDrillWidth;

            // G00 - put the bit into the work piece
            zLine = new GCodeCmd_ZMove(GCodeCmd_ZMove.GCodeZMoveHeightEnum.GCodeZMoveHeight_ZCoordForCut);
            zLine.SetGCodePlotDrillValues(x0, y0, workingDrillWidth);
            zLine.WantLinearMove = true;
            gcLineList.Add(zLine);

            // G00 - pull the bit out of the work piece
            zLine = new GCodeCmd_ZMove(GCodeCmd_ZMove.GCodeZMoveHeightEnum.GCodeZMoveHeight_ZCoordForClear);
            zLine.SetGCodePlotDrillValues(x0, y0, workingDrillWidth);
            gcLineList.Add(zLine);

            return(0);
        }
Exemple #4
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);
        }