使用固高运动卡在圆形里走倒T型运动

 private void RunZ_Click(object sender, EventArgs e)
        {
            
            //搜索点
            double  radius = Convert.ToDouble(Radius.Text);
            double  stepLength = Convert.ToDouble(StepLength.Text);

            double StartLineY = Convert.ToDouble((radius * 2) % stepLength);

            int InterSpaceCount =int.Parse( ((radius*2) / stepLength).ToString() );

            double  y;
            double bottomLength;

            List<double[]> XYPoint = new List<double[]>();
            //  List<PointF> pt = new List<PointF>();


            //运动控制,采用点位运动的形式
            Axis = 1;
            rtn = GT_ClrSts(carNumber, 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;

            // X轴
            rtn = GT_SetTrapPrm(carNumber, Axis, ref trap);
            CommandPrint("GT_SetTrapPrm", rtn);

            // Y轴
            rtn = GT_SetTrapPrm(carNumber, (short)(Axis+1), ref trap);
            CommandPrint("GT_SetTrapPrm", rtn);

            //设置XY轴目标速度
            double vel = Convert.ToDouble(Speed.Text);
            rtn = GT_SetVel(carNumber, Axis, vel);
            CommandPrint("GT_SetVel", rtn);

            rtn = GT_SetVel(carNumber, (short)(Axis + 1), vel);
            CommandPrint("GT_SetVel", rtn);


          

            //搜索点
            for (int i = 0; i < InterSpaceCount; i++)
            {
                double[] site = new double[2];
                double[] sites = new double[2];
                if (StartLineY == 0)
                {
                    site[0] = 0;
                    site[1] = 0;
                    XYPoint.Add(site);
                    // StartLineY += InterSpace;
                    StartLineY += stepLength;
                }
                else
                {
                    if (StartLineY < stepLength)
                    {
                        StartLineY = stepLength;
                    }
                    y = StartLineY - radius;
                    bottomLength = Math.Sqrt((radius * radius) - (y * y));
                    bottomLength = Math.Round(bottomLength, 3);
                    Console.WriteLine($"bottomLength: {bottomLength}");

                    site[0] =  bottomLength;
                    site[1] =  y;
                    XYPoint.Add(site);

                    sites[0] = bottomLength;
                    sites[1] = y;
                    XYPoint.Add(sites);

                  //  StartLineY += InterSpace;
                    StartLineY += stepLength;
                    if (i % 2 == 0)
                    {
                        Console.WriteLine($"i: {i}");
                        //位置2,X轴
                        rtn = GT_SetPos(carNumber, Axis,(int)XYPoint[XYPoint.Count - 1][0]);
                        Console.WriteLine($"X轴移动到位置2: {(int)XYPoint[XYPoint.Count - 1][0]}");
                        //启动点位运动
                        rtn = GT_Update(carNumber, 1 << (Axis - 1));
                        CommandPrint("X轴GT_Update", rtn);

                        //位置2,Y轴
                        rtn = GT_SetPos(carNumber, (short)(Axis + 1), (int)XYPoint[XYPoint.Count - 1][1]);
                        Console.WriteLine($"Y轴移动到位置2: {(int)XYPoint[XYPoint.Count - 1][1]}");
                        rtn = GT_Update(carNumber, 1 << (Axis));
                        CommandPrint("Y轴GT_Update", rtn);
                        MoveDetect((int)XYPoint[XYPoint.Count - 1][0], (int)XYPoint[XYPoint.Count - 1][1]);


                        //位置1,X轴
                        rtn = GT_SetPos(carNumber, Axis, (int)XYPoint[XYPoint.Count - 2][0]);
                        Console.WriteLine($"X轴移动到位置1: {(int)XYPoint[XYPoint.Count - 2][0]}");
                        rtn = GT_Update(carNumber, 1 << (Axis - 1));


                        //位置1,Y轴
                        rtn = GT_SetPos(carNumber, (short)(Axis + 1), (int)XYPoint[XYPoint.Count - 2][1]);
                        Console.WriteLine($"Y轴移动到位置1: {(int)XYPoint[XYPoint.Count - 2][1]}");
                        rtn = GT_Update(carNumber, 1 << (Axis));
                        CommandPrint("Y轴GT_Update", rtn);
                        MoveDetect((int)XYPoint[XYPoint.Count - 2][0], (int)XYPoint[XYPoint.Count - 2][1]);
                  
                    }
                    else
                    {
                        Console.WriteLine($"i: {i}");
                        //位置1,X轴
                        rtn = GT_SetPos(carNumber, Axis, (int)XYPoint[XYPoint.Count - 2][0]);
                        Console.WriteLine($"X轴移动到位置1: {(int)XYPoint[XYPoint.Count - 2][0]}");
                        //启动点位运动
                        rtn = GT_Update(carNumber, 1 << (Axis - 1));
                        CommandPrint("X轴GT_Update", rtn);

                        //位置1,Y轴
                        rtn = GT_SetPos(carNumber, (short)(Axis + 1), (int)XYPoint[XYPoint.Count - 2][1]);
                        Console.WriteLine($"Y轴移动到位置1: {(int)XYPoint[XYPoint.Count - 2][1]}");
                        rtn = GT_Update(carNumber, 1 << (Axis));
                        CommandPrint("Y轴GT_Update", rtn);
                        MoveDetect((int)XYPoint[XYPoint.Count - 2][0], (int)XYPoint[XYPoint.Count - 2][1]);

                        

                        //位置2,X轴
                        rtn = GT_SetPos(carNumber, Axis, (int)XYPoint[XYPoint.Count - 1][0]);
                        Console.WriteLine($"X轴移动到位置2: { (int)XYPoint[XYPoint.Count - 1][0]}");
                        //启动点位运动
                        rtn = GT_Update(carNumber, 1 << (Axis - 1));
                        CommandPrint("X轴GT_Update", rtn);

                        //位置2,Y轴
                        rtn = GT_SetPos(carNumber, (short)(Axis + 1), (int)XYPoint[XYPoint.Count - 1][1]);
                        Console.WriteLine($"Y轴移动到位置2: { (int)XYPoint[XYPoint.Count - 1][1]}");
                        rtn = GT_Update(carNumber, 1 << (Axis));
                        CommandPrint("Y轴GT_Update", rtn);
                        MoveDetect((int)XYPoint[XYPoint.Count - 1][0],  (int)XYPoint[XYPoint.Count - 1][1]);

                    }                  
                }
            }
        }

在这里插入图片描述

相关推荐

  1. C#与雷赛运动控制使用(二) - 轴控制系统

    2024-07-22 17:16:04       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-22 17:16:04       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-22 17:16:04       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-22 17:16:04       45 阅读
  4. Python语言-面向对象

    2024-07-22 17:16:04       55 阅读

热门阅读

  1. 求助Python字体下载!

    2024-07-22 17:16:04       12 阅读
  2. 如何在 Nginx 中配置访问日志的格式?

    2024-07-22 17:16:04       15 阅读
  3. 精简的力量:目标检测中的模型压缩技术解析

    2024-07-22 17:16:04       15 阅读
  4. 如何用外呼系统提高销售打电话效率

    2024-07-22 17:16:04       16 阅读
  5. 计算机网络之物理层

    2024-07-22 17:16:04       14 阅读
  6. 并发编程核心概念

    2024-07-22 17:16:04       15 阅读
  7. iOS中的MVVM设计模式

    2024-07-22 17:16:04       19 阅读
  8. C语言 检查日期是否有效

    2024-07-22 17:16:04       19 阅读
  9. 实现给Nginx的指定网站开启gzip压缩

    2024-07-22 17:16:04       15 阅读
  10. C++多继承与虚继承

    2024-07-22 17:16:04       16 阅读
  11. C++11

    2024-07-22 17:16:04       14 阅读
  12. 直播架构如何设计核心节点和边缘节点

    2024-07-22 17:16:04       16 阅读