/// <summary> /// 連續移動 (需選擇使用軸參的手動速度或是自動速度) /// </summary> /// <param name="dir">移動方向</param> /// <param name="inAuto">手動或自動速度</param> /// <returns></returns> public bool ContinuousMove(RotationDirection dir, SpeedMode inAuto = SpeedMode.Auto) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { if (isAllowMove(dir)) { sbyte bDir = 1; if (dir == RotationDirection.CW) { bDir = 1; } else { bDir = -1; } if (inAuto == SpeedMode.Auto) { CCMNet.CS_mnet_m204_tv_move(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, MmToPulse(checkOverMaxSpeed(axisPara.StrVelA)) * bDir, MmToPulse(checkOverMaxSpeed(axisPara.DevVelA)) * bDir, axisPara.AccVelA); } else { CCMNet.CS_mnet_m204_tv_move(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, MmToPulse(checkOverMaxSpeed(axisPara.StrVelM)) * bDir, MmToPulse(checkOverMaxSpeed(axisPara.DevVelM)) * bDir, axisPara.AccVelM); } } } return(rc == 0 ? true : false); }
//將軸參寫入m1x1 slave private void setMotion() { U16 hMode; //初始化給1 且限制在 1~3,這邊又把home mode變成12 or 9 if (axisPara.HomeMode == HomeMode.TwoPoint) { hMode = 12; } else { hMode = 9; } initErr = CCMNet.CS_mnet_m1_set_alm(RingNoOfMNet, axisPara.SlaveIP, Convert.ToUInt16(axisPara.LogicALM), 0); initErr = CCMNet.CS_mnet_m1_set_inp(RingNoOfMNet, axisPara.SlaveIP, 0, Convert.ToUInt16(axisPara.LogicINP)); initErr = CCMNet.CS_mnet_m1_set_erc_on(RingNoOfMNet, axisPara.SlaveIP, 0); initErr = CCMNet.CS_mnet_m1_set_erc(RingNoOfMNet, axisPara.SlaveIP, Convert.ToUInt16(axisPara.LogicERC), 0, 0); initErr = CCMNet.CS_mnet_m1_set_home_config(RingNoOfMNet, axisPara.SlaveIP, hMode, Convert.ToUInt16(axisPara.LogicORG), Convert.ToUInt16(axisPara.LogicZ), 0, 0); initErr = CCMNet.CS_mnet_m1_set_sd(RingNoOfMNet, axisPara.SlaveIP, 0, Convert.ToInt16(axisPara.LogicSD), 0, 0); initErr = CCMNet.CS_mnet_m1_set_ltc_logic(RingNoOfMNet, axisPara.SlaveIP, Convert.ToUInt16(axisPara.LogicLTC)); initErr = CCMNet.CS_mnet_m1_set_feedback_src(RingNoOfMNet, axisPara.SlaveIP, 3); initErr = CCMNet.CS_mnet_m1_set_pls_outmode(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.PulseMode); initErr = CCMNet.CS_mnet_m1_set_pls_iptmode(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.EncMode, (U16)axisPara.EncDir); initErr = CCMNet.CS_mnet_m1_fix_speed_range(RingNoOfMNet, axisPara.SlaveIP, MmToPulse(axisPara.MaxVel)); }
//scan m1x1 slave IO status private void systemScan() { while (true) { if (keyOfIOStatus) { U32 status = 0; I16 rt = CCMNet.CS_mnet_m1_get_io_status(RingNoOfMNet, axisPara.SlaveIP, ref status); this.status.RDY = BitConverterEx.TestB(status, 0); this.status.ALM = BitConverterEx.TestB(status, 1); this.status.LimitP = BitConverterEx.TestB(status, 2); this.status.LimitN = BitConverterEx.TestB(status, 3); this.status.ORG = BitConverterEx.TestB(status, 4); this.status.DIR = BitConverterEx.TestB(status, 5); this.status.EMG = BitConverterEx.TestB(status, 6); this.status.PCS = BitConverterEx.TestB(status, 7); this.status.ERC = BitConverterEx.TestB(status, 8); this.status.ZPhase = BitConverterEx.TestB(status, 9); this.status.CLR = BitConverterEx.TestB(status, 10); this.status.Latch = BitConverterEx.TestB(status, 11); this.status.SD = BitConverterEx.TestB(status, 12); this.status.INP = BitConverterEx.TestB(status, 13); this.status.SVON = BitConverterEx.TestB(status, 14); this.status.RALM = BitConverterEx.TestB(status, 15); if (this.status.ALM || this.status.EMG) { this.status.Home = false; } Thread.Sleep(50); } } }
private double getErrorCount2() { I16 error = 0; CCMNet.CS_mnet_m204_get_error_counter(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, ref error); return(error); }
/// <summary> /// 吋動 (軸參設定的五個速度值) /// </summary> /// <param name="speedIndex">軸參之吋動速度</param> /// <param name="dir">吋動方向</param> public void Jog(JogSpeed jogSpeed, RotationDirection dir) { if (axisPara.IsActive && axisPara.Enabled) { double speed = 0; int i = 0; switch (jogSpeed) { case JogSpeed.Micro: speed = axisPara.JogMicroSpeed; break; case JogSpeed.Low: speed = axisPara.JogLowSpeed; break; case JogSpeed.Mid: speed = axisPara.JogMidSpeed; break; case JogSpeed.High: speed = axisPara.JogHighSpeed; break; case JogSpeed.Max: speed = axisPara.JogMaxSpeed; break; } i = MmToPulse(speed); CCMNet.CS_mnet_m1_set_tmove_speed(RingNoOfMNet, axisPara.SlaveIP, i / 2, i, axisPara.AccVelM, axisPara.DecVelM); CCMNet.CS_mnet_m1_v_move(RingNoOfMNet, axisPara.SlaveIP, Convert.ToByte(dir)); } }
private double getSpeed2() { double speed = 0; CCMNet.CS_mnet_m204_get_current_speed(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, ref speed); return(speed); }
//set command counter private void setPos(double s) { int cmdPos = new int(); cmdPos = Convert.ToInt32(Math.Round(s / axisPara.DistPerRole * axisPara.PulsePerRole)); CCMNet.CS_mnet_m1_set_command(RingNoOfMNet, axisPara.SlaveIP, cmdPos); }
/// <summary> /// 清除警報 /// </summary> /// <param name="status">OFF=Don't Output ON=Output</param> public void ResetAlarm(CmdStatus status) { if (axisPara.IsActive && axisPara.Enabled) { CCMNet.CS_mnet_m1_set_ralm(RingNoOfMNet, axisPara.SlaveIP, (U16)status); } }
private double getENC2() { int feedBackPos = new I32(); CCMNet.CS_mnet_m204_get_position(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, ref feedBackPos); return(feedBackPos); }
private double getPos2() { int cmdPos = new int(); CCMNet.CS_mnet_m204_get_command(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, ref cmdPos); return(cmdPos); }
/// <summary> /// 吋動 (自定義速度,初速為恆速1/2,加速度減速度為軸參手動設定) /// </summary> /// <param name="speed">速度值 (millimeter).</param> /// <param name="dir">吋動方向</param> public bool JogM(double speed, RotationDirection dir) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { if (isAllowMove(dir)) { sbyte bDir = 1; if (dir == RotationDirection.CW) { bDir = 1; } else { bDir = -1; } if (!this.IsBusy) { CCMNet.CS_mnet_m204_tv_move(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, MmToPulse(checkOverMaxSpeed(speed)) / 2 * bDir, MmToPulse(checkOverMaxSpeed(speed)) * bDir, axisPara.AccVelM); } else { CCMNet.CS_mnet_m204_v_change(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, MmToPulse(checkOverMaxSpeed(speed)) * bDir, axisPara.AccVelM); } } } return(rc == 0 ? true : false); }
/// <summary> /// M2X4 裝置啟停 /// </summary> /// <param name="option">The option.</param> public void ServoOn(CmdStatus option) { I16 rc = -1; if (axisPara != null) { if (axisPara.IsActive) { setMotion(); if (option == CmdStatus.OFF) { this.IsHome = false; axisPara.Enabled = false; rc = CCMNet.CS_mnet_m204_set_svon(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0); } if (option == CmdStatus.ON) { if (axisPara.IsActive) { axisPara.Enabled = true; rc = CCMNet.CS_mnet_m204_disable_soft_limit(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo); CCMNet.CS_mnet_m204_set_svon(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 1); } } } } }
//scan DIO slave status private void systemScan(FlowVar fv) { //while (true) //{ if (keyOfIOScan) { I16 status; for (byte portNo = 0; portNo < 4; portNo++) { status = CCMNet.CS_mnet_io_input(RingNoOfMNet, dIOPara.SlaveIP, portNo); for (int i = 0; i < 8; i++) { Status1[portNo * 8 + i] = BitConverterEx.TestB(status, (byte)i); Status2[portNo, i] = BitConverterEx.TestB(status, (byte)i); } } //Thread.Sleep(15); //if (Environment.ProcessorCount == 1 || (++_loops % 100) == 0) //{ // Thread.Sleep(1); //} //else //{ // Thread.SpinWait(_iterations); //} } //} }
/// <summary> /// 清除所有DO點狀態 /// </summary> public void ClearAllOutput() { CCMNet.CS_mnet_io_output(RingNoOfMNet, dIOPara.SlaveIP, 0, 0); CCMNet.CS_mnet_io_output(RingNoOfMNet, dIOPara.SlaveIP, 1, 0); CCMNet.CS_mnet_io_output(RingNoOfMNet, dIOPara.SlaveIP, 2, 0); CCMNet.CS_mnet_io_output(RingNoOfMNet, dIOPara.SlaveIP, 3, 0); }
public bool SetSoftLimit(I32 positiveLimit, I32 negativeLimit, CmdStatus sw, StopType stopType) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { if (sw == CmdStatus.ON) { /* * 0 INT only * 1 Immediately stop * 2 Slow down then stop * 3 Reserved */ if (stopType == StopType.Emergency) { rc = CCMNet.CS_mnet_m1_enable_soft_limit(RingNoOfMNet, axisPara.SlaveIP, 1); } else { rc = CCMNet.CS_mnet_m1_enable_soft_limit(RingNoOfMNet, axisPara.SlaveIP, 2); } rc = CCMNet.CS_mnet_m1_set_soft_limit(RingNoOfMNet, axisPara.SlaveIP, positiveLimit, negativeLimit); } else { rc = CCMNet.CS_mnet_m1_disable_soft_limit(RingNoOfMNet, axisPara.SlaveIP); } } return(rc == 0 ? true : false); }
public void JogConsiderSoftLimit(JogSpeed jogSpeed, RotationDirection dir) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { double speed = 0; switch (jogSpeed) { case JogSpeed.Micro: speed = axisPara.JogMicroSpeed; break; case JogSpeed.Low: speed = axisPara.JogLowSpeed; break; case JogSpeed.Mid: speed = axisPara.JogMidSpeed; break; case JogSpeed.High: speed = axisPara.JogHighSpeed; break; case JogSpeed.Max: speed = axisPara.JogMaxSpeed; break; } if (softLimitEnabled) { if (dir == RotationDirection.CW) { MoveM(softLimitP, speed); } else { MoveM(softLimitN, speed); } } else { if (isAllowMove(dir)) { byte bDir; if (dir == RotationDirection.CW) { bDir = 0; } else { bDir = 1; } CCMNet.CS_mnet_m1_set_tmove_speed(RingNoOfMNet, axisPara.SlaveIP, MmToPulse(checkOverMaxSpeed(speed)) / 2, MmToPulse(checkOverMaxSpeed(speed)), axisPara.AccVelM, axisPara.DecVelM); CCMNet.CS_mnet_m1_v_move(RingNoOfMNet, axisPara.SlaveIP, Convert.ToByte(dir)); } } } }
public void JogConsiderSoftLimit(JogSpeed jogSpeed, RotationDirection dir) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { double speed = 0; switch (jogSpeed) { case JogSpeed.Micro: speed = axisPara.JogMicroSpeed; break; case JogSpeed.Low: speed = axisPara.JogLowSpeed; break; case JogSpeed.Mid: speed = axisPara.JogMidSpeed; break; case JogSpeed.High: speed = axisPara.JogHighSpeed; break; case JogSpeed.Max: speed = axisPara.JogMaxSpeed; break; } sbyte bDir; if (dir == RotationDirection.CW) { bDir = 1; } else { bDir = -1; } if (softLimitEnabled) { if (dir == RotationDirection.CW) { AbsolueMove(softLimitP, speed); } else { AbsolueMove(softLimitN, speed); } } else { if (isAllowMove(dir)) { CCMNet.CS_mnet_m204_tv_move(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, MmToPulse(checkOverMaxSpeed(speed)) / 2 * bDir, MmToPulse(checkOverMaxSpeed(speed)) * bDir, axisPara.AccVelM); } } } }
/// <summary> /// 絕對移動 (需要自定義速度,初速為恆速1/2,加速度減速度為軸參手動設定) /// </summary> /// <param name="dest">目標位置 (millimeter).</param> /// <param name="speed"> 速度值 </param> public void MoveM(double dest, double speed) { if (axisPara.IsActive && axisPara.Enabled) { CCMNet.CS_mnet_m1_set_tmove_speed(RingNoOfMNet, axisPara.SlaveIP, MmToPulse(speed) / 2, MmToPulse(speed), axisPara.AccVelM, axisPara.DecVelM); nPos = MmToPulse(dest); CCMNet.CS_mnet_m1_start_a_move(RingNoOfMNet, axisPara.SlaveIP, nPos); } }
public bool DisableSoftLimit() { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { rc = CCMNet.CS_mnet_m1_disable_soft_limit(RingNoOfMNet, axisPara.SlaveIP); } return(rc == 0 ? true : false); }
/// <summary> /// 清除警報 /// </summary> public void ResetAlarm() { if (axisPara.IsActive && axisPara.Enabled) { CCMNet.CS_mnet_m204_set_ralm(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 1); Task.Factory.StartNew(() => { Thread.Sleep(1000); CCMNet.CS_mnet_m204_set_ralm(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0); }); } }
public void SetHomeAutoResetCounter() { CCMNet.CS_mnet_m204_set_home_auto_reset_counter(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0); //0 //NULL //1 //RESET COMMAND Count //2 //RESET POSITION Count //3 //RESET ERROR Count //4 //RESET GENENAL Count }
private double getErrorCount() { I16 error = 0; CCMNet.CS_mnet_m204_get_error_counter(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, ref error); if (axisPara.PulsePerRole != 0) { return((double)error / axisPara.PulsePerRole * axisPara.DistPerRole); } else { return(0); } }
private double getSpeed() { double speed = 0; CCMNet.CS_mnet_m204_get_current_speed(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, ref speed); if (axisPara.PulsePerRole != 0) { return(speed / axisPara.PulsePerRole * axisPara.DistPerRole); } else { return(0); } }
/// <summary> /// 絕對移動 (需選擇使用軸參的手動速度或是自動速度) /// </summary> /// <param name="dest">目標位置 (millimeter).</param> /// <param name="inAuto">手動或自動速度</param> public void Move(double dest, SpeedMode inAuto) { if (axisPara.IsActive && axisPara.Enabled) { if (inAuto == SpeedMode.Manual) { CCMNet.CS_mnet_m1_set_tmove_speed(RingNoOfMNet, axisPara.SlaveIP, MmToPulse(axisPara.StrVelM), MmToPulse(axisPara.DevVelM), axisPara.AccVelM, axisPara.DecVelM); } if (inAuto == SpeedMode.Auto) { CCMNet.CS_mnet_m1_set_tmove_speed(RingNoOfMNet, axisPara.SlaveIP, MmToPulse(axisPara.StrVelA), MmToPulse(axisPara.DevVelA), axisPara.AccVelA, axisPara.DecVelA); } nPos = MmToPulse(dest); CCMNet.CS_mnet_m1_start_a_move(RingNoOfMNet, axisPara.SlaveIP, nPos); } }
//get command counter private double getPos() { int cmdPos = new int(); double CmdPosx; CCMNet.CS_mnet_m1_get_command(RingNoOfMNet, axisPara.SlaveIP, ref cmdPos); CmdPosx = cmdPos; if (axisPara.PulsePerRole != 0) { return(CmdPosx / axisPara.PulsePerRole * axisPara.DistPerRole); } else { return(0); } }
/// <summary> /// 吋動 (自定義速度,初速為恆速1/2,加速度減速度為軸參手動設定) /// </summary> /// <param name="speed">速度值 (millimeter).</param> /// <param name="dir">吋動方向</param> public void JogM(double speed, RotationDirection dir) { if (axisPara.IsActive && axisPara.Enabled) { int i = MmToPulse(speed); if (!this.IsBusy) { CCMNet.CS_mnet_m1_set_tmove_speed(RingNoOfMNet, axisPara.SlaveIP, i / 2, i, axisPara.AccVelM, axisPara.DecVelM); } CCMNet.CS_mnet_m1_v_change(RingNoOfMNet, axisPara.SlaveIP, (double)i, 0.1); if (!this.IsBusy) { CCMNet.CS_mnet_m1_v_move(RingNoOfMNet, axisPara.SlaveIP, Convert.ToByte(dir)); } } }
private double getENC() { int feedBackPos = new I32(); double d_feedBackPos; CCMNet.CS_mnet_m1_get_position(RingNoOfMNet, axisPara.SlaveIP, ref feedBackPos); d_feedBackPos = feedBackPos; if (axisPara.PulsePerRole != 0) { return(d_feedBackPos / axisPara.PulsePerRole * axisPara.DistPerRole); } else { return(0); } }
public bool EnableSoftLimit(StopType stopType) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { if (stopType == StopType.Emergency) { rc = CCMNet.CS_mnet_m1_enable_soft_limit(RingNoOfMNet, axisPara.SlaveIP, 1); } else { rc = CCMNet.CS_mnet_m1_enable_soft_limit(RingNoOfMNet, axisPara.SlaveIP, 2); } } return(rc == 0 ? true : false); }
//將軸參寫入M2X4 slave private void setMotion() { U16 hMode; //初始化給1 且限制在 1~3,這邊又把home mode變成12 or 9 if (axisPara.HomeMode == HomeMode.TwoPoint) { hMode = 12; } else { hMode = 9; } initErr = CCMNet.CS_mnet_m204_set_alm(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, Convert.ToUInt16(axisPara.LogicALM), 0); if (axisPara.MotorMode == MotorMode.Servo) { initErr = CCMNet.CS_mnet_m204_set_inp(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 1, Convert.ToUInt16(axisPara.LogicINP)); } else { initErr = CCMNet.CS_mnet_m204_set_inp(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0, Convert.ToUInt16(axisPara.LogicINP)); } initErr = CCMNet.CS_mnet_m204_set_erc_on(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0); initErr = CCMNet.CS_mnet_m204_set_erc(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, Convert.ToUInt16(axisPara.LogicERC), 0, 0); initErr = CCMNet.CS_mnet_m204_set_home_config(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, hMode, Convert.ToUInt16(axisPara.LogicORG), Convert.ToUInt16(axisPara.LogicZ), 0, 0); initErr = CCMNet.CS_mnet_m204_set_sd(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0, Convert.ToInt16(axisPara.LogicSD), 0, 0); initErr = CCMNet.CS_mnet_m204_set_ltc_logic(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, Convert.ToUInt16(axisPara.LogicLTC)); initErr = CCMNet.CS_mnet_m204_set_pls_outmode(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, (U16)axisPara.PulseMode); initErr = CCMNet.CS_mnet_m204_set_pls_iptmode(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, (U16)axisPara.EncMode, (U16)axisPara.EncDir); if (axisPara.MotorMode == MotorMode.Servo) { //initErr = CCMNet.CS_mnet_m204_set_feedback_src(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 3); initErr = CCMNet.CS_mnet_m204_set_feedback_src(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0); } else { initErr = CCMNet.CS_mnet_m204_set_feedback_src(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 2); } //0:External Feedback, Position Counter //1:Command Pulse, Position Counter //2:Command Pulse, Command Pulse //3:External Feedback, Command Pulse initErr = CCMNet.CS_mnet_m204_set_el(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, 0, Convert.ToInt16(axisPara.LogicEL)); initErr = CCMNet.CS_mnet_m204_fix_speed_range(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, MmToPulse(axisPara.MaxVel)); }
/// <summary> /// 絕對移動 (需要自定義速度,初速為恆速1/2,加速度減速度為軸參手動設定) /// </summary> /// <param name="dest">目標位置 (millimeter).</param> /// <param name="speed"> 速度值 </param> /// <param name="s_curve"> T-Curve = true, S-Curve = false </param> public bool AbsolueMove(double dest, double speed, bool curve = true) { I16 rc = -1; if (axisPara.IsActive && axisPara.Enabled) { nPos = MmToPulse(dest); if (curve) { rc = CCMNet.CS_mnet_m204_start_ta_move(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, nPos, MmToPulse(speed) / 2, MmToPulse(speed), axisPara.AccVelM, axisPara.DecVelM); } else { rc = CCMNet.CS_mnet_m204_start_sa_move(RingNoOfMNet, axisPara.SlaveIP, (U16)axisPara.AxisNo, nPos, MmToPulse(speed) / 2, MmToPulse(speed), axisPara.AccVelM, axisPara.DecVelM, MmToPulse(speed) / 2, MmToPulse(speed) / 2); } } return(rc == 0 ? true : false); }