Exemplo n.º 1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (cbxMotionTrail.SelectedItem == null)
            {
                MessageBox.Show("请选择轨迹");
                return;
            }
            ushort _CardID = 0;
            ushort AxisX   = 0;
            ushort AxisY   = 1;
            ushort crd     = 0;

            //设置脉冲当量
            LTDMC.dmc_set_equiv(0, AxisX, FormMain.PulseEquiv);
            LTDMC.dmc_set_equiv(0, AxisY, FormMain.PulseEquiv);
            //   画图
            ushort axisnum = 2;

            ushort[] axises = new ushort[] { AxisX, AxisY };
            LTDMC.dmc_conti_open_list(0, crd, axisnum, axises);

            // LTDMC.dmc_conti_set_blend(0, crd, 1);
            if (cbxMotionTrail.SelectedIndex == 0)
            {
                double[] A = new double[] { 0, 0 };
                double[] B = new double[] { 200, 0 };
                double[] C = new double[] { 400, -200 };
                double[] D = new double[] { 400, -400 };
                //设置插补速度
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, B, 1, 0);  //直线插补,绝对模式
                //设置插补速度
                SetArcVecter();
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     C, new double[] { 200, -200 }, 0, 0, 1, 0);
                //XY平面圆弧插补,顺时针,相对坐标模式。   此函数是基于圆心圆弧扩展的螺旋线插补运动(可作两轴圆弧插补)
                //终点坐标   圆心坐标
                //设置插补速度
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          D, 1, 0); //直线插补,绝对模式

                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          A, 1, 0); //直线插补,绝对模式

                LTDMC.dmc_conti_start_list(_CardID, crd);
                Thread.Sleep(1000);
                LTDMC.dmc_conti_close_list(_CardID, crd);
            }
            if (cbxMotionTrail.SelectedIndex == 1)
            {
                //LTDMC.dmc_pmove_unit(0, 0, 100, 1);//定长运动
                //LTDMC.dmc_check_done(0, 0);
                double[] A = new double[] { 100, 0 };
                double[] B = new double[] { 300, 0 };
                double[] C = new double[] { 300, -200 };
                double[] D = new double[] { 100, -200 };
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          B, 1, 0); //直线插补,绝对模式
                SetArcVecter();
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     C, new double[] { 300, -100 }, 0, 0, 1, 0);
                //XY平面圆弧插补,顺时针,绝对模式模式。   此函数是基于圆心圆弧扩展的螺旋线插补运动(可作两轴圆弧插补)
                //终点坐标   圆心坐标
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          D, 1, 0); //直线插补,绝对模式
                SetArcVecter();
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     A, new double[] { 100, -100 }, 0, 0, 1, 0);
                LTDMC.dmc_conti_start_list(_CardID, crd);
                Thread.Sleep(1000);
                LTDMC.dmc_conti_close_list(_CardID, crd);
            }
            if (cbxMotionTrail.SelectedIndex == 2)
            {//直线 直线 圆弧 直线
                double[] A = new double[] { 0, 0 };
                double[] B = new double[] { 200, 0 };
                double[] C = new double[] { 200, -200 };
                double[] D = new double[] { 0, -200 };
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, B, 1, 0);  //直线插补
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, C, 1, 0);  //直线插补
                SetArcVecter();
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     D, new double[] { 100, -200 }, 0, 0, 1, 0);
                //XY平面圆弧插补,顺时针,相对坐标模式。   此函数是基于圆心圆弧扩展的螺旋线插补运动(可作两轴圆弧插补)
                //终点坐标   圆心坐标
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, A, 1, 0);  //直线插补
                LTDMC.dmc_conti_start_list(_CardID, crd);
                Thread.Sleep(1000);
                LTDMC.dmc_conti_close_list(_CardID, crd);
            }
            if (cbxMotionTrail.SelectedIndex == 3)
            {  //直线 圆弧 直线 圆弧 直线 直线
                double[] A = new double[] { 0, 0 };
                double[] B = new double[] { 200, 0 };
                double[] C = new double[] { 300, -100 };
                double[] D = new double[] { 300, -300 };
                double[] E = new double[] { 200, -400 };
                double[] F = new double[] { 0, -400 };
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, B, 1, 0);  //直线插补
                SetArcVecter();
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     C, new double[] { 200, -100 }, 0, 0, 1, 0);
                //XY平面圆弧插补,顺时针,相对坐标模式。   此函数是基于圆心圆弧扩展的螺旋线插补运动(可作两轴圆弧插补)
                //终点坐标   圆心坐标
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, D, 1, 0);  //直线插补
                SetArcVecter();
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     E, new double[] { 200, -300 }, 0, 0, 1, 0);
                SetLineVecter();
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, F, 1, 0);  //直线插补
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises, A, 1, 0);  //直线插补
                LTDMC.dmc_conti_start_list(_CardID, crd);
                Thread.Sleep(1000);
                LTDMC.dmc_conti_close_list(_CardID, crd);
            }
        }
