W17 <<
Previous Next >> basketball machine final
basketball machine add Mtb_robot
籃球機增加Mtb_robot取放球,還沒有計算位置,所以無法準確放到(x=1.002,y=0)點上。
3.0
使用老師的ik程式,使Mtb_robot放球到最終的位置(x=1.002,y=0)
但是把MTB_robot放到籃球機的場景裡,不能直接在程式裡打ik(1.002,0),因為MTB_robot沒有在座標原點上,所以要減掉MTB_robot的座標(0.7496,-2.3502),得出(0.2506,2.3502),才會移動到正確的座標。
3.1
-- 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*3
-- link 2 length
a2 =0.4*3
-- 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.2506, 2.3502)
print(theta[1], theta[2])
教學如何使用逆向運動函式使用在MTB_robot
檔案
教學影片:
W17 <<
Previous Next >> basketball machine final