Esempio n. 1
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";
            }
        }
Esempio n. 2
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";
            }
        }
Esempio n. 3
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            int ret = 0;

            int[]    actualPos        = new int[TOTAL_AXIS];
            ushort[] actualState      = new ushort[TOTAL_AXIS];
            ushort[] actualStatusWord = new ushort[TOTAL_AXIS];

            for (int i = 0; i < mSlaveCnt; i++)
            {
                ret = NexCoeMotion.NEC_CoE402GetActualPosition(mAxisId[i], ref actualPos[i]);//讀取馬達實際位置
                if (ret != 0)
                {
                    Timer1.Enabled = false;
                    return;
                }

                ret = NexCoeMotion.NEC_CoE402GetState(mAxisId[i], ref actualState[i]);//讀取馬達狀態
                if (ret != 0)
                {
                    Timer1.Enabled = false;
                    return;
                }

                ret = NexCoeMotion.NEC_CoE402GetStatusWord(mAxisId[i], ref actualStatusWord[i]);//讀取CIA402狀態
                if (ret != 0)
                {
                    Timer1.Enabled = false;
                    return;
                }
            }
            for (int i = 0; i < mSlaveCnt; i++)
            {
                if (actualPos[i] >= 0)
                {
                    actualPos[i] = ((actualPos[i] % 129600) / 360);
                }
                else
                {
                    actualPos[i] = ((actualPos[i] % 129600) / 360) + 360;
                }
            }

            theta1 = (double)actualPos[0];
            theta2 = (double)actualPos[1];

            tb_ActualPos_0.Text  = Convert.ToString(actualPos[0]);
            tb_SlaveState_0.Text = Convert.ToString(actualState[0]);

            tb_ActualPos_1.Text  = Convert.ToString(actualPos[1]);
            tb_SlaveState_1.Text = Convert.ToString(actualState[1]);

            if ((actualStatusWord[0] & 1024) == 1024)
            {
                btn_Move_0.Text = "Move";
            }
            if ((actualStatusWord[1] & 1024) == 1024)
            {
                btn_Move_1.Text = "Move";
            }
        }