登录
首页 PLC论坛 三菱Mitsubishi
回帖 发帖
正文

主题:伺服电机运转中的“暂停功能”-新人求指教

点击:7630 回复:14

       如果用绝对位置,代码如下,主要是暂停的时候获取当前位置,如果还没达到目标位置,点击继续的时候重新执行移动到位置命令,相当于在线变位.本人专注工控上位机,运动控制以及机器视觉.代码是c#代码,电机函数换成自己的api即可.希望对你有帮助!
       static bool bPause = false;
       bool posCommandFinished = false;
       void StartMotosThreads()
       {
           Task task0 = Task.Factory.StartNew(()=> {
               while (true)
               {
                   if (!bPause)
                   {
                       if (!posCommandFinished)
                       {
                           posCommandFinished = false;
                           double targetPos = 5000000;
                           //-----------------------------------------------------------------
                           // Create a command value.
                           //-----------------------------------------------------------------
                           Motion.PosCommand posCommand = new Motion.PosCommand();
                           posCommand.Profile.Type = WMX3ApiCLR.ProfileType.SCurve;
                           posCommand.Axis = 0;
                           posCommand.Target = targetPos;
                           posCommand.Profile.Velocity = 100000;
                           posCommand.Profile.Acc = 1000000;
                           posCommand.Profile.Dec = 1000000;
                           //-----------------------------------------------------------------
                           // Execute command to move from current position to
                           // specified position.
                           //-----------------------------------------------------------------
                           //Wmx3Lib_cm.Motion.StartMov(posCommand);
                           Wmx3Lib_cm.Motion.StartPos(posCommand);
                           //-----------------------------------------------------------------
                           // Wait until the axis moves to the target position and stops.
                           //-----------------------------------------------------------------
                           Wmx3Lib_cm.Motion.Wait(0);
                           double currPos = 0;
                           Wmx3Lib_cm.AxisControl.GetPosFeedback(0, ref currPos);
                           if (currPos == targetPos)
                           {
                               posCommandFinished = true;
                           }
                           System.Threading.Thread.Sleep(2000);
                       }
                   }
               }
           });
}
private void button_PauseMotos_Click(object sender, EventArgs e)
       {
           if ("暂停" == button_PauseMotos.Text)
           {
               button_PauseMotos.Text = "恢复";
               bPause = true;
               Wmx3Lib_cm.Motion.Stop(0);
               Logger.Warning("电机暂停...");
           }
           else
           {
               button_PauseMotos.Text = "暂停";
               bPause = false;
               Logger.Warning("电机恢复...");
           }
       }
最后修改:2021/8/12 10:29:05
21-08-12 10:21
永宏有暂停输出功能
21-08-12 12:38
这样不就可以了
21-10-06 15:08
附件 1633504091(1).jpg
这样不就可以了
21-10-06 15:09

引用 飞库 在 2021/10/6 15:09:32 发言【内容省略】

如果是相对定位呢?
21-10-07 21:14

上一页 上一页

工控新闻

更多新闻资讯