Friday, November 28, 2008

低廉智慧型載具 By 正修科大



經三年研發,高雄縣正修科技大學與陸軍官校完成「智慧型載具」(機器人),造價較外國低廉,且可擴充功能,成為軍事、化學災害、災區生命探測的利器。 這輛總重 110公斤的機器人以電動馬達驅動履帶行走,裝置機械手臂。電子系助理教授張法憲表示,機器人以無線遙控,加裝監視器,履帶讓機器人可行走在各種路面或爬坡,有效遙控距離 800公尺,機械手臂可夾帶30公斤的物品,可移除爆裂物;可加裝偵測系統,成為災區生命探測、掃除地雷、危險彈藥搬運等工具,甚至職災時將受傷民眾拖離災區;如加裝太陽能板與蓄電池、「主動式保全系統」,可成為全天候保全巡護系統。

  張法憲表示,這部機器人造價新台幣 200多萬元,比軍方、警方自國外購置移除爆裂物機器人約新台幣700 萬元低廉。


Wednesday, October 22, 2008

創新應用整合案例-視覺型火災偵測系統三秒內緊急通報

火災只要發現得早,便可以及時撲滅,相對的,人們的生命財產損失將可降低許多;因此正確、即時通報的警示系統,一直是消防安全產業的重要課題,也是智慧化居住空間產業在安全監控方面所注重的相關應用。「火」雖然為人類生活帶來便利,但若不謹慎控制使用,也會對民眾帶來極大的威脅。根據內政部消防署的統計,在民國95年因火災所造成的財產損失約為新台幣15.58億元,但不可計數的是對受創家庭的影響與傷痛;若能在第一時間,對足以燎原的星星之火提出警示,將可大幅減少生命財產的損失。工研院能源與環境研究所經過二年多的不斷研發,開發出視覺型火災偵測系統(Video Fire Detection System, VFDS)

Wednesday, October 08, 2008

混合義肢的機器人裝


日商 Cyberdyne 公司七日展示一套名為 HAL(混合義肢)的機器人裝,該公司計畫自十日起以二千二百美元的月費出租給有需要的殘障人士和老年人。圖為廠商在展示會場詳細介紹機器人裝的配備和性能。(法新社)

Tuesday, September 30, 2008

自行車機器人即將上路


亞洲最大的消費電子展CEATEC三十日在日本千葉縣(Chiba)正式開幕,為期五天的展覽中,展出許多電子大廠最新的產品發明與設計。圖為日本的電子元件大廠村田製作所(Murata Electronics)推出的自行車機器人,擁有微小感測器來保持機體平衡,特殊新穎的設計吸引不少人的目光。(法新社)

Friday, September 26, 2008

會騎獨輪車的機器人小妹妹亮相


日本業者村田製造(Murata Manufacturing),開發出了一款名為「村田小妹(Murata Girl)」、騎著獨輪車的機器人;這款機器人配備了陀螺儀感測器、藍牙,以及超音波等功能,能垂直站立或是四處移動。

這款機器人採用了多個村田自有的元件,包括用以在電路儲存電力的電容器、控制運動的感測器,以及跟外接交換資訊的通訊模組。該公司表示,由於有感於日本兒童對於科學的興趣日漸低落,該公司過去曾推出過一款騎著腳踏車的「村田頑童(Murata Boy)」機器人,並主動聯繫各學校提供教育機會,藉由展示該機器人讓學童們知道科學有多麼好玩。

新誕生的「村田小妹」外觀與個性是由一個女性成員組成的團隊負責設計,得克服機器人騎著獨輪車維持平衡與移動的挑戰,並讓它利用一顆超音波感測器來與週遭物體保持距離,同時透過一具實況攝影機來傳送移動的影像。

嬌小的「村田小妹」高50公分、體重5公斤,使用兩個陀螺儀感測器發出的訊號來偵測機器人的傾斜角度,以協助控制獨輪車該前進或後退;在其軀幹部並裝置了一個飛輪(fly wheel),用以監測機器人的兩側,好維持左右平衡。

「村田小妹」身上的一對收/發超音波感測器,能透過訊號發出與彈回的時間,來偵測自己與障礙物間的距離。外界指令以及各種資料的接收/發送,則是透過行動終端設備與PC,使用2.45GHz無線頻段來傳遞。它還配備多款村田自家的通用電子元件,包括晶片陶瓷電容、Ceralock陶瓷振盪器、測溫度用的NTC電熱感測器、電位計,以及雜訊抑制濾波器等。

村田製造並提供了“非常多”有關「村田小妹」的詳細資料,說她是「村田頑童」的小堂妹,生日是9月23日,出生於日本滋賀縣,目前唸幼稚園中班,而個性是「天生好動又怕羞」。

Thursday, September 25, 2008

日本的本田汽車二十四日在東京國際家庭護理康復展中,發表了一款針對老人和腿部肌肉力量薄弱的患者,所研發的步行輔助器模型,這項輔助器配備有角度感應器以及驅動器,重量二千八百公克。目前這項設備已經開始提供給日本醫院中的老人們測試使用。(法新社)

Monday, July 14, 2008

Using the KMPlayer to convert the asf/wmv format to vfw avi.


1. Import the *.tiff file format to windows Movie Maker.
2. Transfer the required *.tif file to the windows wmv format.
3. Open the KMPlaer.
4. Select the video capture (Alt+C) to set the format setting.
5. choose the "*.avi (VFW)".
6. Then use the OpenCv "cvCaptureFromFile" to play the produced files.

Wednesday, May 28, 2008

Writing a Transform Filter

This is a Visual C++ 6.0 appwizard. It will help to create default transform (or In-Place Transform) filter for video processing using DirectShow (part of Microsoft DirectX); It can be easily changed to do audio processing as well. To use the wizard, download the (DShowFilterWiz.awx and DShowFilterWiz.HLP) and copy them to C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Template. You can select "DirectShow Filter AppWizard" when you new a project in VC 6.0. Specify the project name and click "ok" to generate the project.
http://www.ifp.uiuc.edu/~chenyq/research/Utils/DShowFilterWiz/DShowFilterWiz.html

Wednesday, May 14, 2008

ASIMO


日本本田公司的智慧型機器人ASIMO十三日化身樂團指揮,帶領底特律交響樂團演奏「Impossible Dream」,華裔大提琴演奏家馬友友也同台演出,見證首位機器人登上音樂殿堂的紀錄。ASIMO不僅能適應高低起伏的地形活動自如,更能接受人類簡單的 口頭指令。雖然ASIMO僅能以預先錄製的影帶學會指揮技巧,而無法與樂團成員互動,但已是機器人科技的一大進展。圖為馬友友於演奏結束後與ASIMO握 手,並俏皮地嘟起嘴巴假裝獻吻。(美聯社)

Monday, May 05, 2008

高速視覺技術及三指機械手介紹


大多數的智慧型機器人均具備有許多的環境感測技術,例如使用超音波或者雷射來進行障礙物偵測,使用微波或者
GPS 技術來進行定位以及利用視覺技術來分辨目標物等;隨著機器人產品的發展愈趨複雜,因此對於機器人互動技術的規格要求也愈來愈高。高速視覺技術已經被視為未 來應用在機器人上最主要的環境感測技術,透過高速視覺技術可以快速地協助機器人定出空間位置、瞭解周遭環境與物體以及即時監控環境當中之異常事件等。

在本期文章我們將深入介紹由日本東京大學石川正俊教授所領導的研究團隊,針對目前廣泛應用在服務用以及產業用機器人之高速視覺技術的研究成果與由HarmonicDrive所發展的輕量型高速三指機械手,以及兩者結合之應用實例。

