C#控制固高运动卡进行点位,Jog和插补运动

csharp 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static gts.mc;

namespace GTS
{
    public partial class Form1 : Form
    {
        private bool IsOpend;
        private short rtn;
        short Axis;
        short JogAxis;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void opend_Click(object sender, EventArgs e)
        {

            rtn = gts.mc.GT_Open(0,1);
            AxisNumber.SelectedIndex = 3;//选定R轴
            if (rtn == 0) 
            {              
                CommandPrint("GT_Open", 0);
                IsOpend =true;
            }
            else
            {
                CommandPrint("GT_Open", rtn);
            }
        }

        /// <summary>
        /// 复位控制卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 复位控制卡_Click(object sender, EventArgs e)
        {
            if (IsOpend==true)
            {
               rtn= GT_Reset();
                CommandPrint("GT_Reset", rtn);
            }
        }

        private void CommandPrint(string cmdName,short rtn)
        {
            Console.WriteLine($"调用命令:{cmdName} ,返回码结果: {rtn}");
        }

        /// <summary>
        /// 初始化控制卡
        /// </summary>
        string Initialize_Filen_ame = "";//文件名
        private void 初始化控制卡_Click(object sender, EventArgs e)
        {
            rtn= GT_LoadConfig(Initialize_Filen_ame);

            Axis = Convert.ToInt16(AxisNumber.Text);
            GT_PrfTrap(Axis);
        }

        /// <summary>
        /// 清除状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 清除状态_Click(object sender, EventArgs e)
        {
            Axis = Convert.ToInt16(AxisNumber.Text);
            rtn=GT_ClrSts(Axis, 8);//清除1到8轴状态
            CommandPrint("GT_ClrSts", rtn);
        }

        /// <summary>
        /// 位置清零
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 位置清零_Click(object sender, EventArgs e)
        {
           rtn=GT_ZeroPos(Axis,8);//1到8轴位置清零
           CommandPrint("GT_ZeroPos", rtn);
        }

        /// <summary>
        /// 点位运动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 点位运动_Click(object sender, EventArgs e)
        {

            Axis = Convert.ToInt16(AxisNumber.Text);
            rtn = GT_ClrSts(Axis, 8);//清除1到8轴状态

            TTrapPrm trap=new TTrapPrm();

            //获取参数
            double acc = Convert.ToDouble(Acceleration.Text);
            double dec=Convert.ToDouble(Deceleration.Text);
            short SmoothTime = Convert.ToInt16(SmoothingTime.Text);

            //设置参数
            trap.acc= acc;
            trap.dec= dec;
            trap.smoothTime = SmoothTime;
            trap.velStart = 10;

           // Axis = Convert.ToInt16(AxisNumber.Text);
            rtn = GT_SetTrapPrm(Axis, ref trap);
            CommandPrint("GT_SetTrapPrm", rtn);

            //设置目标位置和速度
            int pos = Convert.ToInt32(Position.Text);
            rtn = GT_SetPos(Axis, pos);
            CommandPrint("GT_SetPos", rtn);

            double vel = Convert.ToDouble(Speed.Text);
            rtn= GT_SetVel(Axis, vel);
            CommandPrint("GT_SetVel", rtn);

            //启动点位运动
            rtn = GT_Update(1 << (Axis - 1));
            CommandPrint("GT_Update", rtn);
        }


        /// <summary>
        /// 停止运动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 停止运动_Click(object sender, EventArgs e)
        {
            Axis = Convert.ToInt16(AxisNumber.Text);
            rtn = GT_Stop(1 << (Axis - 1), 0);
            CommandPrint("GT_Stop", rtn);
        }

        /// <summary>
        /// 更新监控数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (AxisNumber.SelectedIndex > 0)
            {
                Axis = Convert.ToInt16(AxisNumber.Text);

                GT_GetPrfPos(Axis, out double prfPos, 1, out uint clk);
                GT_GetEncPos(Axis, out double encPos, 1, out clk);
                GT_GetPrfVel(Axis, out double prfVel, 1, out clk);
                GT_GetEncVel(Axis, out double encVel, 1, out clk);

                PrfPos.Text = Math.Round(prfPos, 1).ToString();
                EncPos.Text = Math.Round(encPos, 1).ToString();
                PrfVel.Text = Math.Round(prfVel, 1).ToString();
                EncVel.Text = Math.Round(encVel, 1).ToString();
            }
              
        }

        /// <summary>
        /// 启动Jog模式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openJog_Click(object sender, EventArgs e)
        {
           
        }


        /// <summary>
        /// Jog运动松开按钮时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Jog_MouseUp(object sender, MouseEventArgs e)
        {
            JogAxis = Convert.ToInt16(JogAxisNumber.Text);
            rtn = GT_Stop(1 << (JogAxis - 1), 0);
            CommandPrint("GT_Stop", rtn);
        }


