Exemplo n.º 1
0
        public Axis(AxisID id, AxisPulseOutMode axisPulseOutMode, double pulseOfMilMeter, long maxRouteDistance, long logicOrgPosition, AxisINPSIG inpsig)
        {
            _axisId             = Convert.ToUInt16(id);
            _pulseOfPerMilMeter = pulseOfMilMeter;
            _maxRouteDistance   = (long)(maxRouteDistance * PulseOfPerMilMeter);
            _logicOrgPosition   = (int)(logicOrgPosition * PulseOfPerMilMeter);
            _axisPulseOutMode   = Convert.ToUInt16(axisPulseOutMode);

            //轴脉冲输出模式
            Dmc2610.d2610_set_pulse_outmode(_axisId, Convert.ToUInt16(AxisPulseOutMode));
            //ALM信号定义: 低电平有效,触发后立即停止
            Dmc2610.d2610_config_ALM_PIN(_axisId, Convert.ToUInt16(AxisALMLogic.HighLevelVaild),
                                         Convert.ToUInt16(AxisALMAction.ImmediatelyStop));
            //INP信号低电平有效, 发送完成指令脉冲后立即置check_done 完成,无需等待,否则需得到INP为低电平才置位check_done
            if (_axisPulseOutMode < 4)
            {
                Dmc2610.d2610_config_INP_PIN(_axisId, Convert.ToUInt16(AxisINPSIG.Enable), Convert.ToUInt16(AxisINPLogic.LowLevelVaild));
            }
            else
            {
                Dmc2610.d2610_config_INP_PIN(_axisId, Convert.ToUInt16(AxisINPSIG.Enable), Convert.ToUInt16(AxisINPLogic.HighLevelVaild));
            }


            //Emergy Stop 信号定义 0为1号卡  1允许,1 高电平有效
            Dmc2610.d2610_config_EMG_PIN(0, 1, 0);

            //编码器计数方式为: AB相 EA单路信号4倍。(无卡时,初始化这一项会出现内存存储违规,故暂时取消掉)
            Dmc2610.d2610_counter_config(_axisId, Convert.ToUInt16(EnCoderCountMode.ABPhased4xEA));
            //Dmc2610.d2610_set_encoder(_axisId, 0);


            //设置Home PIN的回原点以及滤波器开关。(无卡时,初始化这一项会出现内存存储违规,故暂时取消掉)
            Dmc2610.d2610_set_HOME_pin_logic(AxisId, Convert.ToUInt16(AxisHOMEOrgLogic.LowLevelVaild), Convert.ToUInt16(AxisHOMEUseFilter.Enable));
            Dmc2610.d2610_config_home_mode(AxisId, Convert.ToUInt16(AxisHomeMode.HomeCountOnly), Convert.ToUInt16(0));
        }
