2011年4月12日 星期二

利用LabVIEW擷取編碼器的資料(encoder)

最近剛好幫一個客戶做驗證,順便po上來跟大家分享。一般馬達通常都會有個編碼器(encoder)來量馬達的位置還有轉速(若不懂編碼器是什麼,請看這邊: 編碼器原理概論。) 要是馬達沒有編碼器的話,那我們也可以再額外加裝上去。台灣目前最常看到的兩家encoder廠商有企誠(www.honestsensor.com.tw)還有鴻璿(www.encoder.com.tw, 很好記吧),在他們網頁上會有很多各式各樣的encoder.

最近跟企誠買了一款encoder,決定用NI DAQ先給它測一下。因為NI DAQ的DIO還有counter都是5V TTL準位,所以挑選encoder的時候也記得要確認這個spec。另外也要看encoder本身需要的電源是幾伏特,這一款剛好是5V,所以可以直接拿DAQ上的5V輸出來供電給encoder。我用了一款NI USB-6212,蠻方便的。

Encoder連到DAQ示意圖:IMG_1182

接線很簡單: 紅(5V),黑(GND),綠和白為AB相位,分別接PFI0,PFI9 (這兩條是DAQ CTR0的input,我們就是要用counter來幫我們計數encoder的方波)IMG_1183

若是用LabVIEW的話,可以直接開一個現成DAQ的範例﹕Measure Angular Position.vi

IMG_1184

之後用手把encoder動一動,LabVIEW就會量到現在目前的角度啦! 

要用CompactRIO來做的話也是一樣,記得要用Digital Input或是DIO的模組(例如9411,9401),Scan Mode裡面可以直接選擇encoder輸入,把線接好相對應的接腳就可以了。

-John

2011年4月5日 星期二

Using an Bluetooth to RS-232 Converter for Robotics Use

Not much of an update this week, but we found something that can be really useful to us roboticists.  RS-232 is still a pretty standard interface among sensors for robotics.  In fact, much of the instrument drivers included in the LabVIEW Robotics Module are for RS-232 sensors (Hokuyo, Crossbow IMU, Garmin GPS etc.)  Well, what if you didn’t want to tether your sensor to your PC or CompactRIO?  Much like how you can replace ethernet with wifi, you can also replace tethered RS-232 with an off-the-shelf Bluetooth-RS232 converter.  Here’s a short video of us using this in a Hokuyo LIDAR setup.

If you are in the US, you can grab one of these converters off of sparkfun.com:

Bluetooth Modem - Roving Networks RS232

Once your bluetooth-equipped PC scans and finds this device, your PC adds an additional COM port to your device manager.  Run your RS-232 programs as before, and you will now have a wireless link to your RS-232 device.

A few things to note:

1. You can manipulate the Bluetooth converter to run at your specified baud rate.  Remember, the baud rate of the sensor, the BT converter, and the BT COM port on your PC all have to be the same.  However, we did notice slower data transfer, even at the same baud rate (running a Hokuyo LIDAR at 115.2kbps.)  Just like how wifi doesn’t actually achieve transfer speeds like regular ethernet, this BT converter will have an effect on your transfer speed as well.

2. This Sparkfun unit has a RS-232 driver built in, so you don’t need to add another voltage converter for RS-232.  See this tutorial to learn why you need a driver/voltage converter.

Seattle Robotics, Project: RS-232 to TTL cable

As always, keep your feedback coming!

-John