V-rep學習筆記:機器人模型創建3—搭建動力學模型


   接着之前寫的V-rep學習筆記:機器人模型創建2—添加關節繼續機器人創建流程。如果已經添加好關節,那么就可以進入流程的最后一步:搭建層次結構模型和模型定義(build the model hierarchy and finish the model definition)。但是想要進行動力學仿真(碰撞、接觸、自由落體...)的話,還需要進行額外的一些操作:

  • Building the dynamic shapes

  VREP中幾何體的屬性可以分為:

  1. dynamic or static: 具有動態屬性的物體會在重力影響下墜落或在其它外力/力矩作用下發生運動狀態的改變。而靜態物體則會在場景中靜止不動,如地面,或跟隨其父節點運動(or follow the movement of its parent in the scene hierarchy)。
  2. respondable or non-respondable:  respond是回答,響應的意思。a respondable shape will cause a collision reaction with other respondable shapes. 即respondable屬性用於控制物體的碰撞響應,non-respondable物體在與其它物體發生碰撞時,物理引擎不會進行計算,會出現穿透的現象。

  During dynamic simulation, static shapes will not be influenced (i.e. their position relative to their parent object is fixed), whereas non-static shapes will be directly influenced by gravity or other constraints (e.g. dynamically enabled joints. Respondable shapes influence each other during dynamic collision (i.e. they produce a mutual collision reaction, they will bounce off each other). 

  可以進行動力學仿真的物體在仿真過程中可以通過下面的圖標來識別:

[Icon marking dynamically simulated objects]

   當由於某些原因導致物體不能進行動力學仿真時,會提示警告:

[Warning icon when an object cannot be dynamically simulated]

   為了進行快速穩定的仿真計算,Respondable物體的形狀應該越簡單越好。物理引擎可以仿真下面5種幾何體,其性能和穩定性各有差異:  

  1. Pure shapesa pure shape will be stable and handled very efficiently by the physics engine. The draw-back is that pure shapes are limited in geometry: mostly cuboids, cylinders and spheres. If possible, use those for items that are in contact with other items for a longer time (e.g. the feet of a humanoid robot, the base of a serial manipulator, the fingers of a gripper, etc.).

  看下面的一個例子,左邊的立方體是在Blender軟件中導出的STL網格模型,是一個最簡單的8個頂點的立方體;右邊是VREP中添加的Primitive立方體。將它們設為動態物體,並且respondable,放置在地面上。選擇Bullet物理引擎開始仿真,可以看出左邊導入的網格模型不穩定,一會就掉了下去,而右邊的primitive shape始終保持穩定;如果物理引擎換成ODE,開始仿真一會左邊導入的模型將會彈飛...;如果換成Vortex或Newton引擎,結果會好很多,兩個物體都能穩定在地面。因此,機器人模型與外界環境發生交互和接觸的部分最好是Pure shape,以提高計算效率和穩定性。At any time, the user is free to quickly switch from one engine to the other according to his/her simulation needs. The reason for this diversity in physics engine support is that physics simulation is a complex task, that can be achieved with various degrees of precision, speed, or with support of diverse features.

  2. Pure compound shapes: a pure compound shape is a grouping of several pure shapes. It performs almost as well as pure shapes and shares similar properties. Pure compound shapes can be generated by grouping several pure shapes.

  在VREP軟件的motionPlanningAndGraspingDemo.ttt場景中桌子上有一個水杯,這個水杯能穩定地與桌面接觸。雖然看上去這像是一個導入的網格體,但實際上它是由許多pure cuboid組成的pure compound shapes(見圖中右側的杯子),它被隱藏在圖層9中,只用網格模型來做顯示,而用更穩定的pure compound shapes來計算與桌面的接觸。

  3. Convex shapes: a convex shape will be a little bit less stable and take a little bit more computation time when handled by the physics engine. It allows for a more general geometry (only requirement: it need to be convex) than pure shapes. 

  Whenever possible, try using pure shapes as respondable shapes. This is however not always easy to do, or practical. In that case, you can generate a convex shape, or a convex decomposed shape. Convex shapes perform faster and are more stable than random shapes (but they are still not as fast and stable as pure shapes!). Select the shapes you wish to simplify as convex shapes, then select [Menu bar --> Edit --> Morph selected shapes into convex shapes...]

[Non-convex model (left) and corresponding convex-decomposed model (right)]

  4. Compound convex shapes: a convex compound shape is a grouping of several convex shapes. It performs almost as well as convex shapes and shares similar properties. It can be generated by grouping several convex shapes.

  5. Random shapes: a random shape is a shape that is not convex nor pure. It generally has poor performance (calculation speed and stability). Avoid using random shapes as much as possible.

  注意當直接把簡化后的網格體設為respondable時會彈出警告對話框,提示這樣做會影響物理引擎的計算性能,最好使用pure shapes或convex shapes代替。

   只從性能來看,選擇的優先順序為:pure shapes > pure compound shapes > convex shapes > compound conves shapes ≫ random shapes. 綜合仿真性能以及幾何外觀,我們考慮使用基本圓柱體作為UR機器人基座,凸殼或其組合作為連桿來構建機器人動力學模型。用圓柱體和凸殼搭建機器人動態模型雖然可以提高計算性能,但是如果直接用它作為外觀展示就不太好了,這樣會顯得模型比較粗糙。因此,我們可以將其移動到隱藏圖層中,作為之前創建的可視化模型的對應。The hidden part will represent the dynamic model and be exclusively used by the physics engine, while the visible part will be used for visualization, but also for minimum distance calculations, proximity sensor detections, etc.

  下面以官方幫助文檔中的UR5機器人為例進行講解。首先處理機器人基座:進入網格編輯模式,先刪除多余的線纜,然后選中所有面后提取圓柱體,如下圖所示:

 [Pure cylinder generation procedure, in the triangle edit mode]

  將生成的圓柱體重命名為robot_dyn,並移動到圖層9中隱藏起來。剩下的連桿可以用凸殼或凸殼組合來模擬。先選中第一個連桿,然后通過[Menu bar --> Add --> Convex hull of selection]來添加凸殼,同樣將其重命名為robot_link_dyn1並移動到圖層9中隱藏。 

[Original shape, and convex shape]

  當提取的凸殼包含的形狀細節不夠多時可以先手動提取多個凸殼,然后將其合並為一個整體[Menu bar --> Edit --> Grouping/Merging --> Group selected shapes];或者可以使用VREP提供的自動提取凸殼組合體的工具[Menu bar --> Add --> Convex decomposition of selection]:

  這里用到了一個開源庫V-HACDThe V-HACD library decomposes a 3D surface into a set of "near" convex parts),這個開源庫可以將原始形狀復雜的幾何體提取成凸殼組合,既保留了凸殼的運算性能,又逼近了原始形狀。

  至於為什么有時不能單純的用凸殼來代替原始物體可以看看下面這個例子。下圖中原本加上尾翼的汽車尾部是呈現凹狀的,但由於使用凸殼來近似代,如果放一個箱子在那個位置,會導致箱子“懸浮”在汽車上面,違反物理常識。一個更直觀的例子是如果我們把一個碗簡單的提取出凸殼,那么我們將不能在這個碗里放入任何東西!Objects will just float on top of it. In this case, we can use a convex decomposition of the concave shape.

  鑒於上面這種情況,就需要將凹狀物體(或形狀復雜的物體)分解為幾個簡單凸殼的組合。在許多例子中,凸分解(convex decomposition)的工作常常由手工完成,因為實時仿真中最重要的就是性能,而幾何體的形狀會嚴重影響計算性能(It’s generally a good idea to create very simple physical representations for complex graphic objects)。下圖是凸分解后的汽車: 

 

  再回到我們的UR機器人,從下圖可以看出與之前簡單添加的凸殼相比使用V-HACD提取的凸殼組合更接近真實形狀:

