コード例 #1
0
        private void CreateCircle(double x, double y, double radius)
        {
            if (radius < 0.000001)
            {
                return; // true black do nothing
            }

            if (radius * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            Command c = new G00Command();

            c.AddVariable('X', ToGCode(x + radius - StartLaserDist));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);
            LaserOn();
            c = new G01Command();
            c.AddVariable('X', ToGCode(x + radius));
            Commands.Add(c);

            c = new G03Command();
            c.AddVariable('I', ToGCode(-radius));
            Commands.Add(c);
        }
コード例 #2
0
ファイル: LoadImageHole.cs プロジェクト: rockxcn/CNCLib
        private void CreateHexagon(double x, double y, double radius)
        {
            if (radius < 0.000001)
            {
                return;                        // true black do nothing
            }
            if (radius * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            double rotateangel = Math.PI / 6.0;

            double startx = x + radius * Math.Cos(rotateangel);
            double starty = y + radius * Math.Sin(rotateangel);

            Command c = new G00Command();

            c.AddVariable('X', ToGCode(startx - StartLaserDist));
            c.AddVariable('Y', ToGCode(starty - StartLaserDist / 2));
            Commands.Add(c);
            LaserOn();

            //for (double rad = Math.PI / 3.0; rad < Math.PI * 2.0 + 0.1; rad += Math.PI / 3.0)
            for (double rad = 0; rad < Math.PI * 2.0 + 0.1; rad += Math.PI / 3.0)
            {
                double radrotated = rad + Math.PI / 6.0;
                c = new G01Command();
                c.AddVariable('X', ToGCode(x + radius * Math.Cos(radrotated)));
                c.AddVariable('Y', ToGCode(y + radius * Math.Sin(radrotated)));

                Commands.Add(c);
            }
        }
コード例 #3
0
        private void CreateToSmallShape(double x, double y)
        {
            Command cc = new G00Command();

            cc.AddVariable('X', ToGCode(x));
            cc.AddVariable('Y', ToGCode(y));
            Commands.Add(cc);
            LaserOn();
            cc = new G01Command();
            cc.AddVariable('X', ToGCode(x));
            cc.AddVariable('Y', ToGCode(y));
            Commands.Add(cc);
        }
コード例 #4
0
        private void CreateDiamond(double x, double y, double hsizeX2, double hsizeY2)
        {
            if (hsizeX2 < 0.000001)
            {
                return; // true black do nothing
            }

            if (hsizeX2 * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            Command c = new G00Command();

            c.AddVariable('X', ToGCode(x - hsizeX2 + StartLaserDist));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);
            LaserOn();

            c = new G01Command();
            c.AddVariable('X', ToGCode(x - hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y - hsizeY2));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x + hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + hsizeY2));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x - hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);
        }
コード例 #5
0
ファイル: LoadImage.cs プロジェクト: lulzzz/CNCLib
        private void AddCommandX(int x, int y, ref int lastY, bool laserOn)
        {
            // start laser a bit later but switch it off earlier
            double shift = laserOn ? _shiftLaserOff : _shiftLaserOn;

            if (y != lastY)
            {
                var    cy = new G00Command();
                double x1 = (x * PixelSizeX) + ShiftX + shift - (double)LoadOptions.LaserAccDist;

                cy.AddVariable('X', ToGCode(x1));
                cy.AddVariable('Y', ToGCode((SizeY - y - 1) * PixelSizeY + ShiftY));
                lastY = y;
                Commands.Add(cy);
            }

            Command cx;

            // if we have no laser on/off we switch with g01 and g00
            bool useG1 = HaveLaserOnOffCommand() || laserOn;

            if (useG1)
            {
                cx = new G01Command();
            }
            else
            {
                cx = new G00Command();
            }

            cx.AddVariable('X', ToGCode((x * PixelSizeX) + ShiftX + shift));

            if (!useG1)
            {
                cx.AddVariableNoValue('F');
            }

            Commands.Add(cx);
        }
コード例 #6
0
        private void LoadPenUp()
        {
            if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove)
            {
                var r = new G00Command();
                if (LoadOptions.EngravePosInParameter)
                {
                    r.AddVariableParam('Z', "1");
                }
                else
                {
                    r.AddVariable('Z', LoadOptions.EngravePosUp);
                }
                Commands.AddCommand(r);
            }
            else // if (LoadOptions.PenMoveType == LoadInfo.PenType.Command)
            {
                LaserOff();
            }

            FinishCamBamPLine();
        }
コード例 #7
0
        private bool Command(HpglCommand cmd)
        {
            bool isPenUp = true;

            if (cmd.IsPenCommand)
            {
                switch (cmd.CommandType)
                {
                case HpglCommand.HpglCommandType.PenDown:
                    isPenUp = false;
                    break;

                case HpglCommand.HpglCommandType.PenUp:
                    isPenUp = true;
                    break;
                }

                Point3D pt = Adjust(cmd.PointTo);

                if (isPenUp != _lastIsPenUp)
                {
                    if (isPenUp)
                    {
                        LoadPenUp();
                    }
                    else
                    {
                        LoadPenDown(Adjust(cmd.PointFrom));
                    }

                    _lastIsPenUp = isPenUp;
                }

                string  hpglCmd;
                Command r;
                if (isPenUp)
                {
                    r       = new G00Command();
                    hpglCmd = "PU";
                }
                else
                {
                    r = new G01Command();
                    AddCamBamPoint(pt);
                    hpglCmd = "PD";
                }

                r.AddVariable('X', pt.X0, false);
                r.AddVariable('Y', pt.Y0, false);
                if (_needSpeed)
                {
                    _needSpeed = false;
                    r.AddVariable('F', LoadOptions.MoveSpeed ?? 0);
                }

                Commands.AddCommand(r);

                r.ImportInfo = $"{hpglCmd}{(int)(pt.X0 * 40.0)},{(int)(pt.Y0 * 40.0)}";
            }
            else
            {
                var r = new GxxCommand();
                r.SetCode($";Hpgl={cmd.CommandString}");
                r.ImportInfo = cmd.CommandString;
                Commands.AddCommand(r);
            }

            return(true);
        }
コード例 #8
0
        private void CreateHeart(double x, double y, double hsizeX2, double hsizeY2, bool mirror)
        {
            if (hsizeX2 < 0.000001)
            {
                return; // true black do nothing
            }

            if (hsizeX2 * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            hsizeX2 *= 0.9;
            hsizeY2  = hsizeX2;
            double mr = mirror ? -1.0 : 1.0;

            Command c = new G00Command();

            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + (hsizeY2 - StartLaserDist) * mr));
            Commands.Add(c);
            LaserOn();

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + hsizeY2 * mr));
            Commands.Add(c);

            if (mirror)
            {
                c = new G03Command();
            }
            else
            {
                c = new G02Command();
            }

            c.AddVariable('X', ToGCode(x + hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            c.AddVariable('I', ToGCode(hsizeX2 / 2.0));
            c.AddVariable('J', ToGCode(-hsizeY2 / 2.0 * mr));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y - hsizeY2 * mr));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x - hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);

            if (mirror)
            {
                c = new G03Command();
            }
            else
            {
                c = new G02Command();
            }

            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + hsizeY2 * mr));
            c.AddVariable('I', ToGCode(hsizeX2 / 2.0));
            c.AddVariable('J', ToGCode(hsizeY2 / 2.0 * mr));
            Commands.Add(c);
        }