VREP中的力触觉设备接口(CHAI3D)
力反饋技術(shù)是一種新型的人機(jī)交互技術(shù),它允許用戶(hù)借助力反饋設(shè)備觸碰、操縱計(jì)算機(jī)生成的虛擬環(huán)境中的物體,并感知物體的運(yùn)動(dòng)和相應(yīng)的力反饋信息,實(shí)現(xiàn)人機(jī)力覺(jué)交互。雖然傳統(tǒng)的鼠標(biāo)、鍵盤(pán)、觸摸屏等交互手段可以滿(mǎn)足用戶(hù)與環(huán)境中物體交互的需求,但是缺乏力覺(jué)交互信息的反饋。力反饋技術(shù)結(jié)合其他的虛擬現(xiàn)實(shí)技術(shù),使用戶(hù)在交互過(guò)程中不僅能夠通過(guò)視、聽(tīng)覺(jué)通道獲取信息,還能夠通過(guò)觸覺(jué)通道感受模擬現(xiàn)實(shí)世界力覺(jué)交互的“觸感”。因此,力反饋技術(shù)的引入,使交互體驗(yàn)更加自然、真實(shí)。?
力反饋系統(tǒng)的實(shí)現(xiàn)過(guò)程中涉及到以下關(guān)鍵問(wèn)題: 力反饋計(jì)算模型設(shè)計(jì)、碰撞檢測(cè)、視覺(jué)與力覺(jué)的同步渲染,相應(yīng)地產(chǎn)生了針對(duì)解決上述問(wèn)題的一系列算法和接口。
1.?設(shè)計(jì)力反饋計(jì)算模型
力反饋計(jì)算模型用于計(jì)算虛擬環(huán)境中物體間交互時(shí)產(chǎn)生的力,并由力反饋設(shè)備傳遞給用戶(hù)。目前,力反饋算法主要采用基于物理建模方法的有限元模型和彈簧—質(zhì)點(diǎn)模型。其中,有限元模型將連續(xù)體離散為多個(gè)單元,分別對(duì)每個(gè)單元進(jìn)行模擬, 之后連接各單元模擬整個(gè)連續(xù)體,最后通過(guò)解方程組計(jì)算質(zhì)點(diǎn)的受力;彈簧—質(zhì)點(diǎn)模型首先將物體質(zhì)量離散到各個(gè)質(zhì)點(diǎn),并通過(guò)彈簧連接柔性物體離散后的質(zhì)點(diǎn),依據(jù)胡克定律計(jì)算質(zhì)點(diǎn)之間的力,從而模擬整個(gè)物體的受力。有限元模型能夠較好地滿(mǎn)足交互的真實(shí)性需求,但是運(yùn)算量大、求解過(guò)程復(fù)雜,難以滿(mǎn)足交互的實(shí)時(shí)性需求;而彈簧—質(zhì)點(diǎn)模型具有建模過(guò)程簡(jiǎn)單、計(jì)算量較小、交互實(shí)時(shí)性較好的特點(diǎn)。
2.?實(shí)現(xiàn)碰撞檢測(cè)
碰撞檢測(cè)用于實(shí)時(shí)檢測(cè)虛擬環(huán)境中物體間的碰撞情況,為之后圖形信息的繪制及力反饋信息的計(jì)算奠定基礎(chǔ)。當(dāng)前的碰撞檢測(cè)算法主要采用包圍盒技術(shù), 首先對(duì)物體的包圍盒進(jìn)行相交檢測(cè)( 模糊碰撞檢測(cè)), 當(dāng)包圍盒相交時(shí)其包圍的物體才有可能相交。然后進(jìn)行物體間的精細(xì)碰撞檢測(cè),當(dāng)包圍盒不相交時(shí),其包圍的物體一定不相交,結(jié)束物體間的碰撞檢測(cè)。
3.?增強(qiáng)力覺(jué)真實(shí)感
視覺(jué)與力覺(jué)的同步渲染用于保持較低刷新頻率的視覺(jué)信息(30fps ~ 60fps) 和較高刷新頻率的力覺(jué)信息(1000fps) 的一致性。目前,主流的力反饋接口OpenHaptics、CHAI3D等都支持視覺(jué)與力覺(jué)融合的應(yīng)用開(kāi)發(fā)。其中,OpenHaptics是SenseAble 公司針對(duì)Phantom系列力反饋設(shè)備研發(fā)的開(kāi)發(fā)工具包,包括QuickHaptics API、Haptic Device API、Haptic Library API 三個(gè)不同層次的接口庫(kù),能夠滿(mǎn)足不同用戶(hù)的設(shè)計(jì)需求;CHAI3D(Computer Haptics and Active Interface)是由斯坦福大學(xué)人工智能實(shí)驗(yàn)室研發(fā)的支持多種力反饋設(shè)備的開(kāi)源開(kāi)發(fā)工具包,它具有較好的可擴(kuò)展性,允許用戶(hù)在已有視覺(jué)、力覺(jué)渲染算法的基礎(chǔ)上根據(jù)自己的需要設(shè)計(jì)新的渲染算法,也可以通過(guò)添加驅(qū)動(dòng)的方法支持新的力反饋設(shè)備。
VREP中集成了CHAI3D插件,用戶(hù)可以在Lua腳本中調(diào)用其接口編寫(xiě)基于力反饋設(shè)備的仿真程序。在VREP的模型瀏覽器(Model browser/other/Interface to haptic device.ttm)中有一個(gè)力反饋設(shè)備接口模型,如下圖所示:
將其拖入場(chǎng)景中進(jìn)行仿真,但出現(xiàn)了CHAI3D初始化失敗的錯(cuò)誤:
解決方法是可以下載一個(gè)32位版本的VREP,然后重新編譯生成CHAI3D插件的動(dòng)態(tài)鏈接庫(kù)。下載CHAI3D 3.2后解壓,在modules\V-REP目錄下打開(kāi)相應(yīng)版本的VS解決方案文件(e.g.?CHAI3D-V-REP-VS2013.sln?if using VisualStudio 2013),然后生成Release版本下的32位動(dòng)態(tài)鏈接庫(kù),并將VREP安裝目錄中的替換掉。
In summary:
- Compile the?V-REP?module in?RELEASE?mode in?32-bit?configuration.
- Copy the file?v_repExtCHAI3D.dll?in the base directory of?V-REP.
- If you are using the Phantom haptic device, please also copy the file?hdPhantom32.dll?in the base directory of?V-REP. Copy any of the other files if you are using some other devices.
?
The CHAI3D scene can be controlled from V-REP through a set of LUA functions that allow the user to perform the following tasks:
- connect to haptic devices(Haptic devices can be connected to the CHAI3D scene by calling the?simExtCHAI3D_start()?LUA function)
- copy V-REP objects to the CHAI3D scene so that they can be "felt" with the haptic device
- keep the position and orientation of the CHAI3D objects in sync with their V-REP counterparts while the simulation is running
- constrain the behavior of the haptic device (e.g. to emulate a 2D force-feedback joystick by constraining the haptic device in a plane)
- change the characteristics of the haptic device constraints to reflect changes in the simulation
為了能讓設(shè)備輸出交互力,在VREP場(chǎng)景中創(chuàng)建好的物體還需要通過(guò)simExtCHAI3D_addShape()函數(shù)將其添加到CHAI3D的世界中去。添加到CHAI3D場(chǎng)景中后,連接好的力反饋設(shè)備就能“感受到”這個(gè)物體。如果物體在VREP場(chǎng)景中發(fā)生了變化,比如移動(dòng)或旋轉(zhuǎn),那么CHAI3D場(chǎng)景中對(duì)應(yīng)的物體也要通過(guò)simExtCHAI3D_updateShape()函數(shù)進(jìn)行更新。Any object contained in the V-REP scene can be added to the CHAI3D world by using the?simExtCHAI3D_addShape()?LUA function. Once an object is added to the CHAI3D scene, it can be "felt" and explored haptically using any haptic device connected to the?scene. If the object is moving in the V-REP simulation, it can be kept in sync on the CHAI3D side by using the?simExtCHAI3D_updateShape()?LUA function.
接下來(lái)在VREP中通過(guò)CHAI3D插件提供的Lua函數(shù)創(chuàng)建一個(gè)簡(jiǎn)單的靜態(tài)場(chǎng)景。小球代表力反饋設(shè)備末端的位置,立方體代表場(chǎng)景中的墻(或需要接觸交互的其它物體),當(dāng)移動(dòng)末端讓小球碰撞到立方體時(shí)設(shè)備能輸出一定的力讓用戶(hù)感受到。如下圖所示當(dāng)小球貼著立方體正面移動(dòng)時(shí),用戶(hù)能感受到“墻”的存在,且越靠向墻,受到的反作用越大。當(dāng)小球移開(kāi)墻面時(shí),力又變?yōu)榱恪顟B(tài)欄中輸出了小球位置、輸出力大小以及操作桿按鈕狀態(tài)(按下按鈕變?yōu)?):
注意CHAI3D中坐標(biāo)系方向的定義如下圖所示:
All quantities are expressed in IUS (metric) unit. The reference device coordinate system specifies that the x-axis is pointing towards the operator, the y-axis towards his or her right hand side, and the z-axis upward. 即X軸朝向操作者,Z軸豎直向上,Y軸指向操作者右方。返回的數(shù)據(jù)以米為單位。
腳本代碼如下:
addCuboid=function(siz,pos,orient)if CHAI3DPluginInitialized thenlocal cuboidHandle=simCreatePureShape(0,4+16,siz,1)simSetObjectParent(cuboidHandle,modelHandle,true)simSetObjectPosition(cuboidHandle,modelHandle,pos)simSetObjectOrientation(cuboidHandle,modelHandle,orient)return addMesh(cuboidHandle,true), cuboidHandleendreturn -1, -1 end-- copy V-REP objects to the CHAI3D scene so that they can be "felt" with the haptic device addMesh=function(shapeHandle,whenRemovedEraseMesh)if CHAI3DPluginInitialized thenif not objCont thenobjCont={}endobjCont[#objCont+1]=shapeHandlelocal vertices,indices=simGetShapeMesh(shapeHandle)local pos=simGetObjectPosition(shapeHandle,modelHandle)local orient=simGetObjectOrientation(shapeHandle,modelHandle)local hapticObjId=simExtCHAI3D_addShape(vertices,indices,pos,orient,1000)objCont[#objCont+1]=hapticObjIdobjCont[#objCont+1]=whenRemovedEraseMeshreturn hapticObjIdendreturn -1 endremoveAllObjects=function()if CHAI3DPluginInitialized thenif objCont thenfor i=1,(#objCont)/3,1 dolocal obj=objCont[3*(i-1)+1]if objCont[3*(i-1)+3] thensimRemoveObject(obj)endsimExtCHAI3D_removeObject(objCont[3*(i-1)+2])endendobjCont=nilend endif (sim_call_type==sim_childscriptcall_initialization) thenmodelHandle=simGetObjectAssociatedWithScript(sim_handle_self)-- Check if the plugin is loaded:moduleName=0moduleVersion=0index=0pluginNotFound=truewhile moduleName domoduleName,moduleVersion=simGetModuleName(index)if (moduleName=='CHAI3D') thenpluginNotFound=falseendindex=index+1endif (pluginNotFound) thensimDisplayDialog('Error','CHAI3D plugin was not found, or was not correctly initialized (v_repExtCHAI3D.dll).',sim_dlgstyle_ok,false,nil,{0.8,0,0,0,0,0},{0.5,0,0,1,1,1})else-- Start the device:local toolRadius=0.005 -- the radius of the toollocal workspaceRadius=0.2 -- the workspace radiusif simExtCHAI3D_start(0,toolRadius,workspaceRadius)~=1 thensimDisplayDialog('Error','Device failed to initialize.',sim_dlgstyle_ok,false,nil,{0.8,0,0,0,0,0},{0.5,0,0,1,1,1})elseCHAI3DPluginInitialized=truetoolSphereHandle=simCreatePureShape(1,4+16,{toolRadius*2,toolRadius*2,toolRadius*2},1)simSetObjectParent(toolSphereHandle,modelHandle,true)simSetShapeColor(toolSphereHandle,'',0,{1,1,1})-- Create a haptic cuboid:local cuboidSize={0.1,0.1,0.1}local cuboidPosition={0.01,-0.01,0.05}local cuboidOrientation={0,0,0}cuboidId,cuboidHandle=addCuboid(cuboidSize,cuboidPosition,cuboidOrientation)--[[-- Create a haptic mesh from an existing V-REP shape:meshHandle=simGetObjectHandle('mesh')local removeOriginalShapeWhenDone=falsemeshId=addMesh(meshHandle,removeOriginalShapeWhenDone) --]]endend endif (sim_call_type==sim_childscriptcall_actuation) thenendif (sim_call_type==sim_childscriptcall_sensing) thenif CHAI3DPluginInitialized then-- Read the position of the cursor:local p=simExtCHAI3D_readPosition(0)-- Reflect the position of the cursor in V-REP: simSetObjectPosition(toolSphereHandle,modelHandle,p)-- Read the the interaction force:local f=simExtCHAI3D_readForce(0)-- Read the buttons of the device:local b = simExtCHAI3D_readButtons(0)local info = string.format("Position:%.2f,%.2f,%.2f Force:%.2f,%.2f,%.2f Button State:%d",p[1],p[2],p[3],f[1],f[2],f[3],b) simAddStatusbarMessage(info)end endif (sim_call_type==sim_childscriptcall_cleanup) thenif CHAI3DPluginInitialized then-- Remove all Haptic objects (objects and forces): removeAllObjects()-- Remove all objects in the haptic scene: simExtCHAI3D_reset()end end? 可以看出使用CHAI3D就能很方便的讓力反饋設(shè)備感知場(chǎng)景中的環(huán)境,輸出力。如果不使用CHAI3D,則需要自行獲取VREP中物理引擎計(jì)算的接觸力信息,然后轉(zhuǎn)換成合適的值發(fā)送給設(shè)備去渲染接觸力。
?
?
?
參考:
CHAI3D plugin for V-REP Documentation
Haptic Data Retrieve—VREP Forum
VREP Modules—CHAI3D Forum
CHAI3D Current Release (Version 3.2)
轉(zhuǎn)載于:https://www.cnblogs.com/21207-iHome/p/7306217.html
總結(jié)
以上是生活随笔為你收集整理的VREP中的力触觉设备接口(CHAI3D)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 1平方公里等于多少亩(土地面积如何计算亩
- 下一篇: 如何多增加一个无线路由器 怎么多增加一个