コード例 #1
0
        public static ushort startSearchHome(ref AxisInfo axisInfo)
        {
            ulong  axisStatus;
            ushort orignCount = 0;

            axisInfo.m_acc_time = 0.1;
            axisInfo.m_dcc_time = 0.1;
orign_begin:
            axisInfo.m_home_flag = 0;
            RFIDControl.dmc_set_home_pin_logic(axisInfo.m_card_num, axisInfo.m_axis_num, LOW, 0);                                                                                       //原点信号 低电平有效
            RFIDControl.dmc_set_pulse_outmode(axisInfo.m_card_num, axisInfo.m_axis_num, axisInfo.m_pulse_mode);                                                                         //设置脉冲输出模式
            RFIDControl.dmc_set_profile(axisInfo.m_card_num, axisInfo.m_axis_num, axisInfo.m_speed_min_home, axisInfo.m_speed_max_home, axisInfo.m_acc_time, axisInfo.m_dcc_time, 500); //设置速度曲线
            RFIDControl.dmc_set_homemode(axisInfo.m_card_num, axisInfo.m_axis_num, (ushort)axisInfo.m_home_dir, 1, (ushort)axisInfo.m_home_mode, 0);                                    //设置回零方式  反向回原点
            orignCount++;
            axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num);                                                                                      //读取轴的状态
            if (getStatus(axisStatus, (int)AxisStatus.MOTOR_ORG) != 0)                                                                                                                  //开始回原点时正在原点位置上
            {
                //		dmc_set_profile(m_axis->m_card_num,m_axis->m_axis_num,m_axis->m_speed_min_home,m_axis->m_speed_max_home,m_axis->m_acc_time,m_axis->m_dcc_time,500);//设置速度曲线
                RFIDControl.dmc_vmove(axisInfo.m_card_num, axisInfo.m_axis_num, (ushort)(axisInfo.m_home_dir == MoveDir.FOR_WORD ? MoveDir.BACK_WORD : MoveDir.FOR_WORD)); //反向运动
                delayTime(WAIT_TIMER);                                                                                                                                     //延时

                do
                {
                    axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num);//读取轴的状态
                    if (startGoHome == 0)
                    {
                        return(NO_ORG);
                    }
                } while (getStatus(axisStatus, (int)AxisStatus.MOTOR_ORG) != 0);//等到原点信号 变高
                RFIDControl.dmc_stop(axisInfo.m_card_num, axisInfo.m_axis_num, DIRECT_STOP);
            }

            if (getStatus(axisStatus, (int)AxisStatus.MOTOR_EL_B) != 0)                                                                                                    //开始时在负限位
            {
                RFIDControl.dmc_vmove(axisInfo.m_card_num, axisInfo.m_axis_num, (ushort)(axisInfo.m_home_dir == MoveDir.FOR_WORD ? MoveDir.BACK_WORD : MoveDir.FOR_WORD)); //反向运动
                delayTime(WAIT_TIMER);                                                                                                                                     //延时
                do
                {
                    axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num);//读取轴的状态
                    if (startGoHome == 0)
                    {
                        return(NO_ORG);
                    }
                } while (getStatus(axisStatus, (int)AxisStatus.MOTOR_ORG) == 0);//查询原点信号

                do
                {
                    axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num);//读取轴的状态
                    if (startGoHome == 0)
                    {
                        return(NO_ORG);
                    }
                } while (getStatus(axisStatus, (int)AxisStatus.MOTOR_ORG) != 0);//查询消失原点信号
                RFIDControl.dmc_stop(axisInfo.m_card_num, axisInfo.m_axis_num, DIRECT_STOP);
            }

            delayTime(100);                                                                     //延时

            RFIDControl.dmc_home_move(axisInfo.m_card_num, axisInfo.m_axis_num);                //回零动作
            delayTime(WAIT_TIMER);                                                              //延时
            while (RFIDControl.dmc_check_done(axisInfo.m_card_num, axisInfo.m_axis_num) == RUN) //判断当前轴状态
            {
                //遇到极限自动返回
                axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num); //读取轴的状态
                if (getStatus(axisStatus, (int)AxisStatus.MOTOR_EL_B) != 0)                            //负向极限
                {
                    RFIDControl.dmc_stop(axisInfo.m_card_num, axisInfo.m_axis_num, DIRECT_STOP);
                    delayTime(WAIT_TIMER);                                                                                                                                      //延时
                    RFIDControl.dmc_vmove(axisInfo.m_card_num, axisInfo.m_axis_num, (ushort)(axisInfo.m_home_dir == MoveDir.BACK_WORD ? MoveDir.FOR_WORD : MoveDir.BACK_WORD)); //反向运动

                    delayTime(WAIT_TIMER);                                                                                                                                      //延时
                    do
                    {
                        axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num);//读取轴的状态
                        if (startGoHome == 0)
                        {
                            return(NO_ORG);
                        }
                    } while (getStatus(axisStatus, (int)AxisStatus.MOTOR_ORG) == 0);//查询原点信号

                    do
                    {
                        axisStatus = RFIDControl.dmc_axis_io_status(axisInfo.m_card_num, axisInfo.m_axis_num);//读取轴的状态
                        if (startGoHome == 0)
                        {
                            return(NO_ORG);
                        }
                    } while (getStatus(axisStatus, (int)AxisStatus.MOTOR_ORG) != 0);     //查询消失原点信号
                    RFIDControl.dmc_stop(axisInfo.m_card_num, axisInfo.m_axis_num, DIRECT_STOP);
                    delayTime(100);                                                      //延时
                    RFIDControl.dmc_home_move(axisInfo.m_card_num, axisInfo.m_axis_num); //重新开始回零动作
                }
                if (getStatus(axisStatus, (int)AxisStatus.MOTOR_EL_F) != 0)              //负向极限
                {
                    if (orignCount < 3)
                    {
                        goto orign_begin;
                    }
                    RFIDControl.dmc_stop(axisInfo.m_card_num, axisInfo.m_axis_num, DIRECT_STOP);
                    return(NO_ORG);//没有原信号
                }
                if (startGoHome == 0)
                {
                    return(NO_ORG);
                }
            }
            if (startGoHome == 0)
            {
                return(NO_ORG);
            }
            delayTime(100);
            RFIDControl.dmc_set_position(axisInfo.m_card_num, axisInfo.m_axis_num, 0);         //设置零点
            axisInfo.m_home_flag = 1;


            //设定脉冲模式及逻辑方向(此处脉冲模式固定为P+D方向:脉冲+方向)
            RFIDControl.dmc_set_pulse_outmode(axisInfo.m_card_num, axisInfo.m_axis_num, axisInfo.m_pulse_mode);

            RFIDControl.dmc_set_profile(axisInfo.m_card_num, axisInfo.m_axis_num, axisInfo.m_speed_min, axisInfo.m_speed_max, axisInfo.m_acc_time, axisInfo.m_dcc_time, 0);
            //设定S段时间
            RFIDControl.dmc_set_s_profile(axisInfo.m_card_num, axisInfo.m_axis_num, 0, 0.4);


            RFIDControl.dmc_set_encoder(axisInfo.m_card_num, axisInfo.m_axis_num, 0);  //设置初始值为0
            RFIDControl.dmc_set_position(axisInfo.m_card_num, axisInfo.m_axis_num, 0); //初始位置设为零
            RFIDControl.dmc_set_equiv(axisInfo.m_card_num, axisInfo.m_axis_num, 1);
            axisInfo.m_pulse_mode = 3;
            axisInfo.m_home_flag  = 1;

            return(ORG_OK);
        }