        /// <summary>
        /// 按下正向运动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ForJog_MouseDown(object sender, MouseEventArgs e)
        {
            //连接运动卡
            rtn = gts.mc.GT_Open(0, 1);
            if (rtn == 0)
            {
                CommandPrint("GT_Open", 0);
                IsOpend = true;
            }
            else
            {
                CommandPrint("GT_Open", rtn);
            }


            //启动Jog模式
            JogAxis = Convert.ToInt16(JogAxisNumber.Text);
            rtn = GT_PrfJog(JogAxis);
            CommandPrint("GT_PrfJog", rtn);

            //清除状态
            GT_ClrSts(JogAxis, 8);

            TJogPrm jog = new TJogPrm();
            //设置加速度和减速度
            double acc = Convert.ToDouble(JogAcc.Text);
            double dec = Convert.ToDouble(JogDec.Text);
            jog.acc = acc;
            jog.dec = dec;

            //设置jog模式下的运动参数          
            GT_SetJogPrm(JogAxis, ref jog);

            //设置目标速度
            double vel;
            if (JogAxis < 4)//R轴和XY轴的反应速度不一样
            {
                vel = Convert.ToDouble(JogVel.Text) * 10;
            }
            else
            {
                vel = Convert.ToDouble(JogVel.Text)/5;
                jog.acc = jog.acc / 5;
                jog.dec = jog.dec / 5;
            }
            rtn = GT_SetVel(JogAxis, vel);

            GT_Update(1 << (JogAxis - 1));
        }

        /// <summary>
        /// 按下负向运动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NegJog_MouseDown(object sender, MouseEventArgs e)
        {
            //连接运动卡
            rtn = gts.mc.GT_Open(0, 1);
            if (rtn == 0)
            {
                CommandPrint("GT_Open", 0);
                IsOpend = true;
            }
            else
            {
                CommandPrint("GT_Open", rtn);
            }

            //启动Jog模式
            JogAxis = Convert.ToInt16(JogAxisNumber.Text);
            rtn = GT_PrfJog(JogAxis);
            CommandPrint("GT_PrfJog", rtn);

            //清除状态
            GT_ClrSts(JogAxis, 8);

            TJogPrm jog = new TJogPrm();
            //设置加速度和减速度
            double acc = Convert.ToDouble(JogAcc.Text);
            double dec = Convert.ToDouble(JogDec.Text);
            jog.acc = acc;
            jog.dec = dec;
            

            //设置jog模式下的运动参数
            GT_SetJogPrm(JogAxis, ref jog);

            //设置目标速度
            double vel;
            if (JogAxis < 4)//R轴和XY轴的反应速度不一样
            {
                vel = Convert.ToDouble(JogVel.Text) * 10;
            }
            else
            {
                 vel = Convert.ToDouble(JogVel.Text)/5;
                jog.acc = jog.acc / 5;
                jog.dec = jog.dec / 5;
            }
            rtn = GT_SetVel(JogAxis, -vel);

            GT_Update(1 << (JogAxis - 1));
        }



        /// <summary>
        /// 建立插补坐标系
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BuildSystem_Click(object sender, EventArgs e)
        {
            var crd = new TCrdPrm();

            //设置坐标系维度
            crd.dimension = 2;
            crd.synVelMax = 500;
            crd.synAccMax = 3;
            crd.evenTime = 10;

            //规划XY轴
            crd.profile1 = 1;//X轴
            crd.profile2 = 2;//Y轴

            //设置原点
            crd.setOriginFlag = 1;
            crd.originPos1 = 100;
            crd.originPos2 = 100;

            rtn=GT_SetCrdPrm(1,ref  crd);
            CommandPrint("GT_SetCrdPrm", rtn);
        }


        /// <summary>
        /// 定义直线插补
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Linear_Int_Click(object sender, EventArgs e)
        {
           rtn= GT_LnXY(1, -200000, -200000, 100, 0.1, 0, 0);
            GT_LnXY(2, -400000, -400000, 100, 0.1, 0, 0);
            CommandPrint("GT_LnXY", rtn);
           rtn= GT_CrdStart(1, 0);
            CommandPrint("GT_CrdStart", rtn);
        }


        /// <summary>
        /// 圆弧插补
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Circular_Int_Click(object sender, EventArgs e)
        {
            GT_LnXY(1, 10000, 10000, 4, 0.1, 0, 0);
            rtn = GT_ArcXYC(1, 10000, 10000, 2000, 20000, 0, 5, 0.5, 0, 0);
            CommandPrint("GT_ArcXYC", rtn);
            rtn = GT_CrdStart(1, 0);
        }

        private void ForMotion_Click(object sender, EventArgs e)
        {

        }
    }

}
相关推荐
blammmp15 分钟前
Java:数据结构-枚举
java·开发语言·数据结构
何曾参静谧28 分钟前
「C/C++」C/C++ 指针篇 之 指针运算
c语言·开发语言·c++
暗黑起源喵33 分钟前
设计模式-工厂设计模式
java·开发语言·设计模式
WaaTong38 分钟前
Java反射
java·开发语言·反射
Troc_wangpeng39 分钟前
R language 关于二维平面直角坐标系的制作
开发语言·机器学习
努力的家伙是不讨厌的41 分钟前
解析json导出csv或者直接入库
开发语言·python·json
Envyᥫᩣ1 小时前
C#语言:从入门到精通
开发语言·c#
童先生1 小时前
Go 项目中实现类似 Java Shiro 的权限控制中间件?
开发语言·go
lulu_gh_yu1 小时前
数据结构之排序补充
c语言·开发语言·数据结构·c++·学习·算法·排序算法
Re.不晚2 小时前
Java入门15——抽象类
java·开发语言·学习·算法·intellij-idea