40823145-cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Copperation
  • Midterm
    • Week 1
      • Create New repository and Wecsite
    • Week 2
    • Week 3
      • upgrade cmsimde
  • Stage1-ag1
  • stage2-ag1
  • stage3-ag1
    • Task1
    • Task2
    • W13
    • W14
      • MTB_Robot
      • gitlab
    • W15
    • W16
  • Final
  • Note
    • Upgrade pip
    • ssh
    • Leo Editor
      • Blog
      • Reveal
    • Code
  • FreeCAD protable
W15 << Previous Next >> Final

W16

1. Onshape 零組件繪製

Onshape零件連結

MTB_robot零件下載

MTB_base

MTB_link1

MTB_link2

MTB_link3

組合

2. 建立 CoppeliaSim 4.1.0 MTB robot 場景

MTB_1.ttt

MTB_1.lua

操作與講解:

3. 手臂末端加入 components-gripper-suction pad 吸盤

W16_keyboard.ttt

mtb_w16b.lua

mtb_w16s.lua

操作與講解:

function sysCall_init() 
    axis1=sim.getObjectHandle('MTB_axis1')
    axis2=sim.getObjectHandle('MTB_axis2')
    axis3=sim.getObjectHandle('MTB_axis3')
    axis4=sim.getObjectHandle('MTB_axis4')
    mtb3=sim.getObjectHandle('MTB_link3')
    suctionPad=sim.getObjectHandle('suctionPad')
    BaseFrame=sim.getObjectHandle("BaseFrame")
    block =sim.getObjectHandle("block")
    deg1 = 0
    deg2 = 0
    distance3 = 0
    modelBase=sim.getObjectHandle(sim.handle_self)
    robotBase=modelBase
    robotName='suctionPad'
    deg = math.pi/180
     
end
function sysCall_actuation() 
    calibration = 0.0042
    message, auxiliaryData=sim.getSimulatorMessage()
        while message ~= -1 do
            key=auxiliaryData[1]
            sim.addStatusbarMessage('????? key:'..key)
            if (message==sim.message_keypress) then
            if (auxiliaryData[1]==112) then --p activate the suction pad
                sim.setScriptSimulationParameter(sim.getScriptAssociatedWithObject(suctionPad),"active",'true')
                end -- if p
                if (auxiliaryData[1]==113) then --q deactivate the suction pad
                sim.setScriptSimulationParameter(sim.getScriptAssociatedWithObject(suctionPad),'active','false')
                end -- if q
                if (auxiliaryData[1]==108) then --l 
                     deg1 = deg1+0.4*deg
                     sim.setJointPosition(axis1, deg1)
                end -- if l
                if (auxiliaryData[1]==114) then --r 
                     deg1 =deg1-0.4*deg
                     sim.setJointPosition(axis1, deg1)
                end -- if r
                 if (auxiliaryData[1]==103) then --g
                     deg2 =deg2-0.4*deg
                     sim.setJointPosition(axis2, deg2)
                end -- if r
                 if (auxiliaryData[1]==104) then --h 
                     deg2 =deg2+0.4*deg
                     sim.setJointPosition(axis2, deg2)
                end -- if r
                if (auxiliaryData[1]==100) then --d 
                     distance3 = distance3 + 0.03 + calibration
                     sim.setJointPosition(axis3, distance3)
                end -- if d
                if (auxiliaryData[1]==117) then --u
                     distance3 = distance3 - 0.03 - calibration
                     sim.setJointPosition(axis3, distance3)
                end -- if u
                if (auxiliaryData[1]==98) then --b
                     deg1 =0
                     deg2 =0
                     sim.setJointPosition(axis1, deg1)
                     sim.setJointPosition(axis2, deg2)
                end -- if b
           end  -- if
    message, auxiliaryData=sim.getSimulatorMessage()
        end -- while
end -- function

吸盤程式:

function sysCall_init() 
    s=sim.getObjectHandle('suctionPadSensor')
    l=sim.getObjectHandle('suctionPadLoopClosureDummy1')
    l2=sim.getObjectHandle('suctionPadLoopClosureDummy2')
    b=sim.getObjectHandle('suctionPad')
    suctionPadLink=sim.getObjectHandle('suctionPadLink')
 
    infiniteStrength=sim.getScriptSimulationParameter(sim.handle_self,'infiniteStrength')
    maxPullForce=sim.getScriptSimulationParameter(sim.handle_self,'maxPullForce')
    maxShearForce=sim.getScriptSimulationParameter(sim.handle_self,'maxShearForce')
    maxPeelTorque=sim.getScriptSimulationParameter(sim.handle_self,'maxPeelTorque')
 
    sim.setLinkDummy(l,-1)
    sim.setObjectParent(l,b,true)
    m=sim.getObjectMatrix(l2,-1)
    sim.setObjectMatrix(l,-1,m)
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)
    if (sim.getScriptSimulationParameter(sim.handle_self,'active')==false) 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
            -- Here we want to detect a respondable shape, and then connect to it with a force sensor (via a loop closure dummy dummy link)
            -- However most respondable shapes are set to "non-detectable", so "sim.readProximitySensor" or similar will not work.
            -- But "sim.checkProximitySensor" or similar will work (they don't check the "detectable" flags), but we have to go through all shape objects!
            index=0
            while true do
                shape=sim.getObjects(index,sim.object_shape_type)
                if (shape==-1) then
                    break
                end
                if (shape~=b) and (sim.getObjectInt32Parameter(shape,sim.shapeintparam_respondable)~=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
    if (sim.getSimulationState()==sim.simulation_advancing_lastbeforestop) then
        sim.setLinkDummy(l,-1)
        sim.setObjectParent(l,b,true)
        m=sim.getObjectMatrix(l2,-1)
        sim.setObjectMatrix(l,-1,m)
    end
end

4. 逆向運動學函式

MTB_4.ttt

MTB_4.lua

MTB_4s.lua

操作與講解:

根據 W15 課程內容之 Inverse Kinematics 方程式 (影片1 或影片2),使用(0.2, 0.7, 0.05) 與 (-0.3, -0.55, 0.05)計算出角度

(0.2, 0.7, 0.05)

(-0.3, -0.55, 0.05)

5. Python remote API 逆向運動學函式

MTB_remote_API

操作與講解:


W15 << Previous Next >> Final

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