ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

轨迹运动功能

2021-01-30 13:01:35  阅读:272  来源: 互联网

标签:功能 轨迹 LTSMC start num CardNum 运动 smc Row


int Row, Col; double[,] Date; int wether_loading_pointa = 0;
        public static double[] G_X; public static double[] G_Y; public static double[] G_Z; public static double[] posi_mode;
        private void button_datainput_Click(object sender, EventArgs e)
        {
            if (machine_origin == 0)
            {
                MessageBox.Show("原点未校准!");
                return;
            }
            OpenFileDialog openDlg = new OpenFileDialog();
            openDlg.Title = "打开数据文件";
            openDlg.Filter = "数据文件 (*.txt)|*.txt|All|*.*";
            bool result = false;
            string FilePath;
            string[] TempData;
            string[] TempArry;
            Row = 0;
            Col = 0;

            if (openDlg.ShowDialog() == DialogResult.OK)
            {
                FilePath = openDlg.FileName;
                TempData = System.IO.File.ReadAllLines(FilePath, System.Text.Encoding.Default);
                Row = TempData.GetLength(0);                                              //行数    
                TempArry = TempData[1].Split(',');
                Col = TempArry.GetLength(0);                                             //列数
                Date = new double[Row, Col];
                for (int i = 0; i < Row; i++)
                {
                    string[] Arry = TempData[i].Split(',');
                    for (int j = 0; j < Col; j++)
                    {
                        Date[i, j] = Convert.ToDouble(Arry[j]);
                    }
                }
                result = true;
            }
            if (result)
            {
                G_X = new double[Row]; G_Y = new double[Row]; G_Z = new double[Row];
                for (int j = 0; j < Row; j++)
                {
                    posi_mode[j] = Date[j, 0];//插补模式
                    G_X[j] = Date[j, 1]; G_Y[j] = Date[j, 2]; G_Z[j] = Date[j, 3];
                }
                wether_loading_pointa = 1;
                MessageBox.Show("路径读取完成!");
            }
            else
            {
                MessageBox.Show("路径读取错误!");
                return;
            }
            textBox_pointnum.Text = Convert.ToString(Row);  

        }
  private void button_run_Click(object sender, EventArgs e)
        {
            if (wether_link == 0)
            {
                MessageBox.Show("请先打开设备!");
                return;
            }
            if (SF == 0)
            {
                MessageBox.Show("伺服未开启!");
                return;
            }
            if (LTSMC.smc_check_done_multicoor(CardNum, 0) == 0)
            {
                MessageBox.Show("电机运动中,请稍后尝试!", "提示");
                return;
            }
            if (wether_loading_pointa == 0)
            {
                MessageBox.Show("未导入轨迹!", "提示");
                return;
            }

            for (int i = 0; i < axis_all.Length; i = i + 1)
            {
                LTSMC.smc_set_alm_mode(CardNum, axis_all[i], 0, 0, 0);//设置报警使能,关闭报警
                LTSMC.smc_write_sevon_pin(CardNum, axis_all[i], 0);//打开伺服使能               
            }
            double speed = decimal.ToDouble(run_speed.Value) * (fp / (2 * Math.PI));      //单位:unit/s
            ThreadPool.QueueUserWorkItem(
            delegate
            {
                int start_num;
                ushort[] AxisList = { 0, 1, 2 };
                LTSMC.smc_conti_set_lookahead_mode(CardNum, 0, 0, 0, 0, 0);
                LTSMC.smc_conti_open_list(CardNum, 0, 3, AxisList);
                LTSMC.smc_set_vector_profile_unit(CardNum, 0, speed, speed, acc / 2, dec / 2, speed);//设置插补运动速度参数
                LTSMC.smc_set_vector_s_profile(CardNum, 0, 0, acc / 2);//设置s曲线平滑时间
                //LTSMC.smc_conti_change_speed_ratio(CardNum, 0, 0.1);    //设置加工起始速度:50*0.1

                if (Row < 500)
                {
                    start_num = 0;
                    loadinging_interpolation(start_num, Row);
                    processing = 1;
                    LTSMC.smc_conti_start_list(CardNum, 0);//启动插补
                    LTSMC.smc_conti_close_list(CardNum, 0);//关闭插补缓冲区
                }
                else   
                {
                    start_num = 0;
                    loadinging_interpolation(start_num, 500);
                    int loaded_num = 500; int memory_num; int current_loading_num = 40;
                    processing = 1;
                    LTSMC.smc_conti_start_list(CardNum, 0);//启动插补
                    while (loaded_num < Row)
                    {
                        memory_num = LTSMC.smc_conti_remain_space(CardNum, 0);
                        if (memory_num >= current_loading_num)
                        {
                            if (Row - loaded_num >= current_loading_num)
                            {
                                start_num = loaded_num;
                                loadinging_interpolation(start_num, current_loading_num);
                                loaded_num = loaded_num + current_loading_num;
                            }
                            else
                            {
                                start_num = loaded_num;
                                loadinging_interpolation(start_num, Row - loaded_num);
                                loaded_num = Row;
                            }
                        }
                        else
                        {
                            Thread.Sleep(10);
                        }
                    }
                    LTSMC.smc_conti_close_list(CardNum, 0);//关闭插补缓冲区
                }
            }
            );
        }
        public void loadinging_interpolation(int start_num, int loading_point_num)
        {
            ushort[] AxisList = { 0, 1, 2 };
            for (int i = start_num; i < start_num + loading_point_num; i = i + 1)
                if (posi_mode[i] == 0)//直线插补运动模式
                {
                    LTSMC.smc_conti_line_unit(CardNum, 0, 3, AxisList, new double[] { Inverse.C1[i, 0], Inverse.C1[i, 1], Inverse.C1[i, 2] }, 0, 0);//运动模式,0: 相对坐标模式,跑相对坐标模式,首先回到原点
                }
                else
                {
                    MessageBox.Show("轨迹点格式错误!");
                }
        }

        //暂停
        int processing = 1;
        private void button_stop0_Click(object sender, EventArgs e)
        {
            if (processing == 1)
            {
                LTSMC.smc_conti_pause_list(CardNum, 0);
                button_stop0.Text = "继续";
                button_stop0.ForeColor = Color.Blue;
                processing = 0;
            }
            else
            {
                LTSMC.smc_conti_start_list(CardNum, 0);
                button_stop0.Text = "暂停";
                button_stop0.ForeColor = Color.Red;
                processing = 1;
            }
        }
        //停止
        private void button_stop1_Click(object sender, EventArgs e)
        {
            button_stop0.Text = "暂停";
            progressBar_processing.Value = 0;
            LTSMC.smc_set_pwm_output(CardNum, 0, 0, 0);
            wether_loading_pointa = 0;
            LTSMC.smc_conti_stop_list(CardNum, 0, 0);//停止模式, 0: 减速停止, 1: 立即停止
        }
        //程序关闭
        private void main_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result_zero = MessageBox.Show("机器是否已回零?", "提示:",
               MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result_zero == DialogResult.Yes)
            {  
                LTSMC.smc_write_outbit(CardNum, 17, 1);    //打开抱闸的IO(0,低电平。1,高电平打开抱闸)
                LTSMC.smc_conti_stop_list(CardNum, 0, 0);//停止模式, 0: 减速停止, 1: 立即停止              
                LTSMC.smc_set_pwm_output(CardNum, 0, 0, 0);
                LTSMC.smc_handwheel_set_mode(CardNum, 0, 0);//设置手轮运动模式,硬件或软件模式
                LTSMC.smc_handwheel_stop(CardNum);//手轮关闭
                for (int i = 0; i < axis_all.Length; i = i + 1)
                {
                    LTSMC.smc_write_sevon_pin(CardNum, axis_all[i], 1);//关闭伺服使能               
                }
                timer4.Enabled = true;
                timer4.Interval = 500;//执行间隔时间,单位为毫秒    
                timer4.Start();
                Application.ExitThread();
            }
            if (result_zero == DialogResult.No)
            {
                e.Cancel = true;
                DialogResult result_ifzero = MessageBox.Show("机器是否现在回零?", "提示:",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result_ifzero == DialogResult.Yes)
                {
                    comeback();
                }
                if (result_ifzero == DialogResult.No)
                {
                    this.Show();
                }
            }
        }

 

标签:功能,轨迹,LTSMC,start,num,CardNum,运动,smc,Row
来源: https://www.cnblogs.com/charles48789982/p/14348731.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有