public int RelLine_P(int[] axisList, double[] posList, JFMotionParam mp) { _CheckAxisEnable(axisList, "RelLine_P"); if (posList == null || posList.Count() != axisList.Count()) { throw new ArgumentException("RelLine_P(int[] axisList, double[] posList) failed By: posList.Count() != axisList.Count()"); } lock (ml) { HTM.MOTION_PARA _mp = new HTM.MOTION_PARA() { vStart = mp.vs, vMax = mp.vm, vEnd = mp.ve, acc = mp.acc, dec = mp.dec, sFactor = mp.curve, timeout = double.MaxValue }; int opt = HTM.Line(axisList, axisList.Count(), posList, 1.0, HTM.MotionMode.RS, ref _mp); if (opt != 0) { return((int)ErrorDef.InvokeFailed); } return((int)ErrorDef.Success); } }
/// <summary>运动控制卡初始化 </summary> internal void Open() { AxisCount = HTM.GetAxisNum(); if (AxisCount > 0) { axisHomeDones = new bool[AxisCount]; detectHomeDones = new Thread[AxisCount]; _motionParams = new JFMotionParam[AxisCount]; for (int i = 0; i < AxisCount; i++) { HTM.AXIS_INFO ai; HTM.GetAxisInfo(i, out ai); HTM.MOTION_PARA mp = HTM.GetMotionPara(i);//HTM.GetMovePara(i, out mp); //if (ret != 0) //{ // AxisCount = 0; // _motionParams = null; // throw new Exception(string.Format("MC_Htm.Init Failed :HTM.GetMovePara(axis = {0}) return errorCode = {1}", i, ret)); //} _motionParams[i] = new JFMotionParam(); _motionParams[i].vs = mp.vStart; _motionParams[i].vm = mp.vMax; _motionParams[i].ve = mp.vEnd; _motionParams[i].acc = mp.acc; _motionParams[i].dec = mp.dec; _motionParams[i].curve = mp.sFactor; _motionParams[i].jerk = 0; axisHomeDones[i] = false; detectHomeDones[i] = new Thread(new ParameterizedThreadStart(FuncDetectHomeDone)); } } IsOpen = true; }
bool _isMotionParamValid(JFMotionParam mp) { if (mp.acc <= 0) { MessageBox.Show("无效操作:加速度参数acc <=0"); return(false); } if (mp.dec <= 0) { MessageBox.Show("无效操作:减速度参数dec <=0"); return(false); } if (mp.vs < 0) { MessageBox.Show("无效操作:初始速度参数vs <0"); return(false); } if (mp.vm <= 0) { MessageBox.Show("无效操作:工作速度参数vm <=0"); return(false); } if (mp.ve < 0) { MessageBox.Show("无效操作:终点速度参数ve <0"); return(false); } if (mp.curve < 0 || mp.curve > 1) { MessageBox.Show("无效操作:加速取消参数 curve 不在允许范围0~1"); return(false); } return(true); }
/// <summary> /// 以指定运动参数做速度运动 /// </summary> /// <param name="axis"></param> /// <param name="mp"></param> /// <returns></returns> public int VelMove_P(int axis, JFMotionParam mp, bool isPositive) { _CheckAxisEnable(axis, "VelMove_P"); lock (ml) { HTM.MOTION_PARA _mp = new HTM.MOTION_PARA() { vStart = mp.vs, vMax = mp.vm, vEnd = mp.ve, acc = mp.acc, dec = mp.dec, sFactor = mp.curve, timeout = double.MaxValue }; int opt = HTM.Speed(axis, isPositive?1.0:-1.0, ref _mp); if (0 != opt) { return((int)ErrorDef.InvokeFailed); } return((int)ErrorDef.Success); } }
protected override bool ActionGenuine(out string errorInfo) { IJFInitializable dev = null; JFDevCellInfo ci = null; string axisID = GetInitParamValue("轴ID") as string; if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID)) { errorInfo = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo)) { SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } JFMotionParam mp = (JFMotionParam)GetInitParamValue("运动参数"); /* * public double vs { get; set; } * /// <summary>最大速度</summary> * public double vm { get; set; } * /// <summary>结束速度</summary> * public double ve { get; set; } * /// <summary>加速度</summary> * public double acc { get; set; } * /// <summary>减速度</summary> * public double dec { get; set; } * /// <summary>s曲线因子(0~1.0)</summary> * public double curve { get; set; } * /// <summary>加加速</summary> * public double jerk { get; set; } */ if (mp.vs < 0) { errorInfo = "起始速度参数vs < 0"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (mp.vm <= 0) { errorInfo = "运行速度参数vm <= 0"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (mp.ve < 0) { errorInfo = "终点速度参数ve < 0"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (mp.acc <= 0) { errorInfo = "加速度参数acc <= 0"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (mp.dec <= 0) { errorInfo = "减速度参数dec <= 0"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (mp.curve < 0 || mp.curve > 1) { errorInfo = "加速度曲线段系数不在允许范围0~1"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex); int errCode = md.SetMotionParam(ci.ChannelIndex, mp); if (errCode < 0) { errorInfo = "SDK调用出错:" + md.GetErrorInfo(errCode); SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } errorInfo = "Success"; SetOutputParamValue("执行结果", JFWorkCmdResult.Success); return(true); }
public int AbsArc2CE_P(int axis1, int axis2, double center1, double center2, double pos1, double pos2, bool isPositive, JFMotionParam mp) { _CheckAxisEnable(axis1, "AbsArc2CE_P"); _CheckAxisEnable(axis2, "AbsArc2CE_P"); lock (ml) { HTM.MOTION_PARA _mp = new HTM.MOTION_PARA() { vStart = mp.vs, vMax = mp.vm, vEnd = mp.ve, acc = mp.acc, dec = mp.dec, sFactor = mp.curve, timeout = double.MaxValue }; int opt = HTM.ArcCe(axis1, axis2, center1, center2, pos1, pos2, isPositive ? 1 : 0, 1.0, HTM.MotionMode.AS, ref _mp); if (0 != opt) { return((int)ErrorDef.InvokeFailed); } return((int)ErrorDef.Success); } }
public int SetMotionParam(int axis, JFMotionParam mp) { _CheckAxisEnable(axis, "GetMotionParam"); _motionParams[axis] = mp; return(0); }
/// <summary> /// 获取单轴运动参数 /// </summary> /// <param name="axis"></param> /// <returns></returns> public int GetMotionParam(int axis, out JFMotionParam mp) { _CheckAxisEnable(axis, "GetMotionParam"); mp = _motionParams[axis]; return((int)ErrorDef.Success); }
public int BuffRelArc2CA(int axis1, int axis2, double center1, double center2, double angle, JFMotionParam mp) { _CheckAxisEnable(axis1, "BuffRelArc2CA"); _CheckAxisEnable(axis2, "BuffRelArc2CA"); lock (ml) { HTM.MOTION_PARA _mp = new HTM.MOTION_PARA() { vStart = mp.vs, vMax = mp.vm, vEnd = mp.ve, acc = mp.acc, dec = mp.dec, sFactor = mp.curve, timeout = double.MaxValue }; int opt = HTM.ArcCa(axis1, axis2, center1, center2, angle, 1.0, HTM.MotionMode.RS | HTM.MotionMode.BUF, ref _mp); if (0 != opt) { return((int)ErrorDef.InvokeFailed); } return((int)ErrorDef.Success); } }
/// <summary> /// 开始直线插补运动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btStartLiner_Click(object sender, EventArgs e) { if (dgvLinePos.Rows.Count == 0) { MessageBox.Show("请设置差补运动的轴数量"); return; } List <int> axisIDs = new List <int>(); List <double> trgtPoses = new List <double>(); for (int i = 0; i < dgvLinePos.Rows.Count; i++) { string axisIDText = dgvLinePos.Rows[i].Cells[0].Value as string; if (string.IsNullOrEmpty(axisIDText)) { MessageBox.Show("请设置差补轴" + (i + 1) + " 的轴序号"); return; } int axisID = Convert.ToInt32(axisIDText); axisIDs.Add(axisID); string trgtPos = dgvLinePos.Rows[i].Cells[1].Value as string; if (string.IsNullOrEmpty(trgtPos)) { MessageBox.Show("请设置差补轴" + (i + 1) + " 的目标位置"); return; } double dVal = 0; if (!double.TryParse(trgtPos, out dVal)) { MessageBox.Show("差补轴" + (i + 1) + " 的目标位置不是一个数字,请重新输入"); return; } if (!_IsAxisCanMove(axisID)) { return; } trgtPoses.Add(dVal); } if (dgvLinePos.Rows.Count == 0) { MessageBox.Show("请设置差补运动的轴数量"); return; } object omp = null; if (!ucLineParam.GetParamValue(out omp)) { MessageBox.Show("未能获取运动参数,请检查输入"); return; } JFMotionParam mp = (JFMotionParam)omp; if (!_isMotionParamValid(mp)) { return; } int err = 0; if (chkAbsLine.Checked) { err = _module.AbsLine_P(axisIDs.ToArray(), trgtPoses.ToArray(), mp); } else { err = _module.RelLine_P(axisIDs.ToArray(), trgtPoses.ToArray(), mp); } if (err != 0) { MessageBox.Show("操作失败:" + _module.GetErrorInfo(err)); } else { ShowTips("开始插补运动"); } }