Exemple #1
0
        /// <summary>
        /// 寻找原点 多次来回寻找,如果向负方向找到返回0,向正方向找到放回1
        /// </summary>
        /// <param name="axisC"></param>
        /// <returns></returns>
        public short MutHomeFindHomeSinge(AxisConfig axisC1, int count)
        {
            int stepPos = (int)axisC1.intFirstFindOriginDis;

            if (HomeFindHomeSinge(axisC1, stepPos) == 0)
            {
                if (stepPos < 0)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }

            if (WorkBase.IsRestExit())
            {
                return(-1);
            }

            if (HomeFindHomeSinge(axisC1, 0 - 2 * stepPos) == 0)
            {
                if (stepPos < 0)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            return(-1);
        }
Exemple #2
0
        /// <summary>
        /// 寻找原点,一次寻找pos1 ,
        /// </summary>
        /// <param name="axisC"></param>
        /// <returns></returns>
        public short HomeFindHomeSinge(AxisConfig axisC, int pos1)
        {
            short       shrResult = 0;
            bool        pIo       = false;
            int         AxisState = 0;
            PointModule point     = new PointModule(true, false, 0, axisC.Speed, axisC.Acc, axisC.Dec, axisC.tag_accTime, axisC.tag_delTime, axisC.StartSpeed, axisC.tag_S_Time, axisC.tag_StopSpeed);

            point.dblPonitValue = pos1;
            shrResult           = SR_RelativeMove(axisC, point);
            if (shrResult != 0)
            {
                return(-1);
            }
            Thread.Sleep(10);
            while (true)
            {
                if (WorkBase.IsRestExit())
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-1);
                }

                SR_GetOriginInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);                         //采集原点信号

                if (!axisC.tag_homeIoHighLow)                                                              //如果信号位高电平
                {
                    if (!pIo)
                    {
                        SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));                                      //停止轴
                        return(0);
                    }
                }
                else
                {
                    if (pIo)
                    {
                        SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                        return(0);
                    }
                }

                if (SR_GetAxisStatus(axisC.CardNum, (short)(axisC.AxisNum), out AxisState) != 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-2);
                }
                if (AxisState == 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-3);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 运行第二段距离
        /// </summary>
        /// <param name="axisC"></param>
        /// <returns></returns>
        public short HomeMoveTwoDis(AxisConfig axisC)
        {
            short       shrResult = 0;
            int         AxisState = 0;
            PointModule point     = new PointModule(true, false, 0, axisC.Speed, axisC.Acc, axisC.Dec, axisC.tag_accTime, axisC.tag_delTime, axisC.StartSpeed, axisC.tag_S_Time, axisC.tag_StopSpeed);

            point.dblPonitValue = axisC.intSecondFindOriginDis;
            if (axisC.HomeDir == 0)
            {
                point.dblPonitValue = 0 - point.dblPonitValue;
            }

            shrResult = SR_RelativeMove(axisC, point);             //单轴的相对运动
            if (shrResult != 0)
            {
                return(-1);
            }
            if (point.dblPonitValue == 0)
            {
                return(-1);
            }
            Thread.Sleep(10);

            while (true)
            {
                if (WorkBase.IsRestExit())
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-1);
                }

                if (SR_GetAxisStatus(axisC.CardNum, (short)(axisC.AxisNum), out AxisState) != 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(1);
                }
                if (AxisState == 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(0);
                }
            }
        }
Exemple #4
0
        public short SR_GoHome(AxisConfig _acf)
        {
            if (HomeFindLimit(_acf) == 0)
            {
                if (WorkBase.IsRestExit())
                {
                    return(-1);
                }

                Thread.Sleep(1000);
                if (HomeMoveTwoDis(_acf) == 0)
                {
                    if (WorkBase.IsRestExit())
                    {
                        return(-1);
                    }

                    return(HomeFindHomeIO(_acf));
                }
            }
            return(-5);
        }
Exemple #5
0
        //
        /// <summary>
        /// 单原点回原,如果第一次找不到原点即失败,第一段距离位寻找距离,第二段距离为反退距离。,第三段距离为反退距离+感应器的长度
        /// </summary>
        /// <param name="_acf"></param>
        /// <returns></returns>
        public short SR_GoOneHome(AxisConfig _acf)
        {
            short ret = MutHomeFindHomeSinge(_acf, 16);

            if (ret >= 0)
            {
                if (WorkBase.IsRestExit())
                {
                    return(-1);
                }
                Thread.Sleep(1000);
                if (HomeMoveTwoDis(_acf) == 0)
                {
                    if (WorkBase.IsRestExit())
                    {
                        return(-1);
                    }
                    Thread.Sleep(1000);
                    return(HomeFindOneHomeIO(_acf));
                }
            }
            return(-5);
        }
