Webots入門(一)-build up a world

兔美醬xz發表於2014-12-16

        以Webots的guide.pdf為例建立一個擁有a floor, four obstacles 和 a surrounding wall的環境。我想大部分人都可以照著guide一步一步實現整個world的建立,但是對於其中的元件的使用不是特別理解,比如為什麼要用這個元件,不用另外的元件。這裡跳過色彩方面的講解,因為自己也不是很瞭解。下面進入正題:

         先上一張感性的截圖,讓大家直觀的感受下這個wall是什麼樣子的:

          

          Let us create the walls!

       1. Select the last Solid node in the scene tree window(which is the floor) and click on the insert after button.

        那麼問題來了,這裡為什麼要選擇Solid,我們來看看Solid類的介紹

        父類為Transform

Solid{

SFString    name    " "

SFString    model   " "

SFString    description     " "

SFNode     boundingObject     NULL

SFNode     physics                   NULL

SFBool       locked                    FALSE

 }

派生類:DistanceSensor,Servo, Robot, Camera....

描述

Solid節點代表了一個實體諸如形狀和體型的物理屬性描述。Solid類是碰撞檢測實體的基類。機器人和其他裝置類都是它的子類。

Solid域

這裡我們著重瞭解下成員類boundingObject(SFNode意味著當前未被實現),邊界實體指定了碰撞檢測的幾何形狀。如果boundingObject域為NULL,則不做碰撞檢測實體可以直接穿過該實體。下面繼續討論boundingObject域:

        How to use the boundingObject field?

除了children域boundingObject的其他域都可以進行指定。由於碰撞檢測對CPU要求較高,因此常採用一些簡單的幾何模型來作為boundingObject.

各種節點組合可以實現boundingObject,包括:1)Box  2)Cylinder  3)Sphere  4)IndexedFaceSet  5)由上述模型實現的Shape  6)由上述模型實現的Transform  7)由幾個子節點組成的Group,每個子節點都是由上述模型實現。

因此後面我們將使用Solid域中的boundingObject來實現碰撞檢測,馬上將會用到

言歸正傳:

 實現一個牆的形狀,如圖7.2,從截面看這是一個窄條長方形折了3次90°。 

4.Select thechildren field  and insert after aShape node.

這個為什麼使用Shape很簡單不用多解釋了

10. 這裡牆需要阻止機器人穿過,正是通過boundingObject域來實現,要記住邊界障礙物只能用一些簡單模型實現。這裡選擇的是(用原話來說Select the boundingObject field of the wall and create a Group node that will contain the four walls. In this Group, insert a Transform node in the children field. Add a Shape to the unique children of the Transform node in the children field. Add a Shape to the unique children of the Transform. Create a Material in th node Appearance and set its diffuseColor and specularColor to white......Now creat a Box as a geometry for this Shape node. Set the size of the Box to [0.01 0.1 1], so that it matches the size of a wall. Set the translation field of the Transform node to [0.495 0.05 0], so that it matches the position of the first wall.)這一大堆話我總結一下,就是在boundingObject的children域新增一個Group節點,在Group的children節點新增一個Transform節點,在Transform的children節點新增一個shape節點,在shape節點的appearance域新增一個Appearance節點,然後再其中的material域新增一個Material節點,修改顏色作為碰撞檢測條件,最後在shape節點的geometry域新增一個Box節點,最後移動match牆的尺寸。

那麼問題來了,回想最早實現牆那麼簡單,在solid的children節點新增一個shape節點,再在geometry域新增一個Extrusion節點,最後在cross-section處標註convex點即可。那麼為什麼不能在boundingObject上採用同樣的方式,而要如此麻煩呢。


如圖可見確實沒有Extrusion節點可用,第一想法就是Extrusion模型過於複雜,不適合作為邊界模型,再翻看一下reference manual手冊即可找到答案。

我們看下Extrusion,帶圓角的方框代表了幾何節點(geometry node),可以用於shape中geometry域的實現。而加了灰色陰影的是可以直接被用於boundingObject的。

言歸正傳:

如何在walls上match一個boundingObject呢?先上一個已經match上的一個bounding object圖(白線包圍的就是bounding object)


這裡的bounding object匹配的是0167圍成的wall,那麼要建立一個長為0.01,寬1,高0.1的長方體。這裡先了解下BOX節點的geometry圖


如何確定一個BOX的位置,其實就是確定質心的位置。因此我們將剛才設計的立方體放置到(x,y,z) = (0.495,0.05,0)處即可。

其他的wall都可以通過rotation進行旋轉放置,這裡rotation有4個域{x,y,z,alpha},x,y,z = 0,1 alpha = -3.14~3.14,這裡alpha取大於0的數時代表逆時針旋轉。x,y,z取1代表繞值為1的軸旋轉。


Now,let us create the obstacles:

和建立walls類似,首先選擇一個Solid節點。剩下的步驟幾乎一樣。就不做詳細討論了,大家按照文件一步一步就能完成,我偷個懶隨便放了兩個障礙物


Now,let us create a Robot

這裡的robot是一個DifferentialWheels節點,它包括幾個孩子節點:一個Transform節點作為body,兩個Solid節點作為wheels,兩個DistanceSensor節點作為infra-red sensor,一個Shape節點作為face

Robot
Derived from Solid.


Robot {
SFString controller "void"
SFString controllerArgs ""
SFBool synchronization TRUE
MFFloat battery []
3.36. ROBOT 89
SFFloat cpuConsumption 0 # [0,inf)
SFBool selfCollision FALSE
}


Direct derived nodes:DifferentialWheels, Supervisor


由於Robot直接派生DifferentialWheels類,因此首先建立一個DifferentialWheels節點。好吧我想說剩下的步驟都一樣直接上圖,robot這塊有不明白的留言吧。。。。












































相關文章