40823149

  • Home
    • Site Map
    • reveal
    • blog
  • stage1-7
    • 小組-1
    • w1
    • w2
    • w3
  • stage2-7
    • 小組-2
    • w5
    • w6~w7
  • stage3-6
    • 小組-3
    • w10
      • task1
      • task2
    • w11   Task2
      • stage1-6 remote API
      • stage2-7 remote API
    • w13~w14
      • gitlab
    • w15
      • Video and subtitle translation-1
      • Video and subtitle translation-2
    • w16
      • Onshape 零組件繪製
      • 建立 CoppeliaSim 4.1.0 MTB robot 場景
      • 手臂末端加入 components-gripper-suction pad 吸盤
      • 逆向運動學
      • Python remote API 逆向運動學函式
    • w17
      • stage3-ag6
      • 國立虎尾科技大學 - 機械設計工程系 - 協同產品設計實習 - 期末報告 - 學號40823149
手臂末端加入 components-gripper-suction pad 吸盤 << Previous Next >> Python remote API 逆向運動學函式

逆向運動學

w16-4

function move(j1,j2,j3,enable)
--三軸與吸盤
    modelBase=sim.getObjectAssociatedWithScript(sim.handle_self)
    --與腳本關聯的對象的句柄,如果腳本未關聯值為-1
    modelName=sim.getObjectName(modelBase)
    --modename=modelbase
    jointHandle={}
    --建立空列表
    j={j1*math.pi/180,j2*math.pi/180,j3*math.pi/180}
    --三個軸
    for i=1,3,1 do
    --for 迴圈1到3
        jointHandle[i]=sim.getObjectHandle('MTB_axis'..i)
        --讀取每個軸的名稱放入jointhandle列表
        sim.wait(1)
    end
    for i=1,3,1 do
        sim.setJointPosition(jointHandle[i],j[i])
        --設定jointhandle列表中的每根軸的徑度
        sim.wait(1)
    end
    
    if enable then
    --定義吸盤驅動變數,若為true執行下方程式,若為false則執行else下方程式。
        sim.setIntegerSignal(modelName .."activity",1)
        --設定訊號為1,為吸
    else
        sim.setIntegerSignal(modelName .."activity",0)
        --設定為訊號0,為不吸
    end
end

function sysCall_threadmain()
    move(0,0,0,true)
    move(0,0,-0.9,true)
    move(0,0,0,0,true)
    move(43.79,-66.2053,0,false)
    move(0,0,0,false)
    move(43.79,-66.2053,0,false)
    move(43.79,-66.2053,-0.9,true)
    move(43.79,-66.2053,0,true)
    move(-158.2529,-87.7894,0,false)
    move(0,0,0,0,false)
    move(-158.2529,-87.7894,0,false)
    move(-158.2529,-87.7894,-0.9,true)
    move(-158.2529,-87.7894,0,true)
    move(0,0,0,false)
end

-- The decimal point of number x is rounded to the nth place
function round(x, n)
    n = math.pow(10, n or 0)
    x = x * n
    if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end
    return x / n
end
 
-- radian to degree
deg = 180/math.pi
-- link 1 length
a1 = 0.467
-- link 2 length
a2 = 0.401
-- derivated based upon https://www.youtube.com/watch?v=IKOGwoJ2HLk&t=311s
function ik(x, y)
    -- (x, y) need to be located inside the circle with radius a1+a2
    if (x^2 + y^2) <= (a1+ a2)^2 then
        q2 = -math.acos((x^2+y^2-a1^2-a2^2)/(2*a1*a2))
        q1 = math.atan2(y, x) + math.atan2((a2*math.sin(q2)), (a1+a2*math.cos(q2)))
        return {round(q1*deg, 4), round(q2*deg, 4)}
    else
        print("Over range!")
        -- end the script execution
        os.exit()
    end
end
 
theta = ik(0.2, 0.7)
 
print(theta[1], theta[2])
  


手臂末端加入 components-gripper-suction pad 吸盤 << Previous Next >> Python remote API 逆向運動學函式

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