예제 #1
0
        /// <summary>
        /// Calculate rought path.
        /// </summary>
        private void roughtPath(PathArgument pathArgument, MachineCommands mcs, CutDir cd)
        {
            // calc rough path
            double sign       = cd == CutDir.Top ? 1.0 : -1.0;
            double initZ      = 0.0;
            double targetY    = sign * ((cd == CutDir.Top ? pathArgument.UpSize : pathArgument.DownSize) - FINISH_TO_LEAVE) / 1000.0;
            double initX      = -0.500;
            double yStep      = sign * (pathArgument.RoughDia - STEP_OVER_Y) / 1000.0; // step to go
            double targetZ    = -(pathArgument.Deep - FINISH_TO_LEAVE) / 1000.0;
            int    xDirection = 0;                                                     // 0 to right 1 to left

            bool retractNeeded = false;

            // deep loop
            while (true)

            {
                if (initZ <= targetZ) // reach target
                {
                    break;
                }

                if (retractNeeded)
                {
                    mcs.Add(new RapidCommand {
                        Z = CLEARANCE_HEIGHT
                    });
                }

                // move to start pos
                mcs.Add(new RapidCommand {
                    X = initX, Y = sign * getRoughCompY(pathArgument)
                });

                initZ += (-STEP_OVER_Z / 1000.0);
                // boundary
                initZ = Math.Max(initZ, targetZ);

                mcs.Add(new FeedCommand {
                    F = 10.0, Z = initZ
                });

                // get abs y
                double initY = sign * getRoughCompY(pathArgument);

                // y loop
                while (true)
                {
                    double y = initY - (sign * getRoughCompY(pathArgument));
                    if (cd == CutDir.Bottom)
                    {
                        if (y <= targetY)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (y >= targetY)
                        {
                            break;
                        }
                    }

                    retractNeeded = true;

                    initY += yStep;
                    if (cd == CutDir.Bottom)
                    {
                        initY = Math.Max(initY - (sign * getRoughCompY(pathArgument)), targetY) + (sign * getRoughCompY(pathArgument));
                    }
                    else
                    {
                        initY = Math.Min(initY - (sign * getRoughCompY(pathArgument)), targetY) + (sign * getRoughCompY(pathArgument));
                    }

                    mcs.Add(new FeedCommand {
                        F = getRoughFeed(pathArgument), Y = initY
                    });

                    if (xDirection == 0)
                    {
                        initX     += pathArgument.CutLength / 1000.0;
                        xDirection = 1;
                    }

                    else
                    {
                        initX     -= pathArgument.CutLength / 1000.0;
                        xDirection = 0;
                    }

                    mcs.Add(new FeedCommand {
                        F = getRoughFeed(pathArgument), X = initX
                    });
                }
            }
        }
예제 #2
0
        private void finishPath(PathArgument pathArgument, MachineCommands mcs, CutDir cd)
        {
            // finish loop y first, if not last y goto deep z directly(cuz rough already cut)
            double sign       = cd == CutDir.Top ? 1.0 : -1.0;
            double initZ      = 0.0;
            double targetY    = sign * (cd == CutDir.Top ? pathArgument.UpSize : pathArgument.DownSize) / 1000.0;
            double initX      = -0.500;
            double yStep      = sign * (pathArgument.FinishDia - STEP_OVER_Y) / 1000.0; // step to go
            double targetZ    = -pathArgument.Deep / 1000.0;
            int    xDirection = 0;                                                      // 0 to right 1 to left

            // get abs y
            double initY = sign * getFinishCompY(pathArgument);

            // move to start pos
            mcs.Add(new RapidCommand {
                X = initX, Y = sign * getFinishCompY(pathArgument)
            });

            // y loop
            while (true)
            {
                double y = initY - (sign * getFinishCompY(pathArgument));
                if (cd == CutDir.Bottom)
                {
                    if (y <= targetY)
                    {
                        break;
                    }
                }
                else
                {
                    if (y >= targetY)
                    {
                        break;
                    }
                }

                initY += yStep;
                if (cd == CutDir.Bottom)
                {
                    initY = Math.Max(initY - (sign * getFinishCompY(pathArgument)), targetY) + (sign * getFinishCompY(pathArgument));
                }
                else
                {
                    initY = Math.Min(initY - (sign * getFinishCompY(pathArgument)), targetY) + (sign * getFinishCompY(pathArgument));
                }

                mcs.Add(new FeedCommand {
                    F = getFinishFeed(pathArgument), Y = initY
                });

                y = initY - (sign * getFinishCompY(pathArgument));
                if (y != targetY)   // not last Y
                {
                    // move to last Z
                    if (initZ != targetZ)
                    {
                        mcs.Add(new FeedCommand {
                            F = 10.0, Z = targetZ
                        });
                        initZ = targetZ;
                    }

                    if (xDirection == 0)
                    {
                        initX     += pathArgument.CutLength / 1000.0;
                        xDirection = 1;
                    }

                    else
                    {
                        initX     -= pathArgument.CutLength / 1000.0;
                        xDirection = 0;
                    }

                    mcs.Add(new FeedCommand {
                        F = getFinishFeed(pathArgument), X = initX
                    });
                }
                else
                {
                    initZ = 0.0; // cut from z = 0
                    mcs.Add(new RapidCommand {
                        Z = CLEARANCE_HEIGHT
                    });
                    while (true)
                    {
                        if (initZ <= targetZ) // reach target
                        {
                            break;
                        }

                        initZ += (-STEP_OVER_Z / 1000.0);
                        // boundary
                        initZ = Math.Max(initZ, targetZ);

                        mcs.Add(new FeedCommand {
                            F = 10.0, Z = initZ
                        });

                        if (xDirection == 0)
                        {
                            initX     += pathArgument.CutLength / 1000.0;
                            xDirection = 1;
                        }

                        else
                        {
                            initX     -= pathArgument.CutLength / 1000.0;
                            xDirection = 0;
                        }

                        mcs.Add(new FeedCommand {
                            F = getFinishFeed(pathArgument), X = initX
                        });
                    }
                }
            }
        }