Exemplo n.º 1
0
        private void RunLoop(int a, int b)
        {
            int ret = 0;


            mTargetPos[0] = a;
            mVelocity[0]  = Convert.ToUInt32(tb_Vel_0.Text);
            mAccDec[0]    = Convert.ToUInt32(tb_AccDec_0.Text);
            mTargetPos[1] = b;
            mVelocity[1]  = Convert.ToUInt32(tb_Vel_1.Text);
            mAccDec[1]    = Convert.ToUInt32(tb_AccDec_1.Text);

            int[] actualPos = new int[TOTAL_AXIS];
            ret = NexCoeMotion.NEC_CoE402GetActualPosition(mAxisId[0], ref actualPos[0]);//讀取馬達實際位置
            if (ret != 0)
            {
                MessageBox.Show("transform failed");
            }
            ret = NexCoeMotion.NEC_CoE402GetActualPosition(mAxisId[1], ref actualPos[1]);//讀取馬達實際位置
            if (ret != 0)
            {
                MessageBox.Show("transform failed");
            }
            int realactualPos0 = actualPos[0];
            int realactualPos1 = actualPos[1];

            if (actualPos[0] >= 0)
            {
                actualPos[0] = ((actualPos[0] % 129600) / 360);
            }
            else
            {
                actualPos[0] = ((actualPos[0] % 129600) / 360) + 360;
            }

            mTargetPos[0] = (mTargetPos[0] - actualPos[0]) * 360 + realactualPos0;

            if (actualPos[1] >= 0)
            {
                actualPos[1] = ((actualPos[1] % 129600) / 360);
            }
            else
            {
                actualPos[1] = ((actualPos[1] % 129600) / 360) + 360;
            }

            mTargetPos[1] = (mTargetPos[1] - actualPos[1]) * 360 + realactualPos1;

            if (button3.Text == "Move")
            {
                ret = NexCoeMotion.NEC_CoE402Halt(mAxisId[0], 0);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402Halt failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402PtpA(mAxisId[0], 0, mTargetPos[0], mVelocity[0], mAccDec[0], mAccDec[0]);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402PtpA failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402Halt(mAxisId[1], 0);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402Halt failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402PtpA(mAxisId[1], 0, mTargetPos[1], mVelocity[1], mAccDec[1], mAccDec[1]);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402PtpA failed" + ret.ToString()); return;
                }
            }
            else
            {
                ret = NexCoeMotion.NEC_CoE402Halt(mAxisId[0], 1);//移動終止
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402Halt failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402Halt(mAxisId[1], 1);//移動終止
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402Halt failed" + ret.ToString()); return;
                }
                button3.Text = "Move";
            }
        }
Exemplo n.º 2
0
        private void MoveFunc(int ID)
        {
            int ret = 0;

            TextBox tb_targetPos;
            TextBox tb_velocity;
            TextBox tb_acc;
            Button  btn_move;
            Button  btn_startMove;

            if (ID == 0)
            {
                tb_targetPos  = tb_TargetPos_0;
                tb_velocity   = tb_Vel_0;
                tb_acc        = tb_AccDec_0;
                btn_move      = btn_Move_0;
                btn_startMove = btn_ServoOn_0;
            }
            else
            {
                tb_targetPos  = tb_TargetPos_1;
                tb_velocity   = tb_Vel_1;
                tb_acc        = tb_AccDec_1;
                btn_move      = btn_Move_1;
                btn_startMove = btn_ServoOn_1;
            }

            if (btn_startMove.Text == "Servo on")
            {
                MessageBox.Show("Please Servo on first!!");
                return;
            }

            mTargetPos[ID] = Convert.ToInt32(tb_targetPos.Text);
            mVelocity[ID]  = Convert.ToUInt32(tb_velocity.Text);
            mAccDec[ID]    = Convert.ToUInt32(tb_acc.Text);

            int[] actualPos = new int[TOTAL_AXIS];
            ret = NexCoeMotion.NEC_CoE402GetActualPosition(mAxisId[ID], ref actualPos[ID]);//讀取馬達實際位置
            if (ret != 0)
            {
                MessageBox.Show("transform failed");
            }

            int realactualPos = actualPos[ID];

            if (actualPos[ID] >= 0)
            {
                actualPos[ID] = ((actualPos[ID] % 129600) / 360);
            }
            else
            {
                actualPos[ID] = ((actualPos[ID] % 129600) / 360) + 360;
            }
            mTargetPos[ID] = (mTargetPos[ID] - actualPos[ID]) * 360 + realactualPos;

            if (btn_move.Text == "Move")
            {
                ret = NexCoeMotion.NEC_CoE402Halt(mAxisId[ID], 0);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402Halt failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402PtpA(mAxisId[ID], 0, mTargetPos[ID], mVelocity[ID], mAccDec[ID], mAccDec[ID]);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402PtpA failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402WaitTargetReached(mAxisId[ID]);

                btn_move.Text = "Stop";
            }
            else
            {
                ret = NexCoeMotion.NEC_CoE402Halt(mAxisId[ID], 1);//移動終止
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402Halt failed" + ret.ToString()); return;
                }
                btn_move.Text = "Move";
            }
        }