Exemplo n.º 2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (cbxMotionTrail.SelectedItem == null)
            {
                MessageBox.Show("请选择轨迹");
                return;
            }
            ushort _CardID = 0;
            ushort AxisX   = 0;
            ushort AxisY   = 1;
            ushort crd     = 0;

            //设置脉冲当量
            LTDMC.dmc_set_equiv(0, AxisX, FormMain.PulseEquiv);
            LTDMC.dmc_set_equiv(0, AxisY, FormMain.PulseEquiv);
            //   画图
            ushort axisnum = 2;

            ushort[] axises = new ushort[] { AxisX, AxisY };
            LTDMC.dmc_conti_open_list(0, crd, axisnum, axises);
            //设置插补速度
            LTDMC.dmc_set_vector_profile_unit(0, crd, 0, vectorChabu, 0.1, 0.1, 0);
            // LTDMC.dmc_conti_set_blend(0, crd, 1);
            if (cbxMotionTrail.SelectedIndex == 0)
            {
                double[] A = new double[] { 0, 0 };
                double[] B = new double[] { 200, 0 };
                double[] C = new double[] { 400, -200 };
                double[] D = new double[] { 400, -400 };
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          B, 1, 0); //直线插补,相对模式
                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     C, new double[] { 200, -200 }, 0, 0, 1, 0);
                //XY平面圆弧插补,顺时针,相对坐标模式。   此函数是基于圆心圆弧扩展的螺旋线插补运动(可作两轴圆弧插补)
                //终点坐标   圆心坐标
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          D, 1, 0); //直线插补,相对模式
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          A, 1, 0); //直线插补,相对模式
                LTDMC.dmc_conti_start_list(_CardID, crd);
                Thread.Sleep(1000);
                LTDMC.dmc_conti_close_list(_CardID, crd);
            }
            if (cbxMotionTrail.SelectedIndex == 1)
            {
                double[] A = new double[] { 0, 0 };
                double[] B = new double[] { 200, 0 };
                double[] C = new double[] { 400, -200 };
                double[] D = new double[] { 400, -400 };
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          new double[] { 200, 0 }, 1, 0); //直线插补,相对模式

                LTDMC.dmc_conti_arc_move_center_unit(_CardID, crd, axisnum, axises,
                                                     new double[] { 400, -200 }, new double[] { 200, -200 }, 0, 0, 1, 0);
                //XY平面圆弧插补,顺时针,相对坐标模式。   此函数是基于圆心圆弧扩展的螺旋线插补运动(可作两轴圆弧插补)
                //终点坐标   圆心坐标
                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          new double[] { 400, -400 }, 1, 0); //直线插补,相对模式

                LTDMC.dmc_conti_line_unit(_CardID, crd, axisnum, axises,
                                          new double[] { 0, 0 }, 1, 0); //直线插补,相对模式

                LTDMC.dmc_conti_start_list(_CardID, crd);
                Thread.Sleep(1000);
                LTDMC.dmc_conti_close_list(_CardID, crd);
            }
            if (cbxMotionTrail.SelectedIndex == 2)
            {
            }
            if (cbxMotionTrail.SelectedIndex == 3)
            {
            }
        }
Exemplo n.º 3
0
        //设置PWM连续插补
        private void SetVPwm()
        {
            ushort channel = GetChannel();
            double duty    = Convert.ToDouble(this.txtDuty.Value) / 100;
            double freq    = Convert.ToDouble(this.txtFreq.Value);

            m_main.PWMChannel = channel;
            m_main.PWMDuty    = duty;
            m_main.PWMFreq    = freq;

            LTDMC.dmc_set_pwm_onoff_duty(m_cardId, 0, 0.8, 0.05);//设置PWM开关状态对应的占空比

            LTDMC.dmc_set_pwm_enable(m_cardId, GetEnable());
            LTDMC.dmc_set_pwm_output(m_cardId, channel, duty, freq);

            //设置插补轴脉冲
            LTDMC.dmc_set_equiv(m_cardId, 0, 100);
            LTDMC.dmc_set_equiv(m_cardId, 1, 100);

            //设置插补速度曲线参数,Crd坐标系
            LTDMC.dmc_set_vector_profile_unit(m_cardId, 0, 0, 100, 0.1, 0, 0);
            //设置跟随速度参数
            LTDMC.dmc_conti_set_pwm_follow_speed(m_cardId, 0, channel, GetPwmMode(), 100, 0, 0);

            //PWM跟随模式模式为0、1、2时,MaxValue/MaxVel/OutValue此三个参数无效

            ushort onOff   = 1; //PWM输出状态为:打开
            ushort deMode  = 0; //滞后模式为:滞后时间
            double deTime  = 2; //滞后时间:2S
            double revTime = 0; //保留参数:固定为0

            //设置轨迹段起点滞后时间
            LTDMC.dmc_conti_delay_pwm_to_start(m_cardId, 0, channel, onOff, deTime, deMode, revTime);

            //打开连续插补缓冲区
            LTDMC.dmc_conti_open_list(m_cardId, 0, 2, new ushort[] { 0, 1 });

            //第一段轨迹直线插补,绝对模式
            ushort[] axiss = { 0, 1 };
            //目标位置
            double[] tPos = { 200, 0 };
            LTDMC.dmc_conti_line_unit(m_cardId, 0, 2, axiss, tPos, 0, 1);

            //相当于轨迹终点,提前1S关闭使能
            double ahValue = 1; //提前1秒
            ushort ahMode  = 0; //输出提前模式:提前时间

            LTDMC.dmc_conti_ahead_pwm_to_stop(m_cardId, 0, channel, 0, ahValue, ahMode, 0);

            //禁止PWM输出
            //LTDMC.dmc_set_pwm_enable(m_cardId, 0);

            //设置第二段轨迹直线插补,绝对模式
            //目标位置
            double[] ePos = { 0, 0 };
            LTDMC.dmc_conti_line_unit(m_cardId, 0, 2, axiss, ePos, 0, 1);

            //开始连续插补
            LTDMC.dmc_conti_start_list(m_cardId, 0);

            //关闭连续插补缓冲区
            LTDMC.dmc_conti_close_list(m_cardId, 0);
        }