public override async Task AbsMoveAsync(uint axisindex, int position) { if (!m_isInitialed) { throw new Exception("请先初始化"); } if (!m_isLoadConfigFile) { throw new Exception("未加载xml配置文件"); } //APS168.APS_set_axis_param_f((int)axisindex, (Int32)APS_Define.PRA_ACC, acc); //APS168.APS_set_axis_param_f((int)axisindex, (Int32)APS_Define.PRA_DEC, dec); //APS168.APS_set_axis_param_f((int)axisindex, (Int32)APS_Define.PRA_VS, startv); //APS168.APS_set_axis_param_f((int)axisindex, (Int32)APS_Define.PRA_VM, maxv); int maxv = 0; APS168.APS_get_axis_param((int)axisindex, (int)APS_Define.PRA_VM, ref maxv); await Task.Run(() => { APS168.APS_absolute_move((int)axisindex, position, (int)maxv); //等待Motion Down完成 int motionStatusMdn = 5; while ((APS168.APS_motion_status((int)axisindex) & 1 << motionStatusMdn) == 0) { Thread.Sleep(100); } }); }
/// <summary> /// To the start positoin(-116000). /// </summary> /// <returns>System.Int32.</returns> public override int ToStartPositoin() { int err = -1; int pos = 0; if (this.currentDirection != MotionDirection.Stop || this.currentDirection != MotionDirection.Initial) { err = APS168.APS_stop_move(mCardPara.AxisID); System.Threading.Thread.Sleep(200); } int startPos = -116000;//-116000 for smart phone demo; -50000 for Fred's customer err = APS168.APS_get_position(mCardPara.AxisID, ref pos); if (pos == startPos) { return(err); } APS168.APS_set_axis_param_f(mCardPara.AxisID, (Int32)APS_Define.PRA_STP_DEC, 1000000.0); APS168.APS_set_axis_param_f(mCardPara.AxisID, (Int32)APS_Define.PRA_CURVE, 0.5); //Set acceleration rate APS168.APS_set_axis_param_f(mCardPara.AxisID, (Int32)APS_Define.PRA_ACC, 2000000.0); //Set acceleration rate APS168.APS_set_axis_param_f(mCardPara.AxisID, (Int32)APS_Define.PRA_DEC, 2000000.0); //Set deceleration rate err = APS168.APS_absolute_move(mCardPara.AxisID, startPos, 200000); do { APS168.APS_get_position(mCardPara.AxisID, ref pos); } while (pos != startPos); this.currentDirection = MotionDirection.Stop; return(err); }
private void btnAbsoluteMove_Click(object sender, EventArgs e) { _selectAxis = Convert.ToInt32(cmbSelectAxis.SelectedItem); var praAcc = Convert.ToDouble(txtPraAcc.Text); var praDec = Convert.ToDouble(txtPraDec.Text); var praVm = Convert.ToInt32(txtPraVm.Text); var pulse = Convert.ToInt32(txtAbsolutePulse.Text); APS168.APS_set_axis_param_f(_selectAxis, (int)APS_Define.PRA_ACC, praAcc); // Set acceleration rate APS168.APS_set_axis_param_f(_selectAxis, (int)APS_Define.PRA_DEC, praDec); // Set deceleration rate if (_card0.IsLoadXmlFile) { var task = new Task(() => { APS168.APS_absolute_move(_selectAxis, pulse, praVm); //等待Motion Down完成 var motionStatusMdn = 5; while ((APS168.APS_motion_status(_selectAxis) & (1 << motionStatusMdn)) == 0) { Thread.Sleep(100); } MessageBox.Show("运动完成!"); }); task.Start(); } else { MessageBox.Show("请加载配置文件!"); } }
/// <summary> /// 单轴绝对运动 /// </summary> /// <param name="axisNo"></param> /// <param name="pulseNum"></param> /// <param name="velocityCurveParams"></param> public void MoveAbsPulse(int axisNo, int pulseNum, VelocityCurve velocityCurveParams) { //设置速度 SetAxisVelocity(axisNo, velocityCurveParams); //启动运动 APS168.APS_absolute_move(axisNo, pulseNum, (int)velocityCurveParams.Maxvel); }
/// <summary> /// 单轴绝对运动 /// </summary> /// <param name="axisNo"></param> /// <param name="pulseNum"></param> /// <param name="velocityCurveParams"></param> public override void AbsoluteMove(short axisNo, double pulseNum, VelocityCurve velocityCurveParams) { //设置速度 SetAxisVelocity(axisNo, velocityCurveParams); //启动运动 APS168.APS_absolute_move(axisNo, (int)pulseNum, (int)velocityCurveParams.Maxvel); }
private void btnRun_Click(object sender, EventArgs e) { //重置触发计数 //APS168.APS_reset_trigger_count(_card0.CardId, 0); //关闭触发 APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TRG_EN, 0); //TRG 0 ~ 3 enable by bit APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TRG_EN, Convert.ToInt32("0001", 2)); //Source Encoder0 APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TCMP0_SRC, 0); //0=Negative direction , 1= Positive direction, 2=Bi-direction(No direction) APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TCMP0_DIR, 2); //Trigger output 0 (TRG0) source Bit( 1:On, 0:Off) Bit 0: Manual Bit 1:Reserved Bit 2:TCMP0 Bit 3:TCMP1 Bit 4:LCMP0 Bit 5:LCMP1 APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TRG0_SRC, Convert.ToInt32("0100", 2)); //TRG1 pulse width APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TRG0_PWD, 50000); // pulse width= value * 0.02 us //TRG 1 logic 0: Not inverse 1:Inverse APS168.APS_set_trigger_param(_card0.CardId, (short)APS_Define.TGR_TRG0_LOGIC, 0); //设置1可能会多一次触发 //重置触发计数 //APS168.APS_reset_trigger_count(_card0.CardId, 0); //线程1,设置触发点,开始运动 Task.Factory.StartNew(() => { //位置比较触发点 var CMP_x = new[] { 2000, 4000, 7000, 9000, 12000, 15000, 19000, 22000, 23000, 25000, 24000, 21000, 18000, 15000, 11000, 9000 }; APS168.APS_set_trigger_table(_card0.CardId, 0, CMP_x, CMP_x.Length); //运动到30000 APS168.APS_absolute_move(_selectAxis, 30000, 30000); while ((APS168.APS_motion_status(_selectAxis) & (1 << 5)) == 0) //motionStatusMdn = 5 { Thread.Sleep(100); } //运动到0 APS168.APS_absolute_move(_selectAxis, 0, 30000); while ((APS168.APS_motion_status(_selectAxis) & (1 << 5)) == 0) //motionStatusMdn = 5 { Thread.Sleep(100); } }); }
public void MoveAbs(int x, int y) { //_selectAxis = Convert.ToInt32(cmbSelectAxis.SelectedItem); double praAcc = 1000000; double praDec = 1000000; int praVm = 1000; int pulseX = x; int pulseY = y; if (IsInitialed == false) { return; } APS168.APS_set_axis_param_f(_selectAxisX, (Int32)APS_Define.PRA_ACC, praAcc); // Set acceleration rate APS168.APS_set_axis_param_f(_selectAxisX, (Int32)APS_Define.PRA_DEC, praDec); // Set deceleration rate APS168.APS_set_axis_param_f(_selectAxisY, (Int32)APS_Define.PRA_ACC, praAcc); // Set acceleration rate APS168.APS_set_axis_param_f(_selectAxisY, (Int32)APS_Define.PRA_DEC, praDec); // Set deceleration rate //if (_card0.IsLoadXmlFile) { Task task = new Task(() => { APS168.APS_absolute_move(_selectAxisX, pulseX, praVm); APS168.APS_absolute_move(_selectAxisY, pulseY, praVm); //等待Motion Down完成 int motionStatusMdn = 5; while ((APS168.APS_motion_status(_selectAxisX) & 1 << motionStatusMdn) == 0 && (APS168.APS_motion_status(_selectAxisY) & 1 << motionStatusMdn) == 0) { Thread.Sleep(100); } }); task.Start(); } }
private void button7_Click(object sender, EventArgs e) { var boardId = Convert.ToInt32(txtCardId.Text); int motionStatusCstp = 0, motionStatusAstp = 16; APS168.APS_absolute_move(0, -220000, 50000); while ((APS168.APS_motion_status(0) & (1 << motionStatusCstp)) == 0) { Thread.Sleep(100); } if ((APS168.APS_motion_status(0) & (1 << motionStatusAstp)) == 0) { MessageBox.Show("轴" + "到位成功!"); } else { MessageBox.Show("轴" + "到位失败!"); } Thread.Sleep(500); APS168.APS_absolute_move(1, 30000, 10000); while ((APS168.APS_motion_status(1) & (1 << motionStatusCstp)) == 0) { Thread.Sleep(100); } if ((APS168.APS_motion_status(1) & (1 << motionStatusAstp)) == 0) { MessageBox.Show("轴" + "到位成功!"); } else { MessageBox.Show("轴" + "到位失败!"); } APS168.APS_absolute_move(2, 0, 10000); while ((APS168.APS_motion_status(2) & (1 << motionStatusCstp)) == 0) { Thread.Sleep(100); } if ((APS168.APS_motion_status(2) & (1 << motionStatusAstp)) == 0) { MessageBox.Show("轴" + "到位成功!"); } else { MessageBox.Show("轴" + "到位失败!"); } APS168.APS_absolute_move(1, -15000, 10000); //关闭触发 APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG_EN, 0); //TRG 0 ~ 3 enable by bit APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG_EN, Convert.ToInt32("0001", 2)); //Source Encoder0 APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TCMP0_SRC, 0); //Bi-direction(No direction) APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TCMP0_DIR, 1); //Trigger output 0 (TRG0) source Bit( 1:On, 0:Off) Bit 0: Manual Bit 1:Reserved Bit 2:TCMP0 Bit 3:TCMP1 Bit 4:LCMP0 Bit 5:LCMP1 APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG0_SRC, Convert.ToInt32("0100", 2)); //TRG1 pulse width APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG0_PWD, 1500); // pulse width= value * 0.02 us //TRG 1 logic 0: Not inverse 1:Inverse APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG0_LOGIC, 0); //add points to 1th //int[] xPoint = new int[] { 100000, 90000, 80000 }; var xPoint = new int[330]; var csvFile = new CsvReader("x1.csv"); var xTable = csvFile.ReadIntoDataTable(new[] { typeof(int) }); for (var i = 0; i < 330; i++) { xPoint[i] = Convert.ToInt32(xTable.Rows[i][0]); //表格行的数据 } APS168.APS_set_trigger_table(boardId, 0, xPoint, 330); }
private void btnLineTrigTest_Click(object sender, EventArgs e) { int motionStatusCstp = 0, motionStatusAstp = 16; var boardId = Convert.ToInt32(txtCardId.Text); var praAcc = Convert.ToDouble(txtPraAcc.Text); var praDec = Convert.ToDouble(txtPraDec.Text); APS168.APS_set_axis_param_f(0, (int)APS_Define.PRA_ACC, praAcc); // Set acceleration rate APS168.APS_set_axis_param_f(0, (int)APS_Define.PRA_DEC, praDec); // Set deceleration rate //回起始点 APS168.APS_absolute_move(0, -220000, 100000); APS168.APS_absolute_move(1, -15000, 100000); APS168.APS_absolute_move(2, 0, 10000); while ((APS168.APS_motion_status(0) & (1 << motionStatusCstp)) == 0) { Thread.Sleep(100); } if ((APS168.APS_motion_status(0) & (1 << motionStatusAstp)) == 0) { } APS168.APS_absolute_move(0, -62000, 50000); while ((APS168.APS_motion_status(0) & (1 << motionStatusCstp)) == 0) { Thread.Sleep(100); } if ((APS168.APS_motion_status(0) & (1 << motionStatusAstp)) == 0) { } //关闭触发 APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG_EN, 0); //TRG 0 ~ 3 enable by bit APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG_EN, Convert.ToInt32("0001", 2)); //Source Encoder0 APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TCMP0_SRC, 0); //Bi-direction(No direction) APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TCMP0_DIR, 1); //Trigger output 0 (TRG0) source Bit( 1:On, 0:Off) Bit 0: Manual Bit 1:Reserved Bit 2:TCMP0 Bit 3:TCMP1 Bit 4:LCMP0 Bit 5:LCMP1 APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG0_SRC, Convert.ToInt32("11000", 2)); //TRG1 pulse width APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG0_PWD, 2000); // pulse width= value * 0.02 us //TRG 1 logic 0: Not inverse 1:Inverse APS168.APS_set_trigger_param(boardId, (short)APS_Define.TGR_TRG0_LOGIC, 0); //重置触发计数 APS168.APS_reset_trigger_count(boardId, 0); APS168.APS_reset_trigger_count(boardId, 1); APS168.APS_set_trigger_linear(boardId, 0, -61000, 900, 11); APS168.APS_relative_move(0, 20000, 5000); //Int32 ptbId = 0; //Point table id 0 //Int32 dimension = 3; //2D point table //Int32 i = 0; //Int32 ret = 0; //int[] Axis_ID_Array = new int[] { 0, 1, 2 }; //PTSTS Status = new PTSTS(); //PTLINE Line = new PTLINE(); ////Enable point table //ret = APS168.APS_pt_disable(boardId, ptbId); ///////////////////////////ret = APS168.APS_pt_enable(boardId, ptbId, dimension, Axis_ID_Array); //ret = APS168.APS_pt_enable(boardId, ptbId, dimension, Axis_ID_Array); ////Configuration //ret = APS168.APS_pt_set_absolute(boardId, ptbId); //Set to absolute mode //ret = APS168.APS_pt_set_trans_buffered(boardId, ptbId); //Set to buffer mode //ret = APS168.APS_pt_set_acc(boardId, ptbId, 5000000); //Set acc //ret = APS168.APS_pt_set_dec(boardId, ptbId, 5000000); //Set dec //ret = APS168.APS_get_pt_status(boardId, ptbId, ref Status); //if ((Status.BitSts & 0x02) == 0) //Buffer is not Full //{ // Line.Dim = 3; // double Vslow = 300000; // { // PTDWL pwdell = new PTDWL(); // pwdell.DwTime = 2000; // //1st line // ret = APS168.APS_pt_set_vm(boardId, ptbId, Vslow); // ret = APS168.APS_pt_set_ve(boardId, ptbId, Vslow); // Line.Pos = new double[] { -218000, -22000, 50, 0, 0, 0 }; // ret = APS168.APS_pt_line(boardId, ptbId, ref Line, ref Status);//1段起始点 // APS168.APS_set_trigger_linear(boardId, 0, -72000, 900, 11); // double praAcc = Convert.ToDouble(txtPraAcc.Text); // double praDec = Convert.ToDouble(txtPraDec.Text); // APS168.APS_set_axis_param_f(1, (Int32)APS_Define.PRA_ACC, praAcc); // Set acceleration rate // APS168.APS_set_axis_param_f(1, (Int32)APS_Define.PRA_DEC, praDec); // Set deceleration rate // APS168.APS_relative_move(0, 20000, 100000); // } //} }
public override int MoveAbs(int cardId, int axisId, int pos, int vel) { return(APS168.APS_absolute_move(axisId, pos, vel)); }