Exemplo n.º 2
0
        private void btnLoadAxisPara_Click(object sender, EventArgs e)
        {
            // DMC2610卡的函数调用

            nCard = Dmc2610.d2610_board_init(); //'为控制卡分配系统资源,并初始化控制卡。
            if (nCard <= 0)                     //DMC1000控制卡初始化
            {
                MessageBox.Show("未找到DMC2610控制卡!", "警告");
                return;//退出当前程序
            }

            string connectionString = @"Data Source=.\AOI;Initial Catalog=aoi5sys;Integrated Security=True";

            SqlConnection connection = new SqlConnection(connectionString);
            //string sql=@"SELECT * FROM AXIS_PARAM WHERE NAME='#1HOST'";
            string sql = @"SELECT [NAME]
      ,[AXIS]
      ,[AXIS_ID]
      ,[PULSE_MODE]
      ,[MAX_DIST]
      ,[ORG_POSITION]
      ,[RESET_SPEED]
      ,[START_SPEED]
      ,[MAX_SPEED]
      ,[ADD_SPEED]
      ,[ADD_MODE]
      ,[PULSE_PER_MM]
  FROM [aoi5sys].[dbo].[AXIS_PARAM]
  WHERE	NAME='#1HOST'";

            try
            {
                connection.Open();

                SqlCommand cmd = new SqlCommand(sql, connection);

                SqlDataReader dataReader = cmd.ExecuteReader();


                AxisGroup = new List <Axis>();

                while (dataReader.Read())
                {
                    string           tempstr  = dataReader.GetValue(1).ToString();
                    AxisPulseOutMode PoutMode = dataReader.GetInt32(3) == 0
                              ? AxisPulseOutMode.PM_PLDL
                              : AxisPulseOutMode.PM_PHDHPHDH;
                    double     pulseOfMilMeter   = Convert.ToDouble(dataReader.GetValue(11).ToString());
                    long       maxRouterDistance = Convert.ToInt64(dataReader.GetValue(4));
                    long       logicOrgPosition  = Convert.ToInt64(dataReader.GetValue(5));
                    AxisINPSIG axisInpsig        = AxisINPSIG.Enable;

                    double ResetVelocity = Convert.ToDouble(dataReader.GetValue(6));
                    double startVelocity = Convert.ToDouble(dataReader.GetValue(7));
                    double maxVelocity   = Convert.ToDouble(dataReader.GetValue(8));
                    double accVelocity   = Convert.ToDouble(dataReader.GetValue(9));
                    double decVelocity   = Convert.ToDouble(dataReader.GetValue(9));
                    float  scale         = (float)0.75;

                    if (tempstr.Contains("X_"))
                    {
                        this.XAxis = new Axis(AxisID.XAxis, PoutMode, pulseOfMilMeter, maxRouterDistance, logicOrgPosition, axisInpsig);
                        XAxis.AxisSetResetMoveParameters(ResetVelocity / 2, ResetVelocity, ResetVelocity / 2, ResetVelocity / 2);
                        XAxis.AxisSetTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity);
                        XAxis.AxisSetSPMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        XAxis.AxisSetSTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        // XAxis.AxisSetVectorMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, (float)0.6);
                        AxisGroup.Add(XAxis);
                    }
                    if (tempstr.Contains("Y_"))
                    {
                        this.YAxis = new Axis(AxisID.YAxis, PoutMode, pulseOfMilMeter, maxRouterDistance, logicOrgPosition, axisInpsig);
                        YAxis.AxisSetResetMoveParameters(ResetVelocity / 2, ResetVelocity, ResetVelocity / 2, ResetVelocity / 2);
                        YAxis.AxisSetTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity);
                        YAxis.AxisSetSPMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        YAxis.AxisSetSTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        // YAxis.AxisSetVectorMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, (float)0.6);
                        AxisGroup.Add(YAxis);
                    }
                    if (tempstr.Contains("C_"))
                    {
                        this.CAxis = new Axis(AxisID.ZAxis, PoutMode, pulseOfMilMeter, maxRouterDistance, logicOrgPosition, axisInpsig);
                        CAxis.AxisSetResetMoveParameters(ResetVelocity / 2, ResetVelocity, ResetVelocity / 2, ResetVelocity / 2);
                        CAxis.AxisSetTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity);
                        CAxis.AxisSetSPMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        CAxis.AxisSetSTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        //CAxis.AxisSetVectorMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, (float)0.6);
                        AxisGroup.Add(CAxis);
                    }
                    if (tempstr.Contains("L_"))
                    {
                        this.LAxis = new Axis(AxisID.UAxis, PoutMode, pulseOfMilMeter, maxRouterDistance, logicOrgPosition, axisInpsig);
                        LAxis.AxisSetResetMoveParameters(ResetVelocity / 2, ResetVelocity, ResetVelocity / 2, ResetVelocity / 2);
                        LAxis.AxisSetTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity);
                        LAxis.AxisSetSPMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        LAxis.AxisSetSTMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, scale);
                        // LAxis.AxisSetVectorMoveParameters(startVelocity, maxVelocity, accVelocity, decVelocity, (float)0.6);
                        AxisGroup.Add(LAxis);
                    }
                }
                timer1.Enabled = true;
            }
            catch (DataException dataException)
            {
                MessageBox.Show(dataException.ToString());
            }
            finally
            {
                connection.Close();
                this.btnLoadAxisPara.Enabled = false;
            }

            for (int i = 0; i < 2; i++)
            {
                InputinitStatus[i] = Motion2610Control.ReadInputKey((ushort)(i + 1));
                InputiskeyDown[i]  = InputinitStatus[i];
            }
        }