Ejemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < mSlaveCnt; i++)
     {
         NexCoeMotion.NEC_CoE402Home(mAxisId[i], 0);
     }
 }
Ejemplo n.º 2
0
        private void ServoOn(int ID)
        {
            if (btn_StartNetwork.BackColor != Color.YellowGreen)
            {
                MessageBox.Show("Please start network first!!");
                return;
            }

            int ret = 0;

            Button btn_startMove;
            Button btn_move;

            if (ID == 0)
            {
                btn_startMove = btn_ServoOn_0;
                btn_move      = btn_Move_0;
            }
            else
            {
                btn_startMove = btn_ServoOn_1;
                btn_move      = btn_Move_1;
            }

            if (btn_startMove.Text == "Servo on")
            {
                ret = NexCoeMotion.NEC_CoE402SetOperationMode(mAxisId[ID], 1, 5000);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402SetOperationMode failed" + ret.ToString()); return;
                }

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

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

                btn_startMove.Text = "Servo off";
            }
            else
            {
                ret = NexCoeMotion.NEC_CoE402ServoOn(mAxisId[ID], 0);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_CoE402ServoOn failed" + ret.ToString()); return;
                }

                btn_startMove.Text = "Servo on";
                btn_move.Text      = "Move";
            }
        }
Ejemplo n.º 3
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";
            }
        }
Ejemplo n.º 4
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";
            }
        }
Ejemplo n.º 5
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";
            }
        }
Ejemplo n.º 6
0
        private void btn_startNetwork_Click(object sender, EventArgs e)
        {
            int ret = 0;

            if ((tb_EniPath.Text == null) || (tb_EniPath.Text == ""))
            {
                MessageBox.Show("Please load ENI first");
                return;
            }

            if (btn_StartNetwork.BackColor != Color.YellowGreen)
            {
                ret = NexECM.NEC_StartDriver();//初始化函式庫
                if (ret != 0)
                {
                    MessageBox.Show("NEC_StartDriver failed" + ret.ToString()); return;
                }

                ret = NexECM.NEC_ResetEcMaster(MASTER_ID);//重置EC-Master
                if (ret != 0)
                {
                    MessageBox.Show("NEC_ResetEcMaster failed" + ret.ToString()); return;
                }

                ret = NexECM.NEC_SetParameter(MASTER_ID, 0, 1000);//設定EC-Master參數
                if (ret != 0)
                {
                    MessageBox.Show("NEC_SetParameter failed" + ret.ToString()); return;
                }

                ret = NexCoeMotion.NEC_CoE402Reset();//重置函式庫
                if (ret != 0)
                {
                    MessageBox.Show("NexCoeMotion failed" + ret.ToString()); return;
                }

                ret = NexECM.NEC_StartNetworkEx(MASTER_ID, mEniPath, 1, 5000);//啟動EC-Master
                if (ret != 0)
                {
                    MessageBox.Show("NEC_StartNetworkEx failed" + ret.ToString()); return;
                }

                ret = NexECM.NEC_GetSlaveCount(MASTER_ID, ref mSlaveCnt);//讀取線上EC-Slaves數量(2)
                if (ret != 0)
                {
                    MessageBox.Show("NEC_GetSlaveCount failed" + ret.ToString()); return;
                }


                if (TOTAL_AXIS != mSlaveCnt)
                {
                    MessageBox.Show("Please check ENI file and TOTAL_AXIS value!!");
                    return;
                }

                for (ushort i = 0; i < mSlaveCnt; i++)
                {
                    ret = NexCoeMotion.NEC_CoE402GetAxisId(MASTER_ID, i, ref mAxisId[i]);//讀取驅動器ID
                    if (ret != 0)
                    {
                        MessageBox.Show("NEC_CoE402GetAxisId failed" + ret.ToString()); return;
                    }

                    ret = NexCoeMotion.NEC_CoE402UpdatePdoMapping(mAxisId[i]);//更新PDO設定
                    if (ret != 0)
                    {
                        MessageBox.Show("NEC_CoE402UpdatePdoMapping failed" + ret.ToString()); return;
                    }

                    ret = NexCoeMotion.NEC_CoE402FaultReset(mAxisId[i], 5000);//清除重製驅動器錯誤
                    if (ret != 0)
                    {
                        MessageBox.Show("NEC_CoE402FaultReset failed" + ret.ToString()); return;
                    }
                }

                btn_StartNetwork.BackColor = Color.YellowGreen;
                Timer1.Enabled             = true;  //?
                btn_StartNetwork.Text      = "Stop Network";
                btn_Browse.Enabled         = false; //?
            }
            else
            {
                Timer1.Enabled = false;//?

                for (int i = 0; i < mSlaveCnt; i++)
                {
                    ret = NexCoeMotion.NEC_CoE402ServoOn(mAxisId[i], 0);//設定驅動器消磁(disable)
                    if (ret != 0)
                    {
                        MessageBox.Show("NEC_CoE402ServoOn diaable failed" + ret.ToString()); return;
                    }
                }

                btn_ServoOn_0.Text = "Servo on";
                btn_Move_0.Text    = "Move";

                btn_ServoOn_1.Text = "Servo on";
                btn_Move_1.Text    = "Move";

                ret = NexECM.NEC_StopNetwork(MASTER_ID, 5000);
                if (ret != 0)
                {
                    MessageBox.Show("NEC_StopNetwork failed" + ret.ToString()); return;
                }

                ret = NexECM.NEC_StopDriver();
                if (ret != 0)
                {
                    MessageBox.Show("NEC_StopDriver failed" + ret.ToString()); return;
                }

                btn_StartNetwork.Text      = "Start Network";
                btn_StartNetwork.BackColor = Color.WhiteSmoke;
                btn_Browse.Enabled         = true;
            }
        }