예제 #1
0
        public void motors_Init()                                  //电机初始化
        {
            canObj             = new canOpenObj();                 //实例化网络接口
            profileSettingsObj = new ProfileSettingsObj();         //实例化驱动器属性

            canObj.BitRate = CML_BIT_RATES.BITRATE_1_Mbit_per_sec; //设置CAN传输速率为1M/s
            canObj.Initialize();                                   //网络接口初始化

            ampObj         = new AmpObj[MOTOR_NUM];                //实例化四个驱动器(盘式电机)
            ampsettingsObj = new ampSettingsObj();
            ampsettingsObj.enableOnInit = true;
            ampsettingsObj.guardTime    = 1000;
            ampsettingsObj.lifeFactor   = 1000;
            for (int i = 0; i < MOTOR_NUM; i++)    //初始化四个驱动器
            {
                ampObj[i] = new AmpObj();
                //ampObj[i].Initialize(canObj, (short)(i + 1));
                ampObj[i].InitializeExt(canObj, (short)(i + 1), ampsettingsObj);
                ampObj[i].HaltMode      = CML_HALT_MODE.HALT_DECEL;                                //选择通过减速来停止电机的方式
                ampObj[i].CountsPerUnit = 1;                                                       //电机转一圈编码器默认计数25600次,设置为4后转一圈计数6400次
                userUnits[i]            = ampObj[i].MotorInfo.ctsPerRev / ampObj[i].CountsPerUnit; //用户定义单位,counts/圈
            }

            Linkage = new LinkageObj();
            Linkage.Initialize(ampObj);
            Linkage.SetMoveLimits(200000, 3000000, 3000000, 200000);

            motorsTimer          = new DispatcherTimer();
            motorsTimer.Tick    += new EventHandler(motorsTimer_Tick); //Tick是超过计时器间隔时发生事件,此处为Tick增加了一个叫ShowCurTimer的取当前时间并扫描串口的委托
            motorsTimer.Interval = TimeSpan.FromMilliseconds(100);;    //设置刻度之间的时间值,设定为1秒(即文本框会1秒改变一次输出文本)
            motorsTimer.Start();
        }
예제 #2
0
        public void motors_Init()//电机初始化
        {
            try
            {
                canObj             = new canOpenObj();         //实例化网络接口
                profileSettingsObj = new ProfileSettingsObj(); //实例化驱动器属性

                //canObj.BitRate = CML_BIT_RATES.BITRATE_500_Kbit_per_sec;
                canObj.BitRate = CML_BIT_RATES.BITRATE_1_Mbit_per_sec; //设置CAN传输速率为1M/s
                canObj.Initialize();                                   //网络接口初始化

                ampObj        = new AmpObj[MOTOR_NUM];                 //实例化四个驱动器(盘式电机)
                ampsetingsObj = new ampSettingsObj();

                ampsetingsObj.enableOnInit = true;
                ampsetingsObj.guardTime    = 2000; // 防止时间过长工控机电机失能
                //ampsetingsObj.heartbeatPeriod = 1000;
                //ampsetingsObj.heartbeatPeriod = 300;
                ampsetingsObj.lifeFactor = 1000;

                for (int i = 0; i < MOTOR_NUM; i++)//初始化四个驱动器
                {
                    ampObj[i] = new AmpObj();
                    //ampObj[i].Initialize(canObj, (short)(i + 1));
                    ampObj[i].InitializeExt(canObj, (short)(i + 1), ampsetingsObj);
                    ampObj[i].HaltMode      = CML_HALT_MODE.HALT_DECEL;                                //选择通过减速来停止电机的方式
                    ampObj[i].CountsPerUnit = 1;                                                       //电机转一圈编码器默认计数25600次,设置为4后转一圈计数6400次
                    userUnits[i]            = ampObj[i].MotorInfo.ctsPerRev / ampObj[i].CountsPerUnit; //用户定义单位,counts/圈
                }


                //ampObj[0].PositionActual = -1;
                //ampObj[1].PositionActual = -2;
                //ampObj[2].PositionActual = -2;
                //ampObj[3].PositionActual = -1;

                Linkage            = new LinkageObj();
                linkageSettingsObj = new LinkageSettingsObj();
                linkageSettingsObj.moveAckTimeout = 2000;                // 代替WaitMoveDone
                //Linkage.Initialize(ampObj);
                Linkage.InitializeExt(ampObj, linkageSettingsObj);       //电机联动初始化
                Linkage.SetMoveLimits(200000, 3000000, 3000000, 200000); // 设置电机速度,加速度等极限值
                EventObj              = Linkage.CreateEvent(CML_LINK_EVENT.LINKEVENT_TRJDONE | CML_LINK_EVENT.LINKEVENT_MOVEDONE | CML_LINK_EVENT.LINKEVENT_ABORT, CML_EVENT_CONDITION.CML_EVENT_ANY);
                EventObj.EventNotify += new eventObj.EventHandler(EventObj_EventNotify);


                motorsTimer          = new DispatcherTimer();
                motorsTimer.Tick    += new EventHandler(motorsTimer_Tick); //Tick是超过计时器间隔时发生事件,此处为Tick增加了一个叫ShowCurTimer的取当前时间并扫描串口的委托
                motorsTimer.Interval = TimeSpan.FromMilliseconds(100);;    //设置刻度之间的时间值,设定为1秒(即文本框会1秒改变一次输出文本)
                motorsTimer.Start();
            }
            catch (Exception)
            {
                MessageBox.Show("驱动器初始化错误");
            }
        }
