用超音波感測器並編寫Scripts內部程式控制仿生獸配合道路轉彎、直走等等..

Proximity sensor

新增Proximity sensor,這次我參考Vrep內建範本"pioneer p3dx.ttm",學習並用來控制仿身獸joint的變數

首先,我建立8個sensor並配置個方向。

Sensor的形狀可以在內部修改,可以為圓錐形、梯形,這次我用扇形來做

因為感測器必須要感測到物體,所以模型設定裡有Detectable必須要勾起來,但仿身獸本身不需要被感測,則不設定。

點選Scripts,並設定

程式

if (sim_call_type==sim_childscriptcall_initialization) then
    usensors={-1,-1,-1}
    for i=1,8,1 do
        usensors[i]=simGetObjectHandle("Proximity"..i)
    end
    motorLeft=simGetObjectHandle("left_input")
    motorRight=simGetObjectHandle("right_input")
    noDetectionDist=2
    maxDetectionDist=0.5
    detect={0,0,0}
    braitenbergL={-0.2,-0.4,-0.6,-0.8,-1,-1.2,-1.4,-1.6}
    braitenbergR={-1.6,-1.4,-1.2,-1,-0.8,-0.6,-0.4,-0.2}
    v0=2.0
end
if (sim_call_type==sim_childscriptcall_actuation) then
    for i=1,8,1 do
        res,dist=simReadProximitySensor(usensors[i])
        if (res > 0) and (dist < noDetectionDist) then
            if (dist < maxDetectionDist) then
                dist=maxDetectionDist
            end
            detect[i]=1-((dist-maxDetectionDist)/(noDetectionDist-maxDetectionDist))
        else
            detect[i]=0
        end
    end

    vLeft=v0
    vRight=v0

    for i=1,8,1 do
        vLeft=vLeft+braitenbergL[i]*detect[i]
        vRight=vRight+braitenbergR[i]*detect[i]
    end

    simSetJointTargetVelocity(motorLeft,vLeft)
    simSetJointTargetVelocity(motorRight,vRight)
end
if (sim_call_type==sim_childscriptcall_sensing) then

    -- Put your main SENSING code here

end


if (sim_call_type==sim_childscriptcall_cleanup) then

    -- Put some restoration code here

end

影片

虎尾科技大學機械設計系 40423116 李冠辰 vrep 仿生獸,使用proximity sensor控制joint from 40423116 on Vimeo.

順便附上test版

虎尾科技大學機械設計系 40423116 李冠辰 Proximity sensor test from 40423116 on Vimeo.

檔案

40423116car.ttt

test.ttt


Comments

comments powered by Disqus