Exemple #6
0
        public short HomeFindOneHomeIO(AxisConfig axisC)
        {
            short       shrResult = 0;
            bool        pIo       = false;
            int         AxisState = 0;
            PointModule point     = new PointModule(true, false, 0, axisC.HomeSpeed, axisC.Acc, axisC.Dec, axisC.tag_accTime, axisC.tag_delTime, axisC.StartSpeed, axisC.tag_S_Time, axisC.tag_StopSpeed);

            point.dblPonitValue = axisC.intThreeFindOriginDis;

            shrResult = SR_RelativeMove(axisC, point);
            if (shrResult != 0)
            {
                return(-1);
            }

            while (true)
            {
                if (WorkBase.IsRestExit())
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-1);
                }
                SR_GetOriginInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);
                if (axisC.tag_homeIoHighLow)
                {
                    if (pIo)
                    {
                        SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                        shrResult = 0;
                        break;
                    }
                }
                else
                {
                    if (!pIo)
                    {
                        SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                        shrResult = 0;
                        break;
                    }
                }
                if (SR_GetAxisStatus(axisC.CardNum, (short)(axisC.AxisNum), out AxisState) != 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(1);
                }
                if (AxisState == 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(3);
                }
                Thread.Sleep(1);
            }

            SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
            Thread.Sleep(1000);
            int countzeor = 30;

            while (countzeor >= 0)
            {
                if (WorkBase.IsRestExit())
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-1);
                }
                int   status = 0;
                short r      = SR_GetAxisStatus(axisC.CardNum, (short)(axisC.AxisNum), out status);
                if (r != 0)
                {
                    return(-1);
                }
                if (status == 0)
                {
                    break;
                }
            }

            while (countzeor >= 0)
            {
                double pos = 0;
                double Enc = 0;

                Thread.Sleep(1000);

                SR_GetPrfPos(axisC.CardNum, (short)(axisC.AxisNum), ref pos);
                SR_GetEncPos(axisC.CardNum, (short)(axisC.AxisNum), ref Enc);
                SR_SetPrfPos(axisC.CardNum, (short)(axisC.AxisNum), 0);
                SR_SetEncPos(axisC.CardNum, (short)(axisC.AxisNum), 0);
                SR_GetPrfPos(axisC.CardNum, (short)(axisC.AxisNum), ref pos);
                SR_GetEncPos(axisC.CardNum, (short)(axisC.AxisNum), ref Enc);

                if (pos < 5 && pos > -5 && Enc < 5 && Enc > -5)
                {
                    return(0);
                }

                countzeor--;
                Thread.Sleep(10);
            }
            if (countzeor >= 0)
            {
                return(0);
            }

            return(-1);
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="axisC"></param>
        /// <returns></returns>
        public short HomeFindLimit(AxisConfig axisC)
        {
            short       shrResult = 0;
            bool        pIo       = false;
            int         AxisState = 0;
            PointModule point     = new PointModule(true, false, 0, axisC.Speed, axisC.Acc, axisC.Dec, axisC.tag_accTime, axisC.tag_delTime, axisC.StartSpeed, axisC.tag_S_Time, axisC.tag_StopSpeed);

            if (axisC.HomeDir == 1)                                    //回零方向,默认为0
            {
                point.dblPonitValue = 0 - axisC.intFirstFindOriginDis; //第一次找原点距离
            }
            else
            {
                point.dblPonitValue = axisC.intFirstFindOriginDis;
            }

            if (axisC.HomeDir == 0)
            {
                SR_GetLimitPInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);                 //获取正限输入状态
            }
            else
            {
                SR_GetLimitNInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);                //获取负限输入状态
            }

            if (axisC.tag_IoLimtPNHighEnable == 0)             //正负限位高电平有效
            {
                if (!pIo)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(0);
                }
            }
            else
            {
                if (pIo)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(0);
                }
            }

            shrResult = SR_RelativeMove(axisC, point);             //单轴的相对运动

            if (shrResult != 0)
            {
                CommandResult("_SR_AbsoluteMove", shrResult);
                return(-1);
            }
            Thread.Sleep(10);

            while (true)
            {
                if (WorkBase.IsRestExit())
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(-1);
                }

                if (axisC.HomeDir == 0)
                {
                    SR_GetLimitPInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);
                }

                else
                {
                    SR_GetLimitNInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);
                }
                if (axisC.tag_IoLimtPNHighEnable == 0)
                {
                    if (!pIo)
                    {
                        SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                        return(0);
                    }
                }
                else
                {
                    if (pIo)
                    {
                        SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                        return(0);
                    }
                }

                if (SR_GetAxisStatus(axisC.CardNum, (short)(axisC.AxisNum), out AxisState) != 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    return(1);
                }
                if (AxisState == 0)
                {
                    SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                    if (axisC.HomeDir == 0)
                    {
                        SR_GetLimitPInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);
                    }

                    else
                    {
                        SR_GetLimitNInput(axisC.CardNum, (short)(axisC.AxisNum), out pIo);
                    }
                    if (axisC.tag_IoLimtPNHighEnable == 0)
                    {
                        if (!pIo)
                        {
                            SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                            return(0);
                        }
                    }
                    else
                    {
                        if (pIo)
                        {
                            SR_AxisEmgStop(axisC.CardNum, (short)(axisC.AxisNum));
                            return(0);
                        }
                    }
                    return(3);
                }
            }
        }