基于PC與mpc014外置運(yùn)動控制卡的三軸運(yùn)動控制系統(tǒng) 摘要:采用PC和mpc014外置運(yùn)動控制卡作為控制系統(tǒng)的核心,控制三路步進(jìn)電機(jī)或伺服電機(jī)。PC發(fā)送指令給mpc014外置運(yùn)動控制卡,控制器信號輸出給步進(jìn)驅(qū)動器作高速運(yùn)動。可以定點(diǎn)運(yùn)動,直線插補(bǔ)和圓弧插補(bǔ),并能實時作邏輯處理。 1.引言 基于PC的運(yùn)動控制的應(yīng)用在國內(nèi)已有十幾年的歷史,通常運(yùn)動控制都需要用到PCI運(yùn)動控制卡,但PCI運(yùn)動控制卡價格高昂,使用復(fù)雜,插槽容易接觸不良,也不適合用筆記本電腦來編程調(diào)試。因此,本文采用基于RS485接口的mpc014外置運(yùn)動控制卡與PC構(gòu)成運(yùn)動控制系統(tǒng)。 mpc014外置運(yùn)動控制卡集成普通IO,模擬量輸出,步進(jìn)電機(jī)和伺服電機(jī)控制。具有如下特點(diǎn): ◆ RS485通訊,可多個控制器組網(wǎng)工作。 ◆ 7路光耦隔離輸入,9路光耦隔離晶體管集電極開路輸出。 ◆ 最大脈沖輸出頻率為2MHz,脈沖輸出使用脈沖+方向方式。 ◆ 二路0-10v模擬量輸出。 ◆ 輸入輸出口都帶有獨(dú)立指示燈。 ◆ 四軸獨(dú)立運(yùn)動控制,任意兩軸直線插補(bǔ),任意兩軸圓弧插補(bǔ)。 ◆ 每軸可設(shè)一路硬件回原點(diǎn),兩路電機(jī)信號輸出。 ◆ 在線運(yùn)行方式帶1000級指令緩存深度,指令先進(jìn)先出,控制器與PC端無需高速實時通訊。 ◆ 提供DLL動態(tài)鏈接函數(shù)庫,可用于Window2000/XP/7平臺二次開發(fā)。控制器僅有21條函數(shù)指令,使用簡單。 ◆ 單電源12V-24V直流供電。 ◆ 控制器體積小巧,可安裝于狹小空間。 2,系統(tǒng)硬件架構(gòu) 硬件系統(tǒng)由三部分構(gòu)成,如圖所示: (1) PC (2) mpc014外置運(yùn)動控制卡 (3) 電氣機(jī)械傳動部分 mpc014外置運(yùn)動控制卡采用24V電源供電,RS485通訊口A,B與PC通過USB轉(zhuǎn)485轉(zhuǎn)換器連接。X0,X1,X2可作為三路電機(jī)的原點(diǎn)信號,Y3,Y4為第1軸的脈沖和方向信號。Y5,Y6為第2軸的脈沖和方向信號。Y7,Y8為第3軸的脈沖和方向信號。 3,系統(tǒng)軟件設(shè)計 PC端軟件采用Visual Basic 6.0設(shè)計,操作系統(tǒng)為Microsoft Windows XP,首先將從官網(wǎng)下載的動態(tài)鏈接庫mpc.dll拷入系統(tǒng)文件夾,然后在模塊中對函數(shù)作聲明。如下: Public Declare Function inp_move Lib "mpc" (cardno As Byte, no1 As Byte, no2 As Byte, pulse1 As Long, pulse2 As Long, mode As Byte) As Byte '二軸直線插補(bǔ) Public Declare Function inp_arc Lib "mpc" (cardno As Byte, no1 As Byte, no2 As Byte, X As Long, y As Long, i As Long, j As Long, mode As Byte) As Byte '二軸圓弧插補(bǔ) Public Declare Function set_speed Lib "mpc" (cardno As Byte, axis As Byte, acc As Long, dec As Long, startv As Long, speed As Long) As Byte '設(shè)置軸速度 Public Declare Function set_soft_limit Lib "mpc" (cardno As Byte, axis As Byte, mode As Byte, pulse1 As Long, pulse2 As Long) As Byte '設(shè)置軸軟件限位 Public Declare Function pmove Lib "mpc" (cardno As Byte, axis As Byte, pulse As Long, mode As Byte) As Byte '單軸運(yùn)行 Public Declare Function wait_delay Lib "mpc" (cardno As Byte, value As Integer) As Byte '等待延時數(shù) Public Declare Function set_command_pos Lib "mpc" (cardno As Byte, axis As Byte, value As Long) As Byte '設(shè)置軸邏輯位置 Public Declare Function wait_pulse Lib "mpc" (cardno As Byte, axis As Byte, value As Long) As Byte '等待軸脈沖數(shù) Public Declare Function write_bit Lib "mpc" (cardno As Byte, number As Byte, value As Byte) As Byte '寫輸出口狀態(tài) Public Declare Function sudden_stop Lib "mpc" (cardno As Byte, axis As Byte) As Byte '軸停止 Public Declare Function wait_in Lib "mpc" (cardno As Byte, number As Byte, value As Byte) As Byte '等待輸入口狀態(tài) Public Declare Function read_bit Lib "mpc" (cardno As Byte, number As Byte) As Byte '讀取輸入口狀態(tài) Public Declare Function get_out Lib "mpc" (cardno As Byte, number As Byte) As Byte '獲取輸出口狀態(tài) Public Declare Function wait_stop Lib "mpc" (cardno As Byte, axis As Byte) As Byte '等待軸停止 Public Declare Function set_da Lib "mpc" (cardno As Byte, number As Byte, value As Integer) As Byte '設(shè)置DA電壓值 Public Declare Function get_number Lib "mpc" (cardno As Byte) As Long '獲取唯一序列號 Public Declare Function read_fifo_count Lib "mpc" (cardno As Byte) As Integer '讀剩下緩沖數(shù)目 Public Declare Function get_status Lib "mpc" (cardno As Byte) As Byte '獲取各軸工作狀態(tài) Public Declare Function get_command_pos Lib "mpc" (cardno As Byte, axis As Byte) As Long '獲取軸邏輯位置 Public Declare Function set_cardno Lib "mpc" (cardno As Byte) '設(shè)置卡號 Public Declare Function link Lib "mpc" () As Byte '通訊連接 Public Declare Function no_link Lib "mpc" () As Byte '取消連接 使用函數(shù)前先確保PC與控制器物理連接正常,然后使用link函數(shù)連接通訊,如成功便可發(fā)送其它指令了。 試驗程序如下: If link () =1 then '通訊連接成功 call set_cardno(1) '設(shè)卡號為1 call set_speed(1 ,1,1000,1000,10,200) ' 設(shè)1軸速度 call set_speed(1 ,2,1000,1000,10,200) ' 設(shè)2軸速度 call set_speed(1 ,3,1000,1000,10,200) '設(shè)3軸速度 '1軸回原點(diǎn) call pmove(1,1,-1000000,0) ' 1軸運(yùn)動 call wait_in(1,0,1) ' 等待X0為高 call sudden_stop(1,1) ' 1軸停止 call set_command_pos(1,1,0) ' 設(shè)1軸此時坐標(biāo)為0 call pmove(1,2,3200,0) '2軸運(yùn)動 call pmove(1,3,-3200,0) '3軸運(yùn)動 end if 4,結(jié)束語 PC和mpc014外置運(yùn)動控制卡構(gòu)成的運(yùn)動控制系統(tǒng),運(yùn)動控制器只需使用485接口與PC通信,只需使用幾條簡單的指令便可完成運(yùn)動控制過程,大大降低運(yùn)動控制系統(tǒng)的設(shè)計調(diào)試難度,大大提高運(yùn)動控制系統(tǒng)的穩(wěn)定性,對快速可靠構(gòu)建運(yùn)動控制系統(tǒng)具有很大意義。 本文來自泰安迪科技:www.mpc000.com 轉(zhuǎn)載請注明出處。 |