何謂高速視覺?

  日本科學未來館當中展示了一組智慧型的機械手,該手臂搭配一雙眼睛就可以快速抓住任何丟向它的球或其他形狀之物體(如圖1)。普榮獲2007年機器人大獎賽冠軍的裝箱抓取機械手臂(如圖2),透過三支機械手臂可以快速的抓取於輸送帶中移動的任何商品,並精準地放置於包裝箱中。

此外,Fanuc以及Denson等傳統機械手臂生產大廠不約而同的在2007年日本機器人展當中推出可以附加於機械手臂上之高速視覺模組,使傳統機械手臂的應用因為加入的視覺技術而更有智慧,未來的機械手臂將可自行判斷物體形狀、大小以及外觀,然後自動的抓取物品,搬移到目標位置。

1 結合高速視覺模組之機械手(展示於日本科學未來館中)

2 抓取裝箱機械手臂

  高速視覺技術(High Speed Vision Technology)就是這一隻手(手臂)的眼睛,透過每一秒鐘高達1000張圖片的抓取與高速的運算分析,就可以快速的掌握到移動或者靜止的分散物體,分析它的移動路徑、形狀以及大小,進而判斷其立體空間座標而驅動運動機構去作抓取與搬運動作。

高速視覺介紹

  影像處理技術必須透過感光、影像傳輸、成像、合成等過程,並經由後端處理器進行影像壓縮與檔案後處理作業,除了資料的傳輸量大之外,還需要大量的處理器運算資源做影像處理。高速影像技術乃是利用FPGA(Field Programmable Gate Array)做為核心控制處理架構並結合高速傳輸介面,以及FPGA的高速運算能力,可重複規劃等數位訊號處理之優越性,配合動態影像的取得以及同步動態隨機存取記憶體(Synchronous Dynamic RamSDRAM)所發展而成。

  日本東京大學石川正俊教授針對機器人的環境感測技術進行許多研究,其中最重要的研究成果便是發展「高速視覺晶片」(High Speed Vision Chip),將影像感測模組與數位處理元件整合於一片積體電路當中,同時利用第二級FPGA處理器架構(Secondary FPGA)強化了原本單一晶片的運算限制,並提供平行計算演算法,使得多的處理器得以同時運算大幅提昇運算技術能力,也因此得以每一秒鐘擷取超過1000張影像之能力。

3 高速視覺晶片

4 高速視覺晶片架構

  傳統的影像處理速度一般都只有到30~100 frames/sec,處理速度雖不夠快,但用在一般3C產品上已經足夠;然而若要將視覺技術應用於機器人的感測上,若影像擷取速度不夠快的話,對於快速 移動的物體並無法及時偵測到,也無法瞭解到其移動路徑,會因而降低機器人對外在環境之反應力。石川教授的高速視覺晶片,因可以在每一秒鐘擷取高達1000 張影像(這樣的速度已經超越人類眼睛),因此透過影像與影像之間的分析與比對之後,便可即時掌握物體的移動、空間的辨識等。

機械手介紹

  本次所參觀之東京大學石川實驗室當中,在結合高速視覺技術部分應用到了許多由HarmonicDrive所開發的三指擬人機械手(如圖5)。該機械手每一手指具有兩個自由度,可以作兩個關節的彎曲,並且在手指與手指之間還有一個自由度可以作兩個手指的開合動作。

5 HarmonicDrive三指機械手

  HarmonicDrive在手指部分主要以兩種制動器做為關節驅動部分,包含RSF-38-100以及RSF-5A-50等,兩者分別使用1/100以及1/50的減速比提升其輸出扭力,末端最大出力為0.3Nm(牛頓米)。

6 Harmonic Drive手指模組機構示意圖

  HarmonicDrive三指機械手機構不論在轉速或扭力的表現上,已經超越目前業界水準,且整隻手的應用涵蓋範圍也很廣,包括物品夾持、簡易工具操作等,在正式的實驗當中,使用HarmonicDrive機構手已經可以做出以下動作:

  目前大部分的擬人機器人多採用人工肌肉來完成手部動作,其壽命有一定限制,且在速度以及扭力表現上均還無法達到與人相同之地步;因此,如HarmonicDrive所開發三指擬人機械手已經可以將傳統機械手的速度跟扭力拉升至與人相同,但在關節自由度的表現上,許多地方仍以同動方式為主,此外在指節末端關節處也無實現。因此,嚴格來說HarmonicDrive之三指機械手,仍無法與人類的手掌相比,因其對於更靈活之動作要求,目前是無法達到的。

  目前日本已有多所大學投入研發機械手計畫,包含本次在日本展覽當中看到由東京大學以線驅動方式開發之五指機械手;以及由產總研(AIST)所研發應用於HRP-3P之四指17個自由度之機械手,已經可以將機械手縮小到180mm,並達到15Nm之出力。

7 線驅動機械手

8 AIST全馬達驅動機械手

  除了日本外,各國在機械手的研發工作上一直都有成果,以下列出具代表性之研發成果:

DLR(德國宇航中心) II研發出四指擬人靈巧抓取的作業系統,每手指結構相同,各有4個關節和3自由度,另外在手掌內有一自由度,讓機器手能穩定的抓取和操作調整。DLR II機器手具有開關抽屜、操作設備以及使用工具等動作。

英國Shadow研發出24自由度五指的機器手,採用人工肌肉方式驅動,重量大約3.KgShadow機器手在指尖上裝有觸碰感測,允許在柔軟或脆弱的物體上使用。

日本Squse公司設計的機器手用21條人工肌肉牽動關節,能像人手一樣抓取物品及與人握手,它甚至能勝任包裝生雞蛋這樣的細緻工作。

高速視覺應用實例

  石川教授除了發展高速視覺技術之外,並利用此技術發展了相關應用技術,包含高速物體追蹤系統(High Speed Catching System)、目標物統計(Target Counting)、即時多目標物判斷(High Speed Based Moment Analysis of Numerous Object)、轉速測量(Rotation Measurement)、微細世界之視覺回饋系統(Microscopic Visual Feedback)等。

高速追蹤系統可以透過高速視覺技術來追蹤移動中之物體,並利用機械手將物體抓取到位。此外,利用機械手臂做棒球打擊等應用也屬於相同原理。

利用特徵分析與移動追蹤技術,可以在一個影像上分辨出多個目標物,並且同時偵測這些目標物之狀態改變。

利用高速視覺技術可以對移動中之物體做數量統計。譬如一盤流沙,以瀑布方式傾瀉而下經由高速視覺之判斷可以精準無誤地統計出該流沙有多少沙粒。

利用高速視覺技術針對一轉動之球面物品進行特徵分析,並藉由此特徵進一步分析出其轉速。

結合顯微鏡技術以及高速視覺技術,可以觀察到微細世界之狀態。

  石川教授所研發之高速影像處?系統的IC晶片,未?希望朝?快速及?有智慧性的方向研發,在應用上未來可朝向高速檢測儀器、生技醫?手術輔助、道?影像攝影、賽?終點判定、視覺介面、追蹤辨識系統等。

  此外,在產業應用上也已經有多款服務型與產業用機器人結合視覺技術,在2007日本機器人展當中已經有許多產業應用實例出現,包含有:

日本機械手臂大廠Fanuc於2007年正式推出結合視覺辨識模組之機械手臂,透過視覺技術,機械手臂可以在特定區域抓取散落之物品,而無須預先排定物品位置。並且可以透過視覺技術偵測物體形狀與大小以決定抓取方式,提供機械手臂更有彈性之應用。

