当前位置: 首页 > news >正文

正运动控制卡学习-点动

一.硬件介绍

使用正运动控制卡ECI1408进行学习,使用正运动函数库进行设置,并参考网络视频等进行学习记录,侵权删除.

二.轴连续运动

2.1.连接状态查询

在Motion类中定义连接状态验证

//验证轴卡是否连接成功
public OperationResult CommonInitedValited()
{//使用前面数据,InitedOk进行判断if (initedOk){return OperationResult.CreateSuccessResult();}else{OperationResult result = new OperationResult();result.IsSuccess = false;result.ErrorMsg = "轴卡没有连接初始化";return result;}}

2.2.轴状态查询

验证轴状态,验证轴是否运动,采用正运动的控制函数进行验证

//验证轴状态是否OK,当轴运动时,则不能进行点动作业
public OperationResult CommonInitedValited(short axis)
{//验证卡是否连接IPOperationResult result=CommonInitedValited();//当轴卡连接失败时候if(!result.IsSucess) return result;
//判断轴是否运动if(IsMoving(axis)){ result.IsSuccess = false;result.ErrorMsg = "轴正在运行";return result;}return OperationResult.CreateSuccessResult();
}//定义轴运动函数
public bool IsMoving(short axis)
{//判断是否已经初始化OperationResult result = CommonInitedValidate();  if (!result.IsSuccess) return false;//根据正运动函数库,判断轴的状态时,返回值-1为停止状态,0运动中状态//首先定义轴运动状态,即轴为不运动状态int RunState=-1;//定义返回值int error=0;//对轴运动状态进行查看使用try{//对轴状态定义为引用类型,使用ref进行修饰int error=ZAux_Direct_GetIfIdle(IpHandle, axis, ref  RunState);//对返回的代码进行验证ErrorHandler("ZAux_Direct_GetIfIdle",  error)return RunState==0;}catch(Exception){return true;}}
//定义命令执行过程中错误代码private void ErrorHandler(string command, int error)
{string result = string.Empty;switch (error){case 0: break;default:result = string.Format("{0}" + "指令执行错误,错误码为{1}", command, error);break;}if (result.Length > 0){throw new Exception(result);}
}

2.3.轴运动参数设定

单轴连续运动,根据正运动轴运动中中单轴点动函数设定轴运动相关参数,设置轴类型,脉冲当量,起始速度,加速度,减速度,根据以上内容创建轴运动函数

public OperationResult VMove(short axis, float vel, bool dir, float velMin, float acc, float dec, float sramp){// 判断是否满足运动条件var result = CommonMotionValidate(axis);if (!result.IsSuccess) return result;//创建错误码int error = 0;try{//设置轴类型/*Atype类型 描述0 虚拟轴。1 脉冲方向方式的步进或伺服 。2 模拟信号控制方式的伺服 。3 正交编码器 。4 步进+编码器 。6 脉冲方向方式的编码器,可用于手轮输入。7 脉冲方向方式步进或伺服+EZ信号输入。8 ZCAN扩展脉冲方向方式步进或伺服 。9 ZCAN扩展正交编码器。10 ZCAN扩展脉冲方向方式的编码器。*/error = zmcaux.ZAux_Direct_SetAtype(IPHandle, axis, 1);ErrorHandler("ZAux_Direct_SetAtype", error);//设置脉冲当量switch (axis){case 0:error = zmcaux.ZAux_Direct_SetUnits(IPHandle, axis, unit0);ErrorHandler("ZAux_Direct_SetUnits", error);break;case 1:error = zmcaux.ZAux_Direct_SetUnits(IPHandle, axis, unit1);ErrorHandler("ZAux_Direct_SetUnits", error);break;case 2:error = zmcaux.ZAux_Direct_SetUnits(IPHandle, axis, unit2);ErrorHandler("ZAux_Direct_SetUnits", error);break;case 3:error = zmcaux.ZAux_Direct_SetUnits(IPHandle, axis, unit3);ErrorHandler("ZAux_Direct_SetUnits", error);break;default:break;}//设置最小速度error = zmcaux.ZAux_Direct_SetLspeed(IPHandle, axis, velMin);ErrorHandler("ZAux_Direct_SetLspeed", error);//设置运行速度error = zmcaux.ZAux_Direct_SetSpeed(IPHandle, axis, vel);ErrorHandler("ZAux_Direct_SetSpeed", error);//设置加速度error = zmcaux.ZAux_Direct_SetAccel(IPHandle, axis, acc);ErrorHandler("ZAux_Direct_SetAccel", error);//设置减速度error = zmcaux.ZAux_Direct_SetDecel(IPHandle, axis, dec);ErrorHandler("ZAux_Direct_SetDecel", error);//设置S曲线error = zmcaux.ZAux_Direct_SetSramp(IPHandle, axis, sramp);ErrorHandler("ZAux_Direct_SetSramp", error);//设置方向并运动error = zmcaux.ZAux_Direct_Single_Vmove(IPHandle, axis, dir ? 1 : -1);ErrorHandler("ZAux_Direct_Single_Vmove", error);}catch (Exception ex){result.IsSuccess = false;result.ErrorMsg = ex.Message;return result;}return OperationResult.CreateSuccessResult();}
//轴停止
public OperationResult StopAxis(short axis)
{//第一步:验证是否连接板卡OperationResult result = CommonInitedValidate();if (!result.IsSuccess) return result;try{int error = ZAux_Direct_Single_Cancel(IPHandle, axis, 2);return OperationResult.CreateSuccessResult();}catch (Exception e){result.IsSuccess = false;result.ErrorMsg = e.Message;return result;}
}

三.GUI实现

3.1.创建GUI界面

3.2.创建鼠标事件

private void btn_Jog_MouseDown(object sender, MouseEventArgs e)
{if (sender is Button btn){if (btn.Tag != null && btn.Tag.ToString().Length > 0){if (btn.Tag.ToString().Contains(';')){string[] values = btn.Tag.ToString().Split(';');if (values.Length == 2){//获取到轴号short axis = Convert.ToInt16(values[0]);//获取到方向bool dir = values[1] == "1";//获取设置的参数SetParam();var result = motion.VMove(axis, velMax, dir, velMin, acc, dec, sramp);if (result.IsSuccess == false){MessageBox.Show("点动失败:" + result.ErrorMsg, "点动失败");}}}}}
}
private void btn_Jog_MouseUp(object sender, MouseEventArgs e)
{if (sender is Button btn){if (btn.Tag != null && btn.Tag.ToString().Length > 0){if (btn.Tag.ToString().Contains(';')){string[] values = btn.Tag.ToString().Split(';');if (values.Length == 2){//获取到轴号short axis = Convert.ToInt16(values[0]);var result=  motion.StopAxis(axis);//获取设置的参数                      if (result.IsSuccess == false){MessageBox.Show("点动失败:" + result.ErrorMsg, "点动失败");}}}}}
}
private void SetParam()
{velMax = Convert.ToSingle(this.num_velmax.Value);velMin = Convert.ToSingle(this.num_velmin.Value);acc = Convert.ToSingle(this.num_acc.Value);dec = Convert.ToSingle(this.num_dec.Value);sramp = Convert.ToSingle(this.num_sramp.Value);zcreep = Convert.ToSingle(this.num_creepZ.Value);zhomedis = Convert.ToSingle(this.num_homeDisZ.Value);motion.unit0 = Convert.ToInt32(this.num_unit0.Value);}

点击按钮实现运动效果


文章转载自:

http://cLCsd3TQ.pLjdy.cn
http://K2mLaP1d.pLjdy.cn
http://ZQgEmmFM.pLjdy.cn
http://1thMwHYM.pLjdy.cn
http://n66BRs0h.pLjdy.cn
http://UArxFzES.pLjdy.cn
http://JrAJdYaJ.pLjdy.cn
http://K2ZKD5mx.pLjdy.cn
http://ZOZIMON6.pLjdy.cn
http://7n3J60CN.pLjdy.cn
http://fA7iaO45.pLjdy.cn
http://JGBT3Vdj.pLjdy.cn
http://WzjZu6mt.pLjdy.cn
http://yHpIb2LJ.pLjdy.cn
http://wdIL89ZN.pLjdy.cn
http://AgL0siqe.pLjdy.cn
http://8NrvYAiy.pLjdy.cn
http://EqOotIiN.pLjdy.cn
http://tu7nRiQ9.pLjdy.cn
http://HUS3J3F0.pLjdy.cn
http://zhZhRpQf.pLjdy.cn
http://bKcxtt70.pLjdy.cn
http://ocaXHoGb.pLjdy.cn
http://KsSQg36G.pLjdy.cn
http://qrsh15Ix.pLjdy.cn
http://Qjn1NRcu.pLjdy.cn
http://1kOfATgO.pLjdy.cn
http://573HyDpZ.pLjdy.cn
http://PHEoxI47.pLjdy.cn
http://cPnxCmxy.pLjdy.cn
http://www.dtcms.com/a/367494.html

相关文章:

  • CodeBuddy+Lucene 探索与实践日志:记录我如何从零构建桌面搜索引擎
  • 虚拟化安全:从逃逸漏洞到实战分析
  • 实战演练(二):结合路由与状态管理,构建一个小型博客前台
  • Webus 与中国国际航空合作实现 XRP 支付
  • 专项智能练习(计算机动画基础)
  • webpack scope hositing 和tree shaking
  • AGX Orin平台RTC驱动导致reboot系统卡住问题调试
  • 期权平仓后权利金去哪了?
  • 基于深度掩码的动态模糊处理
  • claude code route 使用教程|命令大全
  • LeetCode 994 腐烂的橘子
  • 如何在 ONLYOFFICE AI 插件中连接智谱 AI
  • 【面试题】搜索准确性不高你怎么排查?
  • 静态电流Iq 和 ICONT_MAX
  • Redis在商城开发中起到什么作用?
  • 华为OD最新机试真题-可以处理的最大任务数-OD统一考试(C卷)
  • 学习嵌入式第四十六天
  • redis的hash表如何扩容
  • 单片机和PLC有哪些区别?揭秘单片机MCU的常见应用
  • 基于STM32的智能家居语音控制系统设计
  • 操作系统-进程通信
  • IPV6之DHCPv6服务器和中继代理和前缀代理服务器客户端
  • Fiddler断点应用和弱网测试
  • 【C语言】 第三课 函数与栈帧机制详解
  • 2026届IC秋招联芸科技IC面经(完整面试题)
  • 【数学建模学习笔记】机器学习回归:随机森林回归
  • UE4 UAT 的六大流程 build cook stage pacakge archive deploy 与UAT的参数
  • 具身智能多模态感知与场景理解:多模态3D场景理解
  • 3D 可视化数字孪生运维管理平台:构建 “虚实协同” 的智慧运维新范式
  • 解决前端文件下载时文件名自定义的完美方案