40823131 cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • about
  • Stage1
    • W1
      • 建立網頁
      • Blog建立
    • W2
      • 分組(二人專案小組)
      • 利用Hamachi建立虛擬區域網路
      • 利用虛擬主機建立Ethercalc伺服器
    • W3
      • 初代機(version 1.0.0) ฅ^•ω•^ฅ
      • 貳代機(version 2.0.0) ^ↀᴥↀ^
      • 参代機(version 3.0.0) ଲ(^ⓛ ω ⓛ^)ଲ
      • 肆代機(version 4.0.0) V(=^・ω・^=)v
    • W4
      • 利用程式方法更改影片檔名
  • Stage2
    • W5
      • 分組組員
    • W6
      • Heroku小組網站
      • 運輸小車繪製
    • W7
      • push more easily
      • 程式控制
    • W8
      • 使用鍵盤程式控制小車移動
    • W9
      • 成果(自動化生產線速率程式控制小車ver.)
      • 成果(自動化生產線鍵盤程式控制小車ver.)
      • 心得
  • Stage3
    • W10
      • task1
      • task2-1
    • W11
      • task2-2
    • W12
      • 直播教學影片
    • W13
      • task3-About OBS setting videos
      • Use aegisub to edit and generate subtitles
    • Final專案進度
  • W14
    • 使用QT based GUI介面改寫 legacy GUI介面
    • 改用 CoppeliaSim 制式的 Lua Script 編寫與原先取放方塊零件相同的操控流程
  • Basic teaching
    • Create SSH KEY
    • Setting up putty for ssh
    • Use Leo Editor to create a web blog
    • Android phone camera instead of webcam teaching
  • W15
  • W16
  • Github帳號解除Flagged過程分享
  • Python grammar sort out
使用QT based GUI介面改寫 legacy GUI介面 << Previous Next >> Basic teaching

改用 CoppeliaSim 制式的 Lua Script 編寫與原先取放方塊零件相同的操控流程

場景檔(.ttt)

手臂程式(.lua)

吸盤程式(.lua)

完整檔案壓縮檔

此次程式的編寫是參考了CoppeliaSim中的Dobot機械手臂的程式,我們在stage2專案中,有使用到此機械手臂,它和MTB的機構項目非常相似,同樣是四軸,且同樣具有吸盤構造,故選擇參考其程式碼。

操作影片如下:

手臂程式:

function sysCall_init()
    corout=coroutine.create(coroutineMain)
end

function sysCall_actuation()
    if coroutine.status(corout)~='dead' then
        local ok,errorMsg=coroutine.resume(corout)
        if errorMsg then
            error(debug.traceback(corout,errorMsg),2)
        end
    else
        corout=coroutine.create(coroutineMain)
    end
end

function movCallback(config,vel,accel,handles)
    for i=1,#handles,1 do
        if sim.getJointMode(handles[i])==sim.jointmode_force and sim.isDynamicallyEnabled(handles[i]) then
            sim.setJointTargetPosition(handles[i],config[i])
        else    
            sim.setJointPosition(handles[i],config[i])
        end
    end
end

function moveToConfig(handles,maxVel,maxAccel,maxJerk,targetConf,enable)
    local currentConf={}
    for i=1,#handles,1 do
        currentConf[i]=sim.getJointPosition(handles[i])
        targetConf[i]=targetConf[i]*math.pi/180
    end
    sim.moveToConfig(-1,currentConf,nil,nil,maxVel,maxAccel,maxJerk,targetConf,nil,movCallback,handles)

    if enable then
        sim.writeCustomDataBlock(gripperHandle,'activity','on')
    else
        sim.writeCustomDataBlock(gripperHandle,'activity','off')
    end
end