Denson機械手臂結合三組CCD,可以呈現出多個目標物體之3D立體圖像,並回饋給機械手臂進行搬移。

日本生產技術株式會社利用視覺技術賦予機器人玩魔術方塊之技巧,該機器人可以透過視覺技術判斷目前方塊狀況,並進行推演然後透過兩隻機械手完成魔術方塊遊戲。

乒乓球機器人可以跟人一起打乒乓球。該款機器人利用視覺技術來追蹤乒乓球之移動路徑,然後在落點後將球回擊。

高速視覺之未來發展

  在本次的參訪當中,石川教授的高速視覺技術已經證明可以提供機器人或應用載具基本的環境感測功能,達到物體識別、移動追蹤、立體視覺等,且高速視覺技術在成本與速度上已經超越傳統的雷射掃描器,因此在近幾年吸引許多廠商投入研發。

  然而,視覺在感測的同時容易受到燈光之影響,而影響到判斷的精確度,進而造成誤判等嚴重疏失,而會有安全上之疑慮,未來必須倚賴更精密與更高速之變焦技術來解決此問題。

再 者,是否未來機器人僅需使用視覺技術即可取代目前所使用的所有感測技術,仍有許多爭議。一方面視覺技術在感測精度上會隨著距離而遞減,再者對於許多障礙物 的偵測,單靠視覺技術仍無法做出最正確的判斷,因此短時間內雖可見到視覺技術應用於機器人上,但仍須要結合其他感測技術如超音波、雷射等。

  此外,透過視覺技術來模擬生物的眼睛,亦為視覺技術發展的主軸,但在實際的產品上,仍無法達到非常理想的跨距,以Point Gray目前所推出的3D視覺模組系統(Stereo Vision),跨距至少要12cm才能夠做出3D立體成像,對於小型化的機器人商品因無法使用過寬的跨距,有關於跨距問題在未來仍必須在技術上突破。

9 Point Gray立體視覺模組

結語

  本期我們為各位介紹關於東京大學石川正俊教授所主持之高速視覺技術,並利用高速視覺技術所發展之相關應用。在近兩年當中,已經有愈來愈多的廠商結合視覺技術來強化本身原有產品之應用,尤以產業用機器人為大宗。隨著IC處理器製程技術更加進步之際,也將會推動視覺技術更往前邁進,並可將視覺技術結合其他感測技術後提供機器人產品更加敏銳之環境感測能力。

在下一期文章當中,將介紹日本產業技術總合研究所(AIST)的共通性雙足機器人開發平台HRP-3P與相關機器人之研發成果。


資料出處精密機械研發中心 董成偉

http://www.robotworld.org.tw/index.htm?pid=10&News_ID=1557

Tuesday, April 22, 2008

The C Programmers Guide to Verilog

The C Programmers Guide to Verilog
Now that hardware is designed in high-level languages, the fields of hardware and software development are beginning to merge. Here's an introduction to hardware design in Verilog for the uninitiated.

In the near future, embedded systems designers will be able to use hardware and software interchangeably depending on which best solves a specific design problem. Up until now, the barriers were so high for software engineers who wanted to learn hardware design that few explored the space. The barrier is crumbling because of the similarity between hardware description languages and programming languages. Also, several reasonably low-cost demonstration boards are available that include a field-programmable gate array (FPGA), a microprocessor, and tools that even a software developer can use to learn hardware design.

This article offers an example of this new design process using an FPGA. We'll look at how to implement pulse width modulation (PWM) in software and then turn the design into a logic block that can run from an FPGA and be controlled via software using a memory-mapped I/O interface. You can do everything in this article with the FPGA development kits that are available today from major FPGA manufacturers.

Hardware-software divide Several things have changed that make it easier for software engineers to participate in hardware design. Both hardware and software modules are now designed using programming languages. As you know, C is the lingua franca of embedded software design. On the hardware side, Verilog is often the popular choice (though both VHDL and Verilog are popular). The syntax and structure of Verilog is similar to that of the C programming language, as the examples in this article will illustrate.

At the same time, hardware is getting easier to update and change. It used to be that software could be changed simply by downloading a new executable image while hardware could not. That's no longer entirely true. Just as a software developer can make a quick edit, recompile, and then download the new code into memory, hardware designers using programmable logic have a similar capability. Programmable logic changes the method for designing embedded systems by enabling you to change the hardware as easily as the software. In other words, it affords you the flexibility during design and debugging to choose the best way to handle these tasks—either in software or hardware.

Tools are available from FPGA vendors that enable a designer with a little knowledge of hardware to develop an embedded system for programmable logic, such as an FPGA. For example, the SOPC Builder from Altera (my employer) enables system designers to select and configure peripherals from an existing library as well as add user logic to create and tie peripherals together. With programmable logic and some hardware knowledge, software engineers can take advantage of the benefits of hardware to improve their systems.

PWM software A PWM controller produces a stream of pulses like those shown in Figure 1. Usually the period and pulse width are specified. The duty cycle, or on time, is defined as the ratio of the pulse width to the period. Figure 1 shows a PWM waveform of about 33% duty cycle.

Figure 1: A PWM waveform

PWM is used in many applications, most frequently to control analog circuitry. Because the digital signal varies continuously at a relatively fast rate (depending on the period, of course), the resulting signal will have an average voltage value, which can be used to control an analog device. For example, if a stream of PWM pulses is sent to a motor, it will turn at a rate proportional to the duty cycle (from 0% to 100%). If the duty cycle is increased, the motor will turn faster; likewise, if the duty cycle is decreased the motor will slow.

For more information about PWM, consult Michael Barr's Beginner's Corner article "Introduction to Pulse Width Modulation" (September 2001, p. 103).

Generally speaking, PWM is implemented in hardware because the output signal must be continuously updated—going high from the start of each period for the proper time, then low for the remainder of the period. Software usually just handles the selection of the period and duty cycle and perhaps occasionally making changes to the duty cycle, to effect a behavioral change in whatever is attached to the PWM output.

There's no reason, however, that software couldn't be used to implement PWM, say by bit-banging a spare output pin. Writing such a PWM controller in software is a relatively trivial task and helps illustrate what we will do in Verilog shortly. Listing 1 shows the C code for PWM.

Listing 1: A bit-banging PWM controller implemented entirely in software


void
pwmTask(uint32_t pulse_width, uint32_t period)
{
uint32_t time_on = pulse_width;
uint32_t time_off = period - pulse_width;

while (1) { pwm_output = 1; sleep(time_on); pwm_output = 0; sleep(time_off); } }

Based on the pulse_width and period arguments to this function, the PWM calculates the amount of time the output will be high and low. The infinite loop then sets the output pin high, waits for time_on time units to elapse, sets the output low, waits for time_off, and then repeats the cycle for the next period.

Verilog Listing 2 shows a simple Verilog module implementing an 8-bit wide register with an asynchronous reset. The input of the register, in, is assigned to the output, out, upon the rising edge of the clock, unless the falling edge of the clr_n reset signal occurs (in which case the output is assigned a value of 0).

Listing 2: Verilog module for a register with asynchronous reset

module simple_register(in, out, clr_n, clk, a);

// port declarations
input input input [7:0] input output [7:0] clr_n; clk; in; a; out;
// signal declarations
reg [7:0] wire out; a;

// implement a register with asynchronous clear always @(posedge clk or negedge clr_n) begin
if (clr_n == 0) // could also be written if (!clr_n)
out <= 0;
else
out <= in;
end

