V-rep學習筆記:Reflexxes Motion Library 2


   VREP中的simRMLMoveToPosition函數可以將靜態物體按照設定的運動規律移動到指定的目標位置/姿態。If your object is dynamically enabled, it will not work (since in that case the position of the object is dictated by the physics engine). In that case, make sure to uncheck the Body is dynamic checkbox.

  下面在原點處創建一個Dummy,為其添加threaded child script(The simRMLMoveToPosition function can only be called from child scripts running in a thread (since this is a blocking operation) ),並使用Graph記錄其位置-速度-加速度信息。

local h=simGetObjectAssociatedWithScript(sim_handle_self)

local currentVel={0,0,0,0}
local currentAccel={0,0,0,0}
local maxVel={0.2,0.2,0.2,0.2}
local maxAccel={0.1,0.1,0.1,0.1}
local maxJerk={0.1,0.1,0.1,0.1}
local targetPos={1,0,0}
local targetVel={0,0,0,0}

simRMLMoveToPosition(h,-1,-1,currentVel,currentAccel,maxVel,maxAccel,maxJerk,targetPos,nil,targetVel)
simWait(1)
simStopSimulation()

  Graph的Data stream type中沒有加速度的選項,但是注意下面有個Data transformation(determines how the selected data stream is transformed)選項框可以對原始數據進行微分、積分、縮放、平移等變換。

  Raw uses the original data stream, Derivative uses the time derivative of the data stream (e.g. if the raw data stream is the position of an object, then data will be its velocity), Integral uses the time integral of the data stream (e.g. if the raw data is the velocity of an object, then data will be its position) and Cumulative uses the cumulative value of the data stream (e.g. if the raw data is the surface cut by a mill, then data will be the total surface cut by that mill during the simulation). Additionally, the data can be scaled, shifted, and a moving average period specified.

   選擇記錄Dummy的X方向絕對速度,然后在Data transformations選項框中選擇Derivative對數據進行微分,得到X方向加速度:

  下圖記錄了Dummy沿X軸運動1m時的位置、速度、加速度隨時間的變化曲線。可以看出在開始的加速階段,加速度在加加速度(Jerk)限制下以梯形曲線達到最大值0.1m/s2,此后進行一段勻加速直線運動,速度曲線為直線段,位置曲線為二次曲線;達到最大速度0.2m/s時進行勻速直線運動,此時加速度為0,位置曲線為直線段。

  另外需要注意的是simRMLMoveToPosition是一個阻塞模式(blocking operation)的函數,前一個函數執行完后才會繼續執行下一個。下面連續兩行代碼讓dummy先按規律運動到(1,0,0)處然后再返回遠點:

simRMLMoveToPosition(h,-1,-1,currentVel,currentAccel,maxVel,maxAccel,maxJerk,targetPos,nil,targetVel)
simRMLMoveToPosition(h,-1,-1,currentVel,currentAccel,maxVel,maxAccel,maxJerk,{0,0,0},nil,targetVel)

   使用simRMLMoveToPosition並配合逆運動學可以實現機器人的路徑控制:控制Target的目標位置/姿態和運動規律,VREP的運動學逆解解算器會自動讓Tip跟隨Target運動。下面在場景中拖入ABB IRB4600機器人模型,創建4個路徑點pos1~pos4,使機器人按照指定的運動規律依次經過這4個路徑點。

-- This is a threaded script!

getTargetPosVectorFromObjectPose=function(objectHandle)
    local p=simGetObjectPosition(objectHandle,targetBase)
    local o=simGetObjectQuaternion(objectHandle,targetBase)
    return p,o
end


threadFunction=function()
    while simGetSimulationState()~=sim_simulation_advancing_abouttostop do

        -- target is the object that the robot's tooltip will try to follow via IK, which means that
        -- if you change the position/orientation of target, then the robot's tooltip will try to follow
        -- target is used so that all position and orientation values are always relative to the robot base
        -- (e.g. so that if you move the robot to another position, you will not have to rewrite this code!)

        -- Go to pos1:
        targetP,targetO=getTargetPosVectorFromObjectPose(pos1_handle)
        simRMLMoveToPosition(target,targetBase,-1,nil,nil,maxVel,maxAccel,maxJerk,targetP,targetO,nil)
        -- Go to pos2:
        targetP,targetO=getTargetPosVectorFromObjectPose(pos2_handle)
        simRMLMoveToPosition(target,targetBase,-1,nil,nil,maxVel,maxAccel,maxJerk,targetP,targetO,nil)
        -- Go to pos3:
        targetP,targetO=getTargetPosVectorFromObjectPose(pos3_handle)
        simRMLMoveToPosition(target,targetBase,-1,nil,nil,maxVel,maxAccel,maxJerk,targetP,targetO,nil)
        -- Go to pos4:
        targetP,targetO=getTargetPosVectorFromObjectPose(pos4_handle)
        simRMLMoveToPosition(target,targetBase,-1,nil,nil,maxVel,maxAccel,maxJerk,targetP,targetO,nil)
    end
end

-- Initialization:
simSetThreadSwitchTiming(2) 

target=simGetObjectHandle('IRB4600_IkTarget')
targetBase=simGetObjectHandle('IRB4600')

pos1_handle=simGetObjectHandle('pos1')
pos2_handle=simGetObjectHandle('pos2')
pos3_handle=simGetObjectHandle('pos3')
pos4_handle=simGetObjectHandle('pos4')


-- Set-up some of the RML vectors:
maxVel={0.4,0.4,0.4,1.8}
maxAccel={0.3,0.3,0.3,0.9}
maxJerk={0.2,0.2,0.2,0.8}


-- Here we execute the regular thread code:
res,err=xpcall(threadFunction,function(err) return debug.traceback(err) end)
if not res then
    simAddStatusbarMessage('Lua runtime error: '..err)
end

 

參考:

Reflexxes Motion Libraries  Manual and Documentation

V-REP: Reflexxes Motion Library Demonstration

V-rep學習筆記:Reflexxes Motion Library 1


免責聲明!

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



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