function coroutineMain()
    modelBase=sim.getObjectHandle(sim.handle_self)
    gripperHandle=sim.getObjectHandle('suctionPad')
    modelName=sim.getObjectName(modelBase)
    motorHandles = {}
    for i=1,4,1 do
        motorHandles[i]=sim.getObjectHandle('MTB_axis'..i)
    end
    local vel=60
    local accel=10
    local jerk=10
    local maxVel={vel*math.pi/180,vel*math.pi/180,vel*math.pi/180,vel*math.pi/180}
    local maxAccel={accel*math.pi/180,accel*math.pi/180,accel*math.pi/180,accel*math.pi/180}
    local maxJerk={jerk*math.pi/180,jerk*math.pi/180,jerk*math.pi/180,jerk*math.pi/180}
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{0,0,0,0},true)
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{0,0,1.9,0},true)
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{0,0,-1.9,0},true)
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{-160,-43.5,0,203.5},false)
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{160,43.5,0,203.5},false)
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{160,43.5,1.90,-203.5},true)
    moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{160,43.5,-1.90,-203.5},true)
end

吸盤程式:

function sysCall_init()
    modelBase=sim.getObjectHandle(sim.handle_self)
    s=sim.getObjectHandle('suctionPadSensor')
    l=sim.getObjectHandle('suctionPadLoopClosureDummy1')
    l2=sim.getObjectHandle('suctionPadLoopClosureDummy2')
    b=sim.getObjectHandle('suctionPadBodyRespondable')
    sim.setLinkDummy(l,-1)
    sim.setObjectParent(l,b,true)
    m=sim.getObjectMatrix(l2,-1)
    sim.setObjectMatrix(l,-1,m)
    suctionPadLink=sim.getObjectHandle('suctionPadLink')
    local gripperBase=sim.getObjectHandle(sim.handle_self)
    infiniteStrength=true
    maxPullForce=3
    maxShearForce=1
    maxPeelTorque=0.1

end

function sysCall_cleanup() 
    sim.setLinkDummy(l,-1)
    sim.setObjectParent(l,b,true)
    m=sim.getObjectMatrix(l2,-1)
    sim.setObjectMatrix(l,-1,m)
end 

function sysCall_sensing() 
    parent=sim.getObjectParent(l)
    local on=sim.readCustomDataBlock(modelBase,'activity')=='on'
    if not on then
        if (parent~=b) then
            sim.setLinkDummy(l,-1)
            sim.setObjectParent(l,b,true)
            m=sim.getObjectMatrix(l2,-1)
            sim.setObjectMatrix(l,-1,m)
        end
    else
        if (parent==b) then
            index=0
            while true do
                shape=sim.getObjects(index,sim.object_shape_type)
                if (shape==-1) then
                    break
                end
                local res,val=sim.getObjectInt32Parameter(shape,sim.shapeintparam_respondable)
                if (shape~=b) and (val~=0) and (sim.checkProximitySensor(s,shape)==1) then
                    -- Ok, we found a respondable shape that was detected
                    -- We connect to that shape:
                    -- Make sure the two dummies are initially coincident:
                    sim.setObjectParent(l,b,true)
                    m=sim.getObjectMatrix(l2,-1)
                    sim.setObjectMatrix(l,-1,m)
                    -- Do the connection:
                    sim.setObjectParent(l,shape,true)
                    sim.setLinkDummy(l,l2)
                    break
                end
                index=index+1
            end
        else
            -- Here we have an object attached
            if (infiniteStrength==false) then
                -- We might have to conditionally beak it apart!
                result,force,torque=sim.readForceSensor(suctionPadLink) -- Here we read the median value out of 5 values (check the force sensor prop. dialog)
                if (result>0) then
                    breakIt=false
                    if (force[3]>maxPullForce) then breakIt=true end
                    sf=math.sqrt(force[1]*force[1]+force[2]*force[2])
                    if (sf>maxShearForce) then breakIt=true end
                    if (torque[1]>maxPeelTorque) then breakIt=true end
                    if (torque[2]>maxPeelTorque) then breakIt=true end
                    if (breakIt) then
                        -- We break the link:
                        sim.setLinkDummy(l,-1)
                        sim.setObjectParent(l,b,true)
                        m=sim.getObjectMatrix(l2,-1)
                        sim.setObjectMatrix(l,-1,m)
                    end
                end
            end
        end
    end
end 


使用QT based GUI介面改寫 legacy GUI介面 << Previous Next >> Basic teaching

Copyright © All rights reserved | This template is made with by Colorlib