Exemplo n.º 1
0
        /// <summary>
        /// Finds the minimum limit switches for all 3 Axes
        /// </summary>
        public void FindHome(int delayRapid, int delaySlow, bool findX, bool findY, bool findZ)
        {
            bool wasIgnoringLimits = IgnoreLimitSwitches;

            IgnoreLimitSwitches = false;

            AxisX.StepDirection = false;
            AxisY.StepDirection = false;
            AxisZ.StepDirection = false;

            bool xSeeking = findX;
            bool ySeeking = findY;
            bool zSeeking = findZ;

            // --- STEP 1 - Rapid to home (All minimum limit switches)
            while (xSeeking || ySeeking || zSeeking)
            {
                if (Program.EStopCondition)
                {
                    return;
                }

                xSeeking = xSeeking && AxisX.LimitReached != Axis.LimitSwitch.Min && AxisX.LimitReached != Axis.LimitSwitch.Unknown;
                ySeeking = ySeeking && AxisY.LimitReached != Axis.LimitSwitch.Min && AxisY.LimitReached != Axis.LimitSwitch.Unknown;
                zSeeking = zSeeking && AxisZ.LimitReached != Axis.LimitSwitch.Min && AxisZ.LimitReached != Axis.LimitSwitch.Unknown;

                if (xSeeking)
                {
                    AxisX.Step();
                }
                if (ySeeking)
                {
                    AxisY.Step();
                }
                if (zSeeking)
                {
                    AxisZ.Step();
                }

                DelayBy(delayRapid);
            }

            // --- STEP 2 - After a pause, slowly move each axis back off until the switches are opened
            AxisX.StepDirection = true;
            AxisY.StepDirection = true;
            AxisZ.StepDirection = true;

            xSeeking = findX;
            ySeeking = findY;
            zSeeking = findZ;

            Thread.Sleep(500);

            while (xSeeking || ySeeking || zSeeking)
            {
                if (Program.EStopCondition)
                {
                    return;
                }

                xSeeking = xSeeking && !AxisX.ResetLimitReached();
                ySeeking = ySeeking && !AxisY.ResetLimitReached();
                zSeeking = zSeeking && !AxisZ.ResetLimitReached();

                if (xSeeking)
                {
                    AxisX.Step();
                }
                if (ySeeking)
                {
                    AxisY.Step();
                }
                if (zSeeking)
                {
                    AxisZ.Step();
                }

                DelayBy(delaySlow);
            }

            IgnoreLimitSwitches = wasIgnoringLimits;
        }