예제 #3
0
        ///////////////////////////////////////////////////////////////////////////////
        ///
        ///
        ///////////////////////////////////////////////////////////////////////////////
        private void Motor_Connect()
        {
            try
            {
                xAxisAmp = new AmpObj();

                //***************************************************
                //
                //  CANOpen Network
                //
                //***************************************************
                canOpen          = new canOpenObj(); // Set the bit rate to 1 Mbit per second
                canOpen.BitRate  = CML_BIT_RATES.BITRATE_1_Mbit_per_sec;
                canOpen.PortName = "copley0";        // Indicate that channel 0 of a Copley CAN card should be used
                ampSettings      = new ampSettingsObj();

                //***************************************************
                // Initialize the CAN card and network
                //***************************************************
                canOpen.Initialize();
                canOpen.ClearErrorFrameCounter();

                // CHANGE CAN Address -> based on settings
                //X_AXIS_CAN_ADDRESS = (short) X_AXIS_CAN_ADDRESS;                  // Sets CAN address to connect to


                //***************************************************
                //* Initialize the Amplifier (Stepnet)
                //***************************************************
                ampSettings.enableOnInit = true;
                xAxisAmp.InitializeExt(canOpen, X_AXIS_CAN_ADDRESS, ampSettings);
                xAxisAmp.ClearFaults();                                             // Clear Errors
                //xAxisAmp.StopGuarding();


                //***************************************************
                //* Create Event Handler for the Amplifier (Stepnet)
                //***************************************************
                xAxisEventObj              = xAxisAmp.CreateEvent(CML_AMP_EVENT.AMPEVENT_MOVE_DONE, CML_EVENT_CONDITION.CML_EVENT_ANY);
                xAxisEventObj.EventNotify += new eventObj.EventHandler(xAxisEventObj_EventNotify);


                motorConnect = true;                                                                // Motor Connected Successful
                motorButton.BackgroundImage = TeamMusclesAndMachine.Properties.Resources.Start_button;
            }
            catch (Exception ex)
            {
                motorButton.BackgroundImage = TeamMusclesAndMachine.Properties.Resources.Connect_button;
                //DisplayErrorPopup("Linear Actuator Error", "Connection to Stepnet failed. Check that device is " +
                //                                        "connected and CAN Channel selected is correct.");
            }
        }