完成之前的操作后終於來到最后一步——定義模型,即將之前創建的幾何體、關節等元素按層級關系組織成為一個整體。
將最后一個連桿robot_link_dyn6拖放到相應的關節(robot_joint6)下,成為其子節點。依次進行這樣的操作,直到機器人的基座為止,最終UR機器人的層級結構看起來如下圖所示:
[Robot model hierarchy]
由於根節點代表了整個機器人,這里我們將根節點重命名:robot代表機器人的動力學模型,robot_visibleBase代表機器人的可視化模型。接着選中模型根節點(即robot),雙擊其圖標打開Common屬性頁面,勾選"Object is model base"選項。
Object is model base: indicates whether the object should act as the base of a model. An object flagged as base of model has special properties (e.g. saving or copying the object will also automatically save/copy all its children and children's children, etc.). Additionally, when such an object is selected, the selection bounding box is displayed as thick stippled lines, encompassing the whole model.
同時也勾選"Object/model can transfer or accept DNA"選項。
Object / model can transfer or accept DNA: when this feature is enabled for an object or a model, then it will share a same identifier with all of its copies. An Object or model can then transfer its DNA (i.e. copy an instance of itself) to all of its siblings (i.e. objects/models with the same identifier), via the transfer DNA toolbar button. Imagine having 100 same robots in your scene that you want to modify in a similar way: simply modify one of them, select it, then click the transfer DNA toolbar button. This item should almost always be checked for a model base to facilitate model re-instanciation. 即勾選這一選項后能讓我們很方便的將某一個模型的更改應用到其它復制體上。
[DNA transfer toolbar button]
舉個例子:定義好模型並勾選"Object/model can transfer or accept DNA"后將下圖左邊的二連桿機構復制一份拖到右邊。接着將左側模型連桿L1的顏色改為黃色,然后選中左側模型的根節點J1,這時工具欄上的Transfer DNA to siblings按鈕變得可用。點擊這一按鈕后右邊的模型連桿L1顏色也變為黃色。同樣的可以將右邊模型連桿L2的顏色改為綠色或其它顏色,再transfer DNA,左側模型中連桿L2也會發生同樣的變化。
定義好模型后會出現一個包圍體將模型整各圍起來。不過由於關節、傳感器等物體的存在,包圍體比實際應有的體積要大。我們可以選擇要移出的關節,通過勾選"Don't show as inside model selection"選項將其從包圍體中除去。We could do the same procedure for all invisible items in our model. This is also a useful option in order to also exclude large sensors or other items from the model bounding box.
[Robot model bounding box]
為了防止模型被偶然更改,我們選擇模型中每個可見的幾何體,然后在Common屬性頁勾選" Select base of model instead"選項,這樣一來通過鼠標在場景中點中機器人的某一連桿時,整個機器人(根節點)就會被選中。This allows us to manipulate the model as if it was a single object. 如下圖所示,紅色的圓點為鼠標選擇的連桿,而作為代替機器人的基座將被選中:
之后我們將模型放置合適的位置和姿態上。It is considered good practice to position the model (i.e. its base object) at X=0 and Y=0.
現在我們點擊開始仿真按鈕,機械臂在重力作用下會塌下來,因為此時6個旋轉關節還沒有受控制。進入Joint Dynamic Properties對話框,勾選Motor enabled和Control loop enabled並選擇Position control(PID),對關節進行簡單的PID控制。
再次進行仿真,可以看到機器人將能保持在當前位置。此外,在仿真過程中我們可以點擊工具欄上的動態內容顯示按鈕,通過不同顏色顯示場景中物體所處的狀態。
[Dynamic content visualization button]
Only items that are taken into account by the physics engine will be display, and the display is color-coded. It is very important to always do this, and specially when your dynamic model doesn't behave as expected, in order to quickly debug the model. Similarly, always look at the scene hierarchy during simulation: dynamically enabled objects should display a ball-bounding icon on the right-hand side of their name.
Dynamic objects will appear in various colors, depending on their function or settings. Refer to following figure:
根據上面顏色對應的狀態我們可以看出:機器人基座為白色表示它是一個靜態的respondable物體;連桿為紅色表示它們是動態的respondable物體。
創建好機器人后我們可能要將其安裝在移動底盤上或在機器人的末端裝一個手爪。有下面兩種方式將動態體剛性地連接在一起:
- by grouping them: select the shapes, then [Menu bar --> Edit --> Grouping/Merging --> Group selected shapes].
- by attaching them via a force/torque sensor: a force torque sensor can also act as a rigid link between two separate dynamically enabled shapes.
第一種方式很簡單,我們來看看第二種:先通過[Menu bar --> Add --> Force sensor]添加力傳感器,在場景中將其移動到機器人末端,並在層次結構中將其拖放到最后一個連桿robot_link_dyn6下。更改其外觀與尺寸,並且改名為robot_attachment.
[Attachment force/torque sensor]
在模型瀏覽器中選擇一個手爪並拖入場景中,保持手爪處於選中狀態,然后按Control鍵同時選中robot_attachment力傳感器,接着點擊工具欄上面的"Assemble / Disassemble"按鈕,手抓就會被裝配到合適的位置。The gripper knew how to attach itself because it was appropriately configured during its model definition.
[Assemble / Disassemble button]
[Attached gripper]
手爪模型在定義時就確定了裝配時如何確定位置姿態,因此在考慮將UR機器人安裝到移動小車上時,我們同樣應該定義其裝配行為:先選中機器人模型,然后點擊Common屬性頁下的Assembling按鈕,彈出Assembling Behaviour對話框。消除"Object can have the 'parent' role"選項,然后點擊"Set Matrix"按鈕。This will memorize the current base object's local transformation matrix, and use it to position/orient itself relative to the mobile robot's attachment point.
- Object can have the 'child' role: if checked, then the object can be attached to another object (i.e. become another object's child)
- Object can have the 'parent' role: if checked, then the object can have another obejct attached to itself (i.e. become another object's parent)
- Set matrix: when the object is assembled, a specific transformation matrix will be used as its new local transformation matrix. By default that matrix is the identity matrix, but you can specify a specific matrix by clicking the button. This feature is useful in order to automatically position and orient an object correctly in relation to its new parent (e.g. in order to have a gripper automatically placed correctly at a robot's tooltip)
為了驗證上述功能,我們往場景中拖入一個KUKA Omnirob移動機器人。首先選中UR機器人,然后按Control鍵用鼠標選取移動平台上的attachment points,點擊工具欄上"Assemble / Disassemble"按鈕,此時我們的UR機器人應該正確的安裝在移動平台上面。
[Attached robot]
如果我們在裝配前改變UR機器人的姿態朝向,然后點擊"Set Matrix"按鈕記住機器人在局部坐標系中的位置姿態信息,那么之后進行裝配時UR機器人在移動平台上的朝向也會發生相應的變化(注意如果模型位置不在X=0,Y=0,Z=0處,那么安裝到移動平台時將會有一個偏移),如下圖所示:
對於用戶自己創建的模型如果以后想直接拖入場景中使用,可以選中模型根節點,然后在菜單欄中選擇File --> Save model as... 將其保存。If we saved it in the model folder, then the model will be available in the model brower.
保存時會出現一些提示,比如會提示選擇模型的縮略圖:
將模型命名為user model保存在系統models文件夾下,當新建一個場景時就可以在模型瀏覽器中找到我們自己創建好的模型:
至此,一個完整的機器人模型就已經創建好了。后續工作是為機器人添加各類傳感器和控制腳本控制機器人的運動以及行為。
參考: