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

正运动控制卡学习-点动

一.硬件介绍

使用正运动控制卡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://www.xdnf.cn/news/19927.html

相关文章:

  • 景区负氧离子气象站:引领绿色旅游,畅吸清新每一刻
  • Vue3 中后台管理系统权限管理实现
  • Spring MVC 扩展机制对比总结:@Configuration + WebMvcConfigurer vs @ControllerAdvice
  • Spring Boot 启动卡死:循环依赖与Bean初始化的深度分析
  • 【问题记录】Anaconda的jupyter NoteBook点击launch的时候,弹出的页面提示ERR_FILE_NOT_FOUND
  • 【Linux我做主】细说进程等待
  • 20.35 ChatGLM3-6B QLoRA实战:4bit量化+低秩适配,显存直降70%!
  • 重温经典之游戏模拟器选型指南
  • java注解、Lambda表达式、Servlet
  • Web安全:你所不知道的HTTP Referer注入攻击
  • 【PZ-AU15P】璞致fpga开发板 Aritx UltraScalePlus PZ-AU15P 核心板与开发板用户手册
  • 新客户 | TDengine 时序数据库赋能开源鸿蒙物联展区实时监控与展示
  • 解决 ES 模块与 CommonJS 模块互操作性的关键开关esModuleInterop
  • AI+ 行动意见解读:音视频直播SDK如何加速行业智能化
  • Excel ——INDEX + MATCH 组合
  • [iOS] 折叠 cell
  • Fiddler 实战案例解析,开发者如何用抓包工具快速解决问题
  • 鸿蒙分布式数据同步失败全解
  • jenkins使用ansible单节点lnmp
  • Nvidia Orin DK 本地 ollama 主流 20GB 级模型 gpt-oss, gemma3, qwen3 部署与测试
  • AI搜索排名规则突变:企业如何用GEO工具保持竞争力?
  • LeetCode 刷题【64. 最小路径和】
  • 无人机气象观测技术
  • 华为的 4A 架构简介
  • 代码随想录算法训练营第二十八天 | 买卖股票的最佳实际、跳跃游戏、K次取反后最大化的数组和
  • Vue基础知识-脚手架开发-初始化目录解析
  • 分布式对象存储系统 Minio 之 Centos 环境安装
  • SQLynx 3.7 发布:数据库管理工具的性能与交互双重进化
  • Java 方法:从定义调用到重载,入门到面试全攻略
  • 前端路由切换不再白屏:React/Vue 实战优化全攻略(含可运行 Demo)