Ejemplo n.º 1
0
        /// <summary>
        ///     清除轴状态
        /// </summary>
        /// <param name="nCardNum"></param>
        /// <param name="nAxis">轴号</param>
        /// <param name="count">数量</param>
        /// <returns></returns>
        public override short ClrSts(short nCardNum, short nAxis, short count)
        {
            short nRtn = 0;

            nRtn |= CMc.GT_ClrSts(nCardNum, nAxis, count); // 清除指定轴的报警和限位

            return(nRtn);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     绝对坐标走位
        /// </summary>
        /// <param name="nCardNum"></param>
        /// <param name="nAxis">轴号</param>
        /// <param name="dPos">位置,脉冲为单位</param>
        /// <param name="dVel">速度</param>
        /// <param name="dAcce">加减速度</param>
        /// <returns></returns>
        public override short AbsMove(short nCardNum, short nAxis, int dPos, double dVel, double dAcce)
        {
            short nRtn = 0;

            if (nAxis > m_maxAxisNum)
            {
                return(-1);
            }

            //lock (m_lockMove)
            int sts;

            //获取标志位状态
            nRtn |= CMc.GT_GetSts(nCardNum, nAxis, out sts, 1, out m_oClk);


            if ((sts & 0x400) == 0) //该轴必须静止
            {
                //设定Trap运动模式,失败则返回

                int mode;
                nRtn |= CMc.GT_GetPrfMode(nCardNum, nAxis, out mode, 1, out m_oClk);


                if (mode != 0)
                {
                    nRtn |= CMc.GT_ClrSts(nCardNum, nAxis, 1);

                    nRtn |= CMc.GT_PrfTrap(nCardNum, nAxis);
                }
            }

            //设定Trap运动参数

            CMc.TRAP_PRM trap;
            trap.m_acc        = dAcce;
            trap.m_dec        = dAcce;
            trap.m_velStart   = 0;
            trap.m_smoothTime = 10;
            nRtn |= CMc.GT_SetTrapPrm(nCardNum, nAxis, ref trap);


            //开始运动

            nRtn |= CMc.GT_SetPos(nCardNum, nAxis, dPos);

            nRtn |= CMc.GT_SetVel(nCardNum, nAxis, dVel);

            nRtn |= CMc.GT_Update(nCardNum, 1 << (nAxis - 1));

            return(nRtn);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     JOG移动
        /// </summary>
        /// <param name="nCardNum"></param>
        /// <param name="nAxis">轴号</param>
        /// <param name="dVel"></param>
        /// <param name="dAcce"></param>
        /// <returns></returns>
        public override short JogMove(short nCardNum, short nAxis, double dVel, double dAcce)
        {
            short nRtn = 0;

            if (nCardNum < 0 || nAxis > m_maxAxisNum)
            {
                return(-1);
            }

            //获取标志位状态

            nRtn |= CMc.GT_ClrSts(nCardNum, 1, m_maxAxisNum);


            int sts;

            nRtn |= CMc.GT_GetSts(nCardNum, nAxis, out sts, 1, out m_oClk);

            int mode;

            nRtn |= CMc.GT_GetPrfMode(nCardNum, nAxis, out mode, 1,
                                      out m_oClk); //mode值  //0:trap 1:Jog 2:S 3:PT 4:PVS 5:interpolation 6:gear


            if ((sts & 0x400) != 0) //运动情况下可以改变速度和加速度
            {
                if (1 != mode)
                {
                    return(nRtn);
                }
            }
            else //静止情况下才能修改运动模式
            {
                if (1 != mode)
                {
                    nRtn |= CMc.GT_PrfJog(nCardNum, nAxis);
                }
            }

            //设置Jog运动参数
            CMc.JOG_PRM jogPrm;
            jogPrm.m_acc    = dAcce; //加速度,单位“脉冲/毫秒2”
            jogPrm.m_dec    = dAcce; //减速度,单位“脉冲/毫秒2”
            jogPrm.m_smooth = 0.625; //平滑系数,取值范围[0,1]
            nRtn           |= CMc.GT_SetJogPrm(nCardNum, nAxis, ref jogPrm);

            //启动运动
            nRtn |= CMc.GT_SetVel(nCardNum, nAxis, dVel); //设置目标速度,单位是“脉冲/毫秒”
            nRtn |= CMc.GT_Update(nCardNum, 1 << (nAxis - 1));
            return(nRtn);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     初始化轴
        /// </summary>
        /// <param name="nCardNum"></param>
        /// <param name="nAxisNum">轴数</param>
        protected override short InitAxis(short nCardNum, short nAxisNum)
        {
            short nRtn = 0;

            for (short i = 1; i <= nAxisNum; i++)
            {
                nRtn |= CMc.GT_ZeroPos(nCardNum, i, 1);       //马达位置清零,原点回归完成时也用该指令来置零
                nRtn |= CMc.GT_SetPrfPos(nCardNum, i, 0);     //轴规划位置清零
                Thread.Sleep(200);                            //等待伺服稳定
                nRtn |= CMc.GT_ClrSts(nCardNum, i, nAxisNum); //清楚轴状态
                nRtn |= CMc.GT_AxisOn(nCardNum, i);           //马达伺服使能
            }

            return(nRtn);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     初始化运动卡
        /// </summary>
        /// <param name="nCardNum">卡号</param>
        /// <param name="nAxisNum">轴数</param>
        /// <param name="pFile">配置文件</param>
        /// <returns></returns>
        public override short InitMotionCard(short nCardNum, short nAxisNum, string pFile)
        {
            short nRtn = 0;

            nRtn |= CMc.GT_Open(nCardNum, 0, 1); //打开运动控制器设备

            if (nRtn != 0)
            {
                MessageBox.Show(@"打开运动卡失败,可能原因:1.运动卡没有插好;2.有其他的程序正在对运动卡操作", @"提示", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return(nRtn);
            }

            if (File.Exists("gts.dll") && File.Exists("ExtMdl.cfg"))
            {
                nRtn |= CMc.GT_OpenExtMdl(nCardNum, "gts.dll");
                nRtn |= CMc.GT_LoadExtConfig(nCardNum, "ExtMdl.cfg");
            }
            else
            {
                MessageBox.Show(@"扩展模块加载失败,请检查文件是否存在", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            nRtn |= CMc.GT_Reset(nCardNum); //复位运动控制器


            nRtn |= CMc.GT_LoadConfig(nCardNum, pFile); //加载配置文件


            if (nRtn == 0)
            {
                m_maxAxisNum = nAxisNum;
                nRtn         = CMc.GT_ClrSts(nCardNum, 1, m_maxAxisNum);
                InitAxis(nCardNum, m_maxAxisNum);
            }

            return(nRtn);
        }