// continuous assignment assign a = !out[0];

endmodule

Glancing at the Verilog listing, you should notice several similarities to the C programming language. A semicolon is used to end each statement and the comment delimiters are the same (both /* */ and // are recognized). An == operator is also used to test equality. Verilog's if..then..else is similar to that of C, except that the keywords begin and end are used instead of curly braces. In fact, the begin and end keywords are optional for single-statement blocks, just like C's curly braces. Both Verilog and C are case sensitive as well.

Of course, one key difference between hardware and software is how they "run." A hardware design consists of many elements all running in parallel. Once the device is powered on, every element of the hardware is always executing. Depending on the control logic and the data input, of course, some elements of the device may not change their outputs. However, they're always "running."

In contrast, only one small portion of an entire software design (even one with multiple software tasks defined) is being executed at any one time. If there's just one processor, only one instruction is actually being executed at a time. The rest of the software can be considered dormant, unlike the rest of the hardware. Variables may exist with a valid value, but most of the time they're not involved in any processing.

This difference in behavior translates to differences in the way we program hardware and software code. Software is executed serially, so that each line of code is executed only after the line before it is complete (except for nonlinearities on interrupts or at the behest of an operating system).

A Verilog module starts with the module keyword followed by the name of the module and the port list, which is a list of the names of all the inputs and outputs of the module. The next section contains the port declarations. Note that all of the input and outputs appear in both the port list in the first line of the module and in the port declarations section.

In Verilog, two types of internal signals are widely used: reg and wire. These types differ in function. All parts have a signal by the same name implicitly declared as a wire. Therefore, the line declaring a as a wire is not necessary. A reg will hold the last assigned value so it doesn't need to be driven at all times. Signals of type wire are used for asynchronous logic and sometimes to connect signals. Because a reg holds the last value driven, inputs cannot be declared as a reg. An input can change at any time asynchronous to any event in the Verilog module. The main difference, however, is that signals of type reg can only be assigned a value in procedural blocks (discussed later) while signals of type wire can only be assigned a value outside of procedural blocks. Both signal types can appear on the right-hand side of the assignment operator inside or outside of any procedural block.

It's important to understand that using the reg keyword doesn't necessarily mean the compiler will create a register. The code in Listing 2 has one internal signal of type reg that's 8 bits wide and called out. This module infers a register because of the way the always block (a type of procedural block) is written. Notice that the signal a is a wire and thus is assigned a value only in the continuous assignment statement while out, a reg, is assigned a value only in the always block.

An always block is a type of procedural block used to update signals only when something changes. The group of expressions inside the parentheses of the always statement is called the sensitivity list; it's of the form:

(expression or expression ...)

The code inside the always block is executed whenever any expression in its sensitivity list is true. The Verilog keywords for rising edge and falling edge are posedge and negedge, respectively. These are often used in sensitivity lists. In the example shown, if the rising edge of the clk signal or the falling edge of the clr_n signal occurs, the statements inside the always block will be executed.

To infer a register, the output should be updated on the rising edge of the clock (falling edge would work too, but the rising edge is more common). Adding negedge clr_n makes the register reset upon the falling edge of the clr_n signal. Not all sensitivity lists will contain the keywords posedge or negedge, though, so there won't always be an actual register in the resulting hardware.

Inside the always block, the first statement asks if the falling edge of the clr_n signal occurred. If it did, then the next line of code sets out to 0. These lines of code implement the asynchronous reset portion of the register. If the conditional statement were:

if (negedge clr_n and clk == 1)

then it would be a synchronous reset that depends on the clock.

You may have noticed that the assignment operators inside the always block are different from the one used in the continuous assignment statement that begins with the assign keyword. The <= operator is used for nonblocking assignments while the = operator is used for blocking assignments.

In a group of blocking assignments, the first assignment is evaluated and assigned before the next blocking assignment is executed. This process is just like C's serial execution of statements. With nonblocking assignments, though, the right hand side of all assignments are evaluated and assigned simultaneously. Continuous assignment statements must use the blocking assignment (the compiler will give an error otherwise).

To make the code less prone to errors, it's recommended that you use nonblocking assignments for all assignments in an always block with sequential logic (for example, logic that you want implemented as registers). Most always blocks should use nonblocking assignment statements. If the always block has all combinatorial logic, then you'll want to use blocking assignments.

PWM hardware One of the first tasks when writing a memory-mapped hardware module is to decide what the register map will look like from the software perspective. In the case of PWM, you want to be able to set the period and pulse width in software. In hardware, making a counter that counts system clock cycles is easy. Therefore, there will be two registers, the pulse_width and the period, both measured in clock cycles. Table 1 shows the register map for the PWM.

Table 1: Register map for PWM

Address Name Width Description
0 period 32 bits Number of clock cycles for one period
1 pulse_width 32 bits Number of clock cycles the output will be high
To determine the output signal, the hardware can simply compare the contents of the period and pulse_width registers to the output of a running counter it keeps.

Next, choose the ports for the PWM, most of which are already determined based on the bus architecture. Table 2 has a brief description of the signals for a generic memory-mapped PWM. Note that a popular naming convention for active low signals is to add an "_n" to the signal name, which are fairly common for control signals. The signals write_n, and clr_n in Table 2 are active low (falling-edge triggered) signals.

Table 2: Ports for PWM

Signal Name Direction Description
clk Input System clock
write_data[31:0] Input Write data (for registers in register map)
cs Input Chip select
write_n Input Write enable, active low
addr Input Address (to access registers in register map)
clr_n Input Clear, active low
read_data[31:0] Output Read data output
pwm_out Output PWM output

Now that we have defined the interface of the hardware module, we can start writing the Verilog code. An example implementation is shown in Listing 3.

Listing 3: PWM hardware implementation in Verilog

module pwm (clk, write_data, cs, write_n, addr, clr_n, read_data, pwm_out);
// port declarations
input input [31:0] input input input input output [31:0] output clk; write_data; cs; write_n; addr; clr_n; read_data; pwm_out;
// signal declarations
reg [31:0] reg [31:0] reg [31:0] reg reg [31:0] wire period; pulse_width; counter; off; read_data; period_en, pulse_width_en; // write enables
// Define contents of period and pulse_width registers // including write access for these registers always @(posedge clk or negedge clr_n) begin
if (clr_n == 0)
begin
period <= 32'h 00000000; pulse_width <= 32'h 00000000;
end
else
begin
if (period_en)
period <= write_data[31:0];
else
period <= period;
if (pulse_width_en)
pulse_width <= write_data[31:0];
else
pulse_width <= pulse_width;
end
end
// read access for period and pulse_width registers always @(addr or period or pulse_width)
if (addr == 0)
read_data = period;
else
read_data = pulse_width;
// counter which continually counts up to period always @(posedge clk or negedge clr_n) begin
if (clr_n == 0)
counter <= 0;
else if (counter >= period - 1) // count from 0 to (period-1)
counter <= 0;
else
counter <= counter + 1;
end // Turns output on while counter is less than pulse_width; otherwise // turns output off. // !off is connected to PWM output always @(posedge clk or negedge clr_n) begin
if (clr_n == 0)
off <= 0;
else
if (counter >= pulse_width)
off <= 1;
else
if (counter == 0)
off <= 0;
else
off <= off;
end
// write enable signals for writing to period and pulse_width registers assign period_en = cs & !write_n & !addr; assign pulse_width_en = cs & !write_n & addr;

// PWM output assign pwm_out = !off;

endmodule

The first signals are the port declarations, which were described in Table 2. After the port declarations come the internal signal declarations. The memory-mapped registers that make up the software interface to control the PWM are declared reg. The code allows for only 32-bit accesses to these memory-mapped registers. If you need 8-bit or 16-bit access, then you would split the registers into four 8-bit registers and add logic for byte enable signals. The Verilog code to implement this is straightforward. All the signals with assigned values in the always blocks are also declared reg. The signals declared wire are the write enables for the registers period and pulse_width. These signals are assigned values using continuous assignment statements.

The rest of the listing contains the actual code. There are four always blocks and several assignment statements at the end. Each always block describes the behavior for one signal or a group of signals that have the same basic behavior (in other words, use the same control logic). This is a clean way of writing Verilog code that keeps the code readable and less prone to errors. All of the always blocks have reset logic that sets the signal(s) to 0 when the clr_n signal is asserted (set to 0). While not strictly necessary, this is a good design practice so that every signal has a known value upon reset.

The first always block describes the behavior of the registers in the register map. The value of the write_data register is written into the period or pulse_width register if the appropriate enable signal is asserted. That is the only way to change the values of either register. The write enable signals are defined in the continuous assignment statements at the bottom of the file. The write enables for the period and pulse_width registers are asserted when the main write enable signal and the chip select signal are asserted; the addr bit should be set to 0 for period and 1 for pulse_width.

The second always block defines reading the registers in the register map. The period register will be at the base address of the peripheral, and the pulse_width register will be at the next 32-bit word.

The third and fourth always blocks work together to determine the output of the PWM. The third always block implements a counter that continually counts up to the value in the period register, resets to 0, and begins counting again. The fourth always block compares this counter value to the pulse_width register. While the counter value is less than the pulse_width, the PWM output is kept high; otherwise it's set low.

One thing to keep in mind is that every signal must have a defined value under all conditions. This goes back to one of the fundamental behaviors of hardware—it's always running. For example, in the last always block (the one that describes the off signal) the last line of code assigns off to itself. This may seem strange at first, but without this line, the value of off would be undefined for that case. An easy way to keep track of this is to make sure that every time a signal is assigned a value in an if statement, it is assigned a value in the corresponding else statement as well.

Software access Now that the hardware is complete, the PWM can be controlled via software using the registers in the register map. You can use a simple data structure along with a pointer to connect to the registers in the PWM.


typedef volatile struct
{
 uint32_t  period;
 uint32_t pulse_width;

} PWM;

For example, the PWM could be hooked to an LED. A variable called pLED of type PWM * could be initialized to point to the PWM base address. This abstracts the hardware into a data structure. Writing to pLED->period will set or change the period. Writing to pLED->pulse_width will change the duty cycle and cause the brightness of the LED to increase or decrease. If a blinking LED is desired, the period need only be lengthened, so that the human eye perceives the on and off periods as distinct.

The Verilog PWM implementation shown in Listing 3 was tested as a peripheral for Altera's Nios processor system and accessed via software using a C struct like the one I previously described. Altera's SOPC Builder creates macros that facilitate performing co-simulation in ModelSim, a hardware simulator from Mentor Graphics. Using the ModelSim simulator, the behavior of the PWM signals, along with the rest of the system's signals, can be observed while the system is executing C code.

Listing 4 shows the C code that was used to generate the waveform in Figure 2. The waveform shows the behavior of the pertinent PWM signals. The C code writes to the PWM registers to create a PWM output with a period of five cycles and a pulse width of four. Notice that at the beginning of the waveform, the cs and wr_n signals are asserted twice since we're writing to both the period and pulse_width registers. (The address signal is low when writing to the period register and high when writing to the pulse_width register.)

Listing 4 Test software used to produce waveforms in Figure 2


void
main(void)
{
 PWM * const  pLED = ...

pLED->period = 5; pLED->pulse_width = 4;

asm("nop"); asm("nop"); asm("nop");

pLED->pulse_width = 2; }

Figure 2: Waveform for software-controlled PWM hardware

After the new values have been written to the registers, the pwm_output signal begins to reflect the change. Then, just to add some delay so we can see the output, some NOP instructions are executed by the C code. Finally, the pulse width is changed to two cycles, and the PWM waveform changes accordingly while still having a period of five cycles.

Best of both worlds Part of architecting an embedded system is partitioning the system into hardware and software modules to take advantage of the benefits of each. As development tools evolve, interchanging software and hardware modules is becoming more transparent to the designer.

Once you understand the concepts discussed in this article, you'll have the knowledge to develop hardware on an FPGA that can be hooked up as a memory-mapped peripheral in a microprocessor system and interfaced by simply writing software. Because certain algorithms run much faster in hardware, converting an algorithm from software to hardware may greatly increase system performance. Known as hardware acceleration, the ability to do this is key to using configurable processors implemented effectively in programmable logic. At long last, even a software engineer has the power to improve system performance and efficiency through hardware acceleration.

Lara Simsic is an applications engineer at Altera. She has developed embedded hardware and software for five years and has an EE degree from the University of Dayton. Contact her at lsimsic@altera.com.

http://www.embedded.com/shared/printableArticle.jhtml?articleID=12800116

Friday, March 21, 2008

日本娃娃機不用吊的用丟的 小小機器人代勞

最近日本街頭流行一款新型娃娃機,玻璃窗內不是懸吊手臂,而是一隻小小機器人。只要投入硬幣,它就會為您將娃娃扔到洞口。不過機器人偶爾也會跌倒,可別以為這樣就結束了,機器人會自動爬起來,繼續為您服務。

夾娃娃一定得用夾的嗎?那可不一定,日本街頭就出現一種抱娃娃機,只要投入硬幣,玻璃窗內的小機器人就會站起來為您服務。按前進鈕,機器人就會小碎步往目標物移動,再按抓取鍵,機器人就會把娃娃抱起來,只是操縱還是得靠技巧,兩手空空抓不到是常有的事。

小機器人不小心也會跌倒,這時候就GAMEOVER了嗎?可沒這麼快,只要在限定時間內,機器人就會撐著地面爬起來,繼續為您服務。

這款名為ROBOCATCHER的娃娃機,不只受到男生青睞,就連年輕女性也為之瘋狂,即使造價是一般夾娃娃機的3倍,仍然供不應求,天馬行空的創意概念,也為業者開發無限商機。


Tuesday, March 11, 2008

機器人在前進:機器人平台與開發工具

機器人在前進:機器人平台與開發工具

( 3 月 1 日 2008 年)
Robert Cravotta,技術編輯

機 器人終於讓人有了想像的空間。隨著低成本開發平台變得越來越容易取得,人們將機器人用於教育與最終應用的機會也在不斷增加。不過,“機器人”此一用語是一 個要限定範圍的猛獸,因為人們通常會把這些裝置擬人化,把它們看作佣人或寵物。大多數人能在看到機器人時,就把它認出來,但你也會發現,很難找到一種能夠 適用於所有或大多數機器人的說明。例如,iRobot 把自己的Roomba 稱為吸塵機器人(vacuuming robot),但很多人毫無疑問地會稱它是一種機器人(robot)。另一方面,多數人很難把自動式的汽車(autonomous automobile)稱為機器人,例如像是在美國國防部高等研究計畫局(he Defense Advanced Research Projects Agency,DARPA)的Urban Challenge中所跑的那些車子。這些功能近似的系統之間究竟有什麼差異?更重要的是,身為一名設計者,在建立這些類型系統時,他所使用的設計方案與 開發資源有何差異?一個嵌入式自動或半自動子系統的設計(如高檔汽車中的刹車與牽引控制系統),與多數人所認為的機器人設計之間有何差異?
幸運的 是,在機器人社群中,有越來越多的設計資源並不擔心這些差異,並且他們每天都在為更多的人群開啟機器人技術與自動化子系統的天地。這很重要;這些類型的系 統是由一系列由通用型與專業型專家所組成的跨學科團隊之研究成果。機器人技術開發平台為這些團隊提供了一個起點,讓他們不需要成為感測器、機械與電機控制 的專家,就能開始發展自己的專案。由於這些系統的軟體發展工具日益成熟,讓領域中的專家有更大的動力來進行這些系統的規格、設計、測試與部署。
本 次實作計畫的第一部分(編註:本文英文版發表於2007年12月3日的EDN雜誌上)將先簡要地說明計畫的內容,然後再把焦點聚集在我準備用來實現專案的 平台與開發工具。第二部分(編註:英文版原文)則是在2008 年 2 月 7 日出版的EDN雜誌上發表,其中描述了以所選定的硬體與軟體平台實現該專案的相關細節。這次的實作計畫將嘗試達成下列多個目標。第一個目標是為您揭示那些 能讓開發團隊立即開始建立自動化系統的資源,無論它們是嵌入式的或獨立式的,也不管它們是全自動的還是部分自動的。另一個目標是揭示那些支援它們的最新平 台與開發資源;重要的是要清楚地瞭解,這些開發資源的成熟程度,是否(或在多大程度上)處於或超出了早期使用者的水平。
另一個目標是呈現檢測一個 在行動平台上(而不是固定平台)的世界的構想。我看過很多展示,尤其是在視覺檢測方面,設計者將感測器安裝在一個穩固的架子上,以盡力消除在資料擷取期間 發生任何運動的可能性。這種類型的系統似乎都用在計算負載較大的場合,以便為一個牢固、穩定平台所無法擷取到的資料進行補償。在開發自動汽車時,我的團隊 特意在檢測情境中引入了運動(motion),以幫助我們識別和過濾掉感測器的異常情況,並且讓它更容易判別出我們試圖要找的東西。此一計畫是對運動輔助 檢測的靈活性測試之第一次嘗試,運動輔助檢測最終可降低越來越大的計算負載,從而在檢測中獲得更好的資料識別與模式識別結果。為了此一計畫,我嘗試建立一 個雙耳檢測(binaural-sensing)系統,並證明它是一個雙話筒、運動輔助、聲音定位的機器人。換句話說,機器人將嘗試用兩個話筒來相互定 位,並用機器人的能力來協調行動、指示並最終判別出聲源的位置。
此一專案並非試圖要用盡一切力量來找出現有的機器人開發資源,因為這個社群還在不 斷發展之中;相反的,此一專案的目標是找出我為此一計畫所考慮的幾款少數行動機器人平台,及以現有支援它們的開發資源。有關機器人開發資源請見在博客 (blog)上的文章“嵌入式機器人技術”,網址為www.edn.com/071203b1。現在,讓我們研究一下我為此一計畫所準備的平台和開發資 源。
平台
從 1990 年起,iRobot 就一直在提供系列可完成從清潔地板到清除爆炸物等各種工作的各種機器人。該公司使用自己專利的 Aware 機器人智慧系統,以便在各傢俱之間進行導航,以及在廢棄的建築物內搜索。該公司在 2005 年 10 月以後製造的 iRobot Roomba 包含有 iRobot Roomba SCI(serial-command interface,串列指令介面)的電路與軟體,使開發人員能夠控制或修改自己 Roomba 的性能,並可從遠端監控其感測器。Roomba SCI 協議透過一個 miniDIN 連接器的外接串列埠,為 Roomba 提供一控制鏈路。SCI 包含了控制 Roomba 所有致動器(actuator)的命令,如電機、LED 與揚聲器,並要求來自所有系統內部感測器的感測器資料。
2007 年年初,該公司推出了一款 iRobot Create,這是一款預先組裝的行動機器人平台,有 32 個內建的感測器、致動器以及串列介面,起始價格為 129.99 美元(圖 1)。Create 採用 Roomba 的核心技術,並與Roomba 的可充電電池、遙控器和其他附件相容。該平台包括一個開放式載荷倉(payload bay);一個 25 針的擴充埠;以及可以在機器人上安裝的市售感測器、致動器和其他第三方電子部件(如攝影鏡頭、臂和無線連接)的螺紋安裝孔。
使用者可以透過串列連 接,從桌上型電腦下載數位命令的短腳本來對平台進行編程,或將程式載進到命令模組。命令模組中的處理器是一款 20MHz、8位元的Atmel ATMega168 微控制器。WinAVR開放原始碼開發(open-source-development)工具組支援用 C 或 C++ 對命令模組的編程。開發工具組包括一個編輯器、一個編譯器,以及命令模組的下載器(downloader)。開發人員還可以用微軟於 2006 年 11 月推出的Microsoft Robotics Studio來對機器人進行編程。RoboDynamics 的 Roomba DevTools 工具可以使開發人員透過藍牙、USB 或串列介面,從自己的電腦來控制 Roomba 平台。
命令模組手冊包含了有低階的編程 技巧和實例(參考文獻 1)。編程技巧包括盡可能地用 8位元的值(8-bit value)來計算、避免浮點演算法,以及使用整數(integer)和右移位(right shift)來代替除法(division)。這些技巧中所舉的一個例子是對暫存器或埠寫入位元遮罩(bit mask),以清除、啟動和讀取 ADC,因為現在還沒有函數呼叫(function call)的應用編程介面(application-programming interface,API)。另一個技巧則是說明如何用計時器延遲函數來讓按鍵輸入反彈跳(debounce)。執行複雜的自動控制需要相當長的一段學 習曲線,除非 iRobot 為工具集增加一個對該層做抽象的 API 框架,如微軟的 Robotics Studio 那樣。
Segway 提供的是機器人技術行動平台(robotic-mobility platform,RMP),它是以 Segway 的個人輸送機(personal transporter,PT)為基礎;RMP 採用的是耐用型的包裝,以便用於人類尺寸機器人(human-scale-robotic)的應用(圖 2)。Segway RMP 包含了在各種地形緊湊空間內移動沉重負載的配置。Segway RMP 電機(motor)可以連續提供 2 hp 功率,必要時可達 4 至 5 hp 峰值功率,足以帶動一個人體尺寸大小的負載。Segway RMP 有多種型號,包含各種電池與輪胎/車輪的組合,提供最遠 15 英里範圍和 400 lbs 的承載能力。Segway RMP 採用一至四個鎳氫充電電池(nickel-metal-hydride,NiMH)或鋰(鋰離子)電池組。任何能提供 52V 電壓的電源均可為 Segway RMP 供電。你可以將 Segway RMP 接在一個緊湊型氣體產生器(gas generator)上,在使用中為電池充電。
Segway RMP 包括一個板上充電系統,且系統可以透過 USB 或控制器區域網路(controller-area-network,CAN)串列匯流排界面來進行控制。 Segway 表示,USB 電氣介面隱藏著一個 CAN 介面,因為該公司發現,提供 USB 前端大幅縮短了開發人員與平台介接的學習曲線。如果他們願意,開發人員也可以直接在 CAN 級上工作。該公司正在考慮增加其他通信介面,如乙太網路。另外,他們還在考慮改進機械介面,包括增加用於安裝支架的螺孔。有些型號帶有用於客戶檢測設備的 支架和計算硬體,靜態穩定運行的腳輪(caster),或不同 Segway RMP 之間互連的連接點。有些開發人員沒有採用安裝孔和安裝架,而是成功地用工業級 Velcro 來測試和連接其平台的原型部件。
該公司的開發支援包 括使用開放原始碼開發(open-source-development)的工具,並能使用多種由公司支援的演算法,以便管理平台上重量與均衡性的配置。 Segway 與微軟最近宣佈將經由Microsoft Robotics Studio來對該平台提供支援。微軟的 Robotics Studio 是一個端到端的 Windows 環境,支援機器人應用的開發,這些應用是以那些可以提供以.NET為基礎之代表性狀態傳輸技術(representational-state- transfer,REST)服務導向的運轉時間環境的硬體平台為目標,例如 Windows CE 和 Windows 行動設備。運轉時間(runtime)部件支援各種機器人的開發,如仿真機器人;透過與桌上型電腦直接鏈結控制的機器人,如串列埠、USB 或藍牙;以及帶有板載控制處理器的機器人。開發環境亦包括了視覺化創作(visual authoring)與仿真工具。有幾家公司均已正式聲明他們的產品支援微軟 Robotics Studio,這些公司包括 iRobot、Lego 和 Segway(參考文獻 2)。
根據微軟的《Robotics Studio 使用者指南》,運轉時間環境包括了並行與協調運轉時間(concurrency-and-coordination-runtime,CCR)與分散軟體 服務(decentralized-software-services,DSS)部件,而這些部件必須依附在以下的需求集(參考文獻 3)。它必須能夠進行狀態監控,以及應用運轉時間部件之間的互動。它必須能夠在應用運行中發現、建立、終止和重新啟動部件。它必須能夠並行地處理多個感測 器的輸入,並將這些輸入組織成工作任務,而不會讓這些任務之間有無意干擾的風險。它必須能夠透過網路同時處理本地與遠端的自動與受控機器人應用。運轉時間 必須夠輕量(lightweight),從而能在廣泛的環境中執行。應用環境必須為可擴充,並有足夠的靈活性,以適應各種硬體與軟體環境的互動。
CCR 透過一個訊息導向編程的(message-oriented-programming)模型來支援非同步的與並行的操作,該模型可以自動揭示並行硬體與協 定的訊息,而不需要用到人工的線程(manual threading)、鎖定或給出信號(semaphore)。這種方案使設計者能夠建立起更鬆散耦合的軟體模組或部件。任何以.NET 2.0 CLR(Common Language Runtime,公共語言運轉時間)為目標的語言,都可以來處理自足的(self-contained )CCR .NET DLL。微軟在 CCR 上建立了 DSS 運轉時間,且 DSS 並不仰賴微軟 Robotics Studio 中的任何其他部件。它為管理服務提供了一個主控環境,以及一組基礎的服務(infrastructure service),它們可以用來服務的開創、發現、記錄、除錯、監控與保全。DSS 支援一種輕量的、以服務為導向的應用模型,該模型結合了基於傳統 REST Web 的(traditional REST Web-based)架構,以及部分 Web 服務架構。DSS 定義了一種應用模型,它建立在 REST 模型上,透過它們的狀態和對該狀態的一組統一操作而展示服務,但透過增加結構化資料操作、事件通知以及服務組織擴充了超文件傳輸協定(hypertext -transfer protocol,HTTP)應用模型。
DSS 的主要目標是提供服務之間的互通性,不管這些服務是否在相同的結點上運行或是在網路上運行。DSS 用 HTTP 和分散軟體服務協定(Decentralized Software Services Protocol ,DSSP)來當作與服務介接的基礎。基於 DSSP 的羽量級簡單物件存取協定(Decentralized Software Services Protocol,SOAP)支援結構化狀態與事件模型的操作,這改變了結構化狀態的驅動。可以把 DSSP 當作一種狀態驅動的應用模型,對各個服務進行處理與簽署。
微軟虛擬編程語言(Visual Programming Language,VPL)的繪圖編輯開發環境採用一種資料流(data-flow)編程模型,而不是控制流(control-flow)模型。一個 VPL 資料流包括一個連接的動作串列順序(a connected sequence of activities),資料流將其表示為帶輸入和輸出的區塊,可以將它們連接到其他的動作區塊上。動作可以表示為預建構的服務(prebuilt service)、資料流控制、函數或其他代碼模組;動作也可以包含其他動作的組合。VPL 針對初級程式師,但該編程語言也吸引高級程式師用來進行快速原型的開發或代碼開發。
Robotics Studio 仿真(simulation)運轉時間包含了仿真引擎服務、受控物理引擎(managed-physics-engine)控管器(wrapper)、原 生的物理引擎(native-physics-engine)庫,以及與物理引擎介接的部件和在仿真世界中表示硬體與物理物件的渲染引擎。仿真引擎服務負 責實體的渲染,以及物理引擎仿真時間的處理。它跟蹤整個仿真的狀態,為仿真提供一個服務/分佈(service/distributed)前端。受控物理 引擎控管器將使用者從低階物理引擎 API 中抽象出來,為物理仿真提供一個受控介面。原生物理引擎庫透過 Ageia PhysX 技術實現硬體加速,這是透過 Ageia PhysX 技術處理器來支援硬體的加速,該處理器現用於桌上型電腦的 PhysX Accelerator 附加卡。微軟的 Robotics Studio 帶有一些預先定義的實體(entitie),它們表示為仿真硬體的高級介面,隱藏了物理 API 的使用。
開發人員可以選擇只與受控物理引擎 API 互動,而不用任何的視覺化。但為了簡化對仿真代碼的狀態檢查、除錯和持久性,微軟建議開發人員總是使用仿真引擎服務,以及定義關閉(disable)了渲 染的訂製實體。渲染引擎用到了繪圖加速卡的可編程流水線,遵從 DirectX9 的圖元/頂點著色器(pixel/vertex-shader)標準。
Lego 的 Mindstorms NXT 是該公司最新一代機器人技術工具組,它開始於 1998 年商用的 Robotics Invention System;NXT 則在 2006 年 8 月推出。支持這個平台的內建資源、第三方資源和專業級開發工具越來越多,如 National Instruments 用於 Lego 的 LabView 工具組。大量的支持淹沒了最初可能的印象,即 NXT 不過是一個玩具(圖 3)。事實上,Lego 的 NXT 積木方案使該平台具備機械的靈活性,可使它適用於快速的原型製作,以及感測器和運動部件的多種物理配置之探索。
NXT 利用一顆 32位元的ARM7 處理器來為平台提供自動的控制器。基本的系統包括三個有精密控制功能的內建旋轉感測器之伺服電機、一個用於運動檢測的超聲波感測器、一個支援聲音模式識別 與音調識別的聲音感測器、一個檢測顏色和光強度的光感測器、一個觸控感測器,以及支持第三方資源開發與整合的 USB 2.0 與藍牙無線介面。瀏覽 Mindstorms 網站可以獲得豐富的使用者資源與開發資源,包括開放原始碼的 NXT 韌體、軟體及硬體開發包和一個藍牙開發包。
將 LabView 當作 NXT 的開發工具來使用,正好趕上去年 NXT 平台的推出,並且隨著微軟 Robotics Studio 支持平台數量的增加,這些工具元件可能是支援與工具的爆炸性成長之預兆。一方面,這種爆炸性增長將透過較高級別的抽象,為更多開發人員開啟機器人編程平台 的大門。另一方面,它能獲得更高的生產力,並能夠充分利用第三方開發者的工作,完成日益複雜和重要的機器人設計。這些目標的實現將透過一種強健的機制,用 於開發者封裝(encapsulate)、保護和分發機器人的子系統設計。利用LabView 工具組來對 NXT 編程,需要 LabView 7.1、8.0 或 8.20,而為 NXT 軟體建立原生區塊則需要 LabView 7.1。
LabView 繪圖開發環境包括了一個內建的編譯器,也可支援即時的資料獲取與儀器控制,同時還帶有開創控制與測試應用的繪圖展示工具(graphical presentation tool)。它透過一個可以讓結點間資料流動(而不是文字(text)的連續行)的資料流編程模型(data-flow-programming),來確 定代碼的執行順序,從而支援一個通用編程環境的特性,如資料結構、迴圈結構、事件處理以及針對物件的編程。該方案使開發人員能夠建立起捕獲多工或多線程部 件的方塊圖,並可以在有適當硬體情況下,並行地執行多個運算。
開發者可以擴充 LabView 的功能,方法是使用處理軟體優化、資料管理與視覺化,以及對各種硬體目標(包括 FPGA)進行部署的插件(add-on)。其他插件則用於信號處理與分析、自動化測試、影像擷取以及機器視覺,還有控制設計與仿真工業控制。數百個第三 方插件都帶有第三方工具與模型和仿真設計介面的內容,如 MathWorks 的 Simulink 環境。
可擴充性
所有這些平台有一個 共同的主題,那就是對可擴充性的支持,不僅是針對訂製與第三方軟體模組,也是針對硬體介面與子系統。這些平台中的每一款都提供了我對這次實作計畫所期望的 行動性,但我還要用一些軟、硬體來擴充這些平台,增加雙耳檢測功能,以及為回應音頻輸入而進行的引導平台之動作。
與 iRobot Create 和 Lego NXT 不同,Segway RMP 包括了檢測其方向與慣性運動的能力,我認為這是在量產產品中實現聲音定位的基礎。不過,這次的實作計畫是要進行構想的驗證,目的是要看:是否最粗略的運動 控制與立體檢測的結合,也可以讓聲音的定位問題變得更容易處理。另外,在這一點上,對一個原型構想驗證專案而言,硬體部件之間的介面和建立 RMP 軟體控制的長期學習曲線似乎是使用 RMP 所要支付的一個巨大成本。這個問題使 Create 和 NXT 成為了平台候選人。
我最開始的目標 是 iRobot 平台,因為我在一個先前的計畫中購買過一台 Roomba(參考文獻 4),另外,也是因為 Roomba 有在房間內不確定位置的物體之間導航的演算法。挑戰來自於要找到一些可以快速設置的模組,它能收集音頻輸入,發出指令,並接收來自 Roomba 控制器的回應。我為聲音的檢測和高級控制器子系統找到了兩款可能成為計畫的候選人的評估平台。
其中之一是德州儀器公司的 eZ430-RF2500 開發工具,它包括兩個 USB Sstick大小的開發板,支持彼此間的無線連接(圖 4)。我喜歡無線連接,因為很多年來,我都希望把它應用到一項計畫中,並且,它似乎也為一項設計增加了無線功能,從而最終就實現了為系統增加模組,而不必 自己從頭來設計。一片開發板從 USB 連接的主控電腦上獲得電源,另一片板子則連接到一個電池盒,以便獲得電源。該板採用一個 16 MHz、16位元的MSP430F2274 微控制器,它提供充足的處理能力,還有一個 10位元、200k-sample/sec的 ADC,其速度足以擷取音頻輸入。
另一個來自 Silicon Labs 的平台是 C8051F064-EK 評估包,它採用一個 25 MIPS、8位元的C8051F064 微控制器,帶有兩個 16位元、1M-sample/sec 的ADC,可同時從兩個音頻輸入採樣(圖 5)。該評估板可以透過 USB 連接從主機接受電源,並帶有一個 BNC 和前端電路,以調整來自兩個類比輸入的類比信號。但是,為了能同時使用這些板子,我必須為話筒建立硬體介面和軟體驅動,並透過 Roomba 的串列埠通信。
當在研究將 National Instruments 的 LabView 用於 Lego NXT 時,我發現 National Instruments 的一位工程師最近把 NXT 用在一個類似電子“牧羊犬”的驗證應用,它可以根據聽到的聲音來完成一個動作,如向左或向右轉、停止或前進。這個功能不同於完成運動輔助的聲音定位,但瞭 解該計畫的詳情後,我可以將其作為一種參考設計,這樣就能節省此次實作計畫設置的寶貴時間。
我選擇 NXT 系統的另一個原因是,立即可以得到確認能與 NXT 系統介接的恰當模組。將 National Instruments 的 Speedy 33(一片採用德州儀器公司 TMS320VC33 的 DSP 板)與 LabView DSP 模組和一個來自 HiTechnic 的感測器原型板相結合,就得到了一個包含此一專案全部適用硬體的結構。Speedy 33 整合了兩個相距約 5 英寸的話筒,有48 kHz 的採樣,並且還採用了 LabView DSP 模組,為時域與頻域信號處理提供資料獲取與資料分析虛擬儀器庫的存取(圖 6)。HiTechnic 原型板在 Speedy 33 與 NXT 之間提供一個物理鏈路,並且在 NXT 的感測器記憶體模組中提供了一個邏輯映射。
這篇實作計畫文章 的第二部分(編註:英文版原文)會刊登在 2008 年 2 月 7 日出版的EDN雜誌上,將進一步研究使用 NXT 平台和開發資源,以及用運動輔助雙耳採樣進行聲音定位的工作細節。在時間和空間許可的情況下,我還會嘗試使用微軟的 Robotics Studio 模型建立與仿真功能,並分享自己的經驗。

作者簡介
有興趣的讀者可透過以下的方式與技術編輯 Robert Cravotta聯絡。電話: 1-661-296-5096 ;電子郵件信箱: rcravotta@edn.com.。

參考文獻
1. iRobot Command Module Owner’s Manual, www.irobot.com/filelibrary/create/Command%20Module%20Manual_v2.pdf.
2. “Microsoft Robotics Studio Partners,” http://msdn2.microsoft.com/en-us/robotics/bb383566.aspx.
3. Microsoft Robotics Studio User Guide, http://msdn2.microsoft.com/en-us/library/bb482024.aspx.
4. Cravotta, Robert, “Rummage through a Roomba: Sensor-packed vacuum robot attracts hacks,” EDN, March 15, 2007, pg 32, www.edn.com/article/CA6421379.

圖 1 機器人製造商 iRobot 用 Create 建造了公司的 Roomba 吸塵機器人,可供教育者、愛好者和開發人員添加到自己的軟硬體中,以控制平台。
圖 2 Segway 的 RMP(機器人行動平台)是以該公司的個人運輸產品為基礎,現有多種配置,可支援不同的負載與地形場合。
圖 3 National Instruments 提供一種版本的 LabView來支援 Lego Mindstorm NXT 的開發。
圖 4 德州儀器公司的 eZ430-RF2500 發展工具是擴充板候選人之一,部分原因是因為它採用了模組化的無線通信方案。
圖 5 Silicon Labs 的 C8051F064EK 評估套件是擴充板候選人之一,部分原因是因為它使用了雙 ADC,這可以同時從兩個話筒進行採樣。
圖 6 National Instruments 的 Speedy 33 信號處理模組帶有兩個內建話筒和驅動器,以及處理採樣資料的虛擬儀器。

Click here for Illustrations:


Figure 1, Figure 2, Figure 3, Figure 4, Figure 5, Figure 6