[Original shape, and convex decomposed shape pendant]

  接下來我們可以使用同樣的方法處理剩下的幾個連桿,處理完成后將每個表現外觀的幾何體拖到其相應的動態幾何體下(attach each visible shape to its corresponding invisible dynamic pendant) :

[Visible shapes attached to their dynamic pendants] 

  到這里我們的動力學模型基本已經構建完畢,但還有下面一些選項要設置:

  首先,我們搭建在隱藏圖層的動力學模型只是為了供物理引擎進行動力學計算,因此其它一些不必要的計算可以取消。在物體的Object common properties屬性對話框的Object special properties欄去掉所有選項

  然后,設置每個連桿的碰撞屬性: 勾選Body is respondable選項。並勾選基座的Local respondable mask的前4位,連桿1相應的后4位,連桿2前4位...這樣一直交替錯開,避免機械臂自身連桿之間的碰撞相應(once the model will be defined, consecutive dynamic shapes of the robot will not generate any collision response when interacting with each other)。

  Respondable mask: indicates when a collision response is generated. The mask is composed by two 8-bit values, local and global. If two colliding shapes share any of their parents (direct or indirect), then the local masks are used, otherwise the global masks are used. If two shapes' AND-combined masks (local or global) is different from zero, then a collision response will be generated. 即當兩個物體碰撞掩碼按位與時如果得到非零值,則兩個物體干涉時會發生碰撞;如果得到零,則兩個物體會相互穿透。

   下面舉一個簡單的例子:創建兩個立方體(沒有共同的父節點),則Global respondable mask會起作用。第一個立方體勾選前面4位,第二個立方體勾選后4位,掩碼之間沒有重合,因此按位與的結果為0。仿真時上方的物體自由墜落,會穿透下面的立方體,最終落在地板上。如果將上面的立方體掩碼全部去掉,仿真時它會連地板一起穿透,直接掉下去(因為去掉了Global respondable mask的所有位,不會與場景中任何物體發生碰撞)。

  最后,將之前提取的凸殼設置為dynamic:在Rigid Body Dynamics Properties對話框中勾選Body is dynamic。我們可以人工輸入幾何體的質量和慣性矩,或者通過點擊"Compute mass & inertia properties for selected convex shapes"按鈕,根據幾何體形狀和設定的密度自動計算出質量以及慣性矩

  注意機器人的基座有些特別:通常基座都固定在地面靜止不動,因此不需要設置成動態體,否則仿真時會掉下去。但當我們想把機器人裝在一個移動小車上使用時,就要將其設置為dynamic。在動力學屬性對話框中先勾選"Set to dynamic if gets parent",然后去掉 "Body is dynamic"選項,即可實現把基座裝在移動小車上時它是動態的,單獨使用(沒有父節點)時它是靜態的。

 

 

參考:

Building a clean model tutorial

Designing dynamic simulations

Khaled Mamou's Blog

https://github.com/kmammou/v-hacd

Video Game Physics Tutorial - Part II: Collision Detection for Solid Objects

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM