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(); }
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("驱动器初始化错误"); } }
/////////////////////////////////////////////////////////////////////////////// /// /// /////////////////////////////////////////////////////////////////////////////// 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."); } }
private void Motor_Connect() { try { short tempAddress; 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; // Indicate that channel 0 of a Copley CAN card should be used canOpen.PortName = "copley0"; //*************************************************** //* Initialize the CAN card and network //*************************************************** canOpen.Initialize(); X_AXIS_CAN_ADDRESS = (short)getCANChannel(); //*************************************************** //* Initialize the Amplifier (Stepnet) //*************************************************** xAxisAmp.Initialize(canOpen, X_AXIS_CAN_ADDRESS); //************************************** //* Clear Errors //************************************** xAxisAmp.ClearFaults(); xAxisAmp.Disable(); //*************************************************** //* 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); } catch (Exception ex) { DisplayErrorPopup("Linear Actuator Error", "Connection to Stepnet failed. Check that device is " + "connected and CAN Channel selected is correct."); } }
private void MotorForm_Load(object sender, EventArgs e) { try { //Initialize code here xAxisAmp = new AmpObj(); //*************************************************** // // CANOpen Network // //*************************************************** canOpen = new canOpenObj(); // //************************************************************************** //* The next two lines of code are optional. If no bit rate is specified, //* then the default bit rate (1 Mbit per second) is used. If no port name //* is specified, then CMO will use the first supported CAN card found and //* use channel 0 of that card. //************************************************************************** // Set the bit rate to 1 Mbit per second canOpen.BitRate = CML_BIT_RATES.BITRATE_1_Mbit_per_sec; // Indicate that channel 0 of a Copley CAN card should be used canOpen.PortName = "copley0"; //*************************************************** //* Initialize the CAN card and network //*************************************************** canOpen.Initialize(); //*************************************************** //* Initialize the amplifier //*************************************************** xAxisAmp.Initialize(canOpen, X_AXIS_CAN_ADDRESS); // Read velocity loop settings from the amp, use these as reasonble starting // points for the trajectory limits. VelocityTextBox.Text = Convert.ToString((xAxisAmp.VelocityLoopSettings.VelLoopMaxVel) / 10); AccelTextBox.Text = Convert.ToString((xAxisAmp.VelocityLoopSettings.VelLoopMaxAcc) / 10); DecelTextBox.Text = Convert.ToString((xAxisAmp.VelocityLoopSettings.VelLoopMaxDec) / 10); // Initialize home object with amplifier home settings Home = xAxisAmp.HomeSettings; } catch (Exception ex) { DisplayError(ex); } }
public void Form1_Load(object sender, EventArgs e) { try { //Initialize code here xAxisAmp = new AmpObj(); ProfileSettings = new ProfileSettingsObj(); //*************************************************** // // CANOpen Network // //*************************************************** canOpen = new canOpenObj(); // //************************************************************************** //* The next two lines of code are optional. If no bit rate is specified, //* then the default bit rate (1 Mbit per second) is used. If no port name //* is specified, then CMO will use the first supported CAN card found and //* use channel 0 of that card. //************************************************************************** // Set the bit rate to 1 Mbit per second canOpen.BitRate = CML_BIT_RATES.BITRATE_1_Mbit_per_sec; // Indicate that channel 0 of a Copley CAN card should be used canOpen.PortName = "copley1"; //// Indicate that channel 0 of a KVaser card should be used //canOpen.PortName = "kvaser0"; //// Indicate that channel 0 of an IXXAT card should be used //canOpen.PortName = "IXXAT0"; //// Indicate that channel 0 of an IXXAT card (V3.x or newer drivers) should be used //canOpen.PortName = "IXXATV30"; //*************************************************** //* Initialize the CAN card and network //*************************************************** canOpen.Initialize(); //*************************************************** //* Initialize the amplifier //*************************************************** xAxisAmp.Initialize(canOpen, X_AXIS_CAN_ADDRESS); //Code to replace vb handle statements JogPosButton.MouseUp += JogPosButton_MouseUp; JogPosButton.MouseDown += JogPosButton_MouseDown; JogNegButton.MouseUp += JogNegButton_MouseUp; JogNegButton.MouseDown += JogNegButton_MouseDown; //*************************************************** //* //* EtherCAT Network //* //*************************************************** //ecatObj = new EcatObj(); // //*************************************************** //* The next line of code is optional. The port name is the IP address of //* the Ethernet adapter. Alternatively, a shortcut name “eth” can be used //* in conjunction with the adapter number. For example “eth0” for the first //* Ethernet adapter, “eth1” for the second adapter. If no port name is //* supplied, it will default to “eth0”. //************************************************************************** //// Indicate that the first Ethernet adapter is to be used //ecatObj.PortName = "eth0"; //// Specify an IP address //ecatObj.PortName = "192.168.1.1"; // //*************************************************** //* Initialize the EtherCAT network //*************************************************** //ecatObj.Initialize(); // //*************************************************** //* Initialize the amplifier //*************************************************** //xAxisAmp.InitializeEcat(ecatObj, ECAT_NODE); // // Read velocity loop settings from the amp, use these as reasonble starting // points for the trajectory limits. VelocityTextBox.Text = Convert.ToString((xAxisAmp.VelocityLoopSettings.VelLoopMaxVel) / 10); AccelTextBox.Text = Convert.ToString((xAxisAmp.VelocityLoopSettings.VelLoopMaxAcc) / 10); DecelTextBox.Text = Convert.ToString((xAxisAmp.VelocityLoopSettings.VelLoopMaxDec) / 10); // Initialize home object with amplifier home settings Home = xAxisAmp.HomeSettings; Timer1.Start(); } catch (Exception ex) { DisplayError(ex); } }