這頁會完整呈現全部手足球的版本,若要參考請標示來原出處,由於版本過多可能已經搞混,目前將還記得的推上共15種。Download_all (解壓密碼是俺學號da)
Read_me:
包含中後期版本
圖檔更新頻繁所以沒有打入版本也沒加入壓縮中
V-rep中操作手足球與電腦對打
建議調慢一格速度
若要操作最終版本
操作說明:方向鍵的左右下按鍵 + zxcv 分別按照順序從 z 的守門員到 v 的最前排 + R 鍵用來讓球回位到中間(怕卡bug)
FTB_Version(1):算是最初的版本,不包含code,場地設計最初版本,人員有20人,全部碰裝關係都沒設定好,一碰就倒的且只有上下左右的版本。
.gif)
function sysCall_init()
Slide_rail= sim.getObjectHandle('R1')
Roller= sim.getObjectHandle('RR1')
Slide_rail_v=0
Roller_v=0
dVel=0.5
end
function sysCall_actuation()
message,auxiliaryData=sim.getSimulatorMessage()
while message~=-1 do
if (message==sim.message_keypress) then
if (auxiliaryData[1]==32) then
Roller_v = Roller_v - dVel*20
if (Roller_v > 0) then
Roller_v = 0
end
end
if (auxiliaryData[1]==2008) then
Roller_v = Roller_v + dVel*20
if (Roller_v < 0) then
Roller_v = 0
end
end
if (auxiliaryData[1]==2009) then
Slide_rail_v = Slide_rail_v + dVel/15
if (Slide_rail_v < 0) then
Slide_rail_v = 0
end
end
if (auxiliaryData[1]==2010) then
Slide_rail_v = Slide_rail_v - dVel/15
if (Slide_rail_v > 0) then
Slide_rail_v = 0
end
end
end
message,auxiliaryData=sim.getSimulatorMessage()
end
sim.setJointTargetVelocity(Slide_rail,Slide_rail_v)
sim.setJointTargetVelocity(Roller,Roller_v)
end
FTB_Version(2):設定好大部分桿件的作動關係,方向鍵及踢球完成,設定好四根同動,與上個版本相差最多的版本...
.gif)
function sysCall_init()
Slide_rail= sim.getObjectHandle('R1')
Roller= sim.getObjectHandle('RR1')
Slide_rail2= sim.getObjectHandle('R2')
Roller2= sim.getObjectHandle('RR2')
Slide_rail3= sim.getObjectHandle('R3')
Roller3= sim.getObjectHandle('RR3')
Slide_rail4= sim.getObjectHandle('R4')
Roller4= sim.getObjectHandle('RR4')
Slide_rail_v=0
Roller_v=0
Roller_v2=0
Roller_v3=0
Roller_v4=0
dVel=0.5
end
function sysCall_actuation()
message,auxiliaryData=sim.getSimulatorMessage()
while message~=-1 do
if (message==sim.message_keypress) then
if (auxiliaryData[1]==122) then
Roller_v = Roller_v - dVel*20
if (Roller_v > 0) then
Roller_v = 0
end
end
if (auxiliaryData[1]==120) then
Roller_v2 = Roller_v2 - dVel*20
if (Roller_v2 > 0) then
Roller_v2 = 0
end
end
if (auxiliaryData[1]==99) then
Roller_v3 = Roller_v3 - dVel*20
if (Roller_v3 > 0) then
Roller_v3 = 0
end
end
if (auxiliaryData[1]==118) then
Roller_v4 = Roller_v4 - dVel*20
if (Roller_v4 > 0) then
Roller_v4 = 0
end
end
if (auxiliaryData[1]==2008) then
Roller_v = Roller_v + dVel*20
if (Roller_v < 0) then
Roller_v = 0
end
end
if (auxiliaryData[1]==2008) then
Roller_v2 = Roller_v2 + dVel*20
if (Roller_v2 < 0) then
Roller_v2 = 0
end
end
if (auxiliaryData[1]==2008) then
Roller_v3 = Roller_v3 + dVel*20
if (Roller_v3 < 0) then
Roller_v3 = 0
end
end
if (auxiliaryData[1]==2008) then
Roller_v4 = Roller_v4 + dVel*20
if (Roller_v4 < 0) then
Roller_v4 = 0
end
end
if (auxiliaryData[1]==2009) then
Slide_rail_v = Slide_rail_v + dVel/15
if (Slide_rail_v < 0) then
Slide_rail_v = 0
end
end
if (auxiliaryData[1]==2010) then
Slide_rail_v = Slide_rail_v - dVel/15
if (Slide_rail_v > 0) then
Slide_rail_v = 0
end
end
end
message,auxiliaryData=sim.getSimulatorMessage()
end
Slide_rail_v2 = Slide_rail_v/1.1
Slide_rail_v3 = Slide_rail_v/1.2
Slide_rail_v4 = Slide_rail_v/1.3
sim.setJointTargetVelocity(Slide_rail,Slide_rail_v)
sim.setJointTargetVelocity(Roller,Roller_v)
sim.setJointTargetVelocity(Slide_rail2,Slide_rail_v2)
sim.setJointTargetVelocity(Roller2,Roller_v2)
sim.setJointTargetVelocity(Slide_rail3,Slide_rail_v3)
sim.setJointTargetVelocity(Roller3,Roller_v4)
sim.setJointTargetVelocity(Slide_rail4,Slide_rail_v4)
sim.setJointTargetVelocity(Roller4,Roller_v3)
end
FTB_Version(3):新增玩家的人形回位code、染色、反向操作 (Hard version)
.gif)
以下程式加到function sysCall_actuation()中
A= sim.getObjectHandle('RS1_PO1')
PA= sim.getObjectPosition(A,-1)
if PA[1] >= -0.712 then
Roller_v = Roller_v + dVel*3
end
B= sim.getObjectHandle('RS2_PO1')
PB= sim.getObjectPosition(B,-1)
if PB[1] >= -0.531 then
Roller_v2 = Roller_v2 + dVel*3
end
C= sim.getObjectHandle('RS4_PO2')
PC= sim.getObjectPosition(C,-1)
if PC[1] >= -0.197 then
Roller_v3=Roller_v3 + dVel*5
end
D= sim.getObjectHandle('RS3_PO1')
PD= sim.getObjectPosition(D,-1)
if PD[1] >= 0.137 then
Roller_v4=Roller_v4 + dVel*5
end
FTB_Version(4):注意!code中第28行擷取的物件名稱為('LL3')而非壓縮檔中的('LR3')、加入電腦回擊code{守門員}及第二桿件追蹤半設定、改變玩家桿件旋轉的踢球速度
.gif)
以下程式為新增的code
function sysCall_init()
--computer--
KBV = 10
F = (math.pi/180)*KBV
G = -(math.pi/180)*KBV
Ball=sim.getObjectHandle('ball')
Body=sim.getObjectHandle('LSO1')
Body2=sim.getObjectHandle('LSO2')
-- test=sim.getObjectHandle('LS2_P2')
LR1=sim.getObjectHandle('LR1')
LR2=sim.getObjectHandle('LR2')
LR3=sim.getObjectHandle('LL3')
LR4=sim.getObjectHandle('LR4')
L1=sim.getObjectHandle('L1')
L2=sim.getObjectHandle('L2')
L3=sim.getObjectHandle('L3')
L4=sim.getObjectHandle('L4')
end
function sysCall_actuation()
--computer--
Body_s = sim.getObjectPosition(Body,-1)
Ball_s = sim.getObjectPosition(Ball,-1)
X = Body_s[1] - Ball_s[1]
Y = Body_s[2] - Ball_s[2]
if 1 then
if X <= 0.02 and Y <= 0 then
sim.setJointTargetVelocity(LR1,G)
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 and Y <= 0 then
sim.setJointTargetVelocity(LR1,G)
sim.setJointTargetVelocity(LR1,2)
elseif X <= 0.02 and Y > 0 then
sim.setJointTargetVelocity(LR1,F)
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 and Y > 0 then
sim.setJointTargetVelocity(LR1,F)
sim.setJointTargetVelocity(LR1,2)
end
YYYYY = Y*7
sim.setJointTargetVelocity(L1,YYYYY)
end
--test--
Body_s2 = sim.getObjectPosition(Body2,-1)
-- test_s = sim.getObjectPosition(test,-1)
X2_1 = Body_s2[1] - Ball_s[1]
Y2_1 = Body_s2[2] - Ball_s[2] -0.15
Y2_2 = Body_s2[2] - Ball_s[2] +0.15
--M = test_s[2]- Ball_s[2]
print(X2_1)
if X2_1 > 0.02 then
Y2_1 = Y2_1*5
sim.setJointTargetVelocity(L2,Y2_1)
Y2_2 = Y2_2*5
sim.setJointTargetVelocity(L2,Y2_2)
end
end
FTB_Version(5):將反向操作改回同向操作,新增電腦二、三桿件回擊與位置判斷,此版本存在些許BUG測試請注意、稍縮短電腦擊球判斷式
.gif)
以下程式為新增的code
function sysCall_init()
--computer--
KBV = 10
F = (math.pi/180)*KBV
G = -(math.pi/180)*KBV
Ball=sim.getObjectHandle('ball')
Body=sim.getObjectHandle('LSO1')
Body2=sim.getObjectHandle('LSO2')
Body3=sim.getObjectHandle('LSO3')
Body4=sim.getObjectHandle('LSO4')
-- test=sim.getObjectHandle('LS2_P2')
LR1=sim.getObjectHandle('LR1')
LR2=sim.getObjectHandle('LR2')
LR3=sim.getObjectHandle('LL3')
LR4=sim.getObjectHandle('LR4')
L1=sim.getObjectHandle('L1')
L2=sim.getObjectHandle('L2')
L3=sim.getObjectHandle('L3')
L4=sim.getObjectHandle('L4')
end
function sysCall_actuation()
--computer--
Body_s = sim.getObjectPosition(Body,-1)
Ball_s = sim.getObjectPosition(Ball,-1)
X = Body_s[1] - Ball_s[1]
Y = Body_s[2] - Ball_s[2]
if 1 then
if X <= 0.02 and Y <= 0 then
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 and Y <= 0 then
sim.setJointTargetVelocity(LR1,2)
elseif X <= 0.02 and Y > 0 then
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 and Y > 0 then
sim.setJointTargetVelocity(LR1,2)
end
YYYYY = Y*7
sim.setJointTargetVelocity(L1,YYYYY)
end
--test--
Body_s2 = sim.getObjectPosition(Body2,-1)
--test_s = sim.getObjectPosition(test,-1)
X2_1 = Body_s2[1] - Ball_s[1]
Y2_1 = Body_s2[2] - Ball_s[2] - 0.15
Y2_2 = Body_s2[2] - Ball_s[2] + 0.15
--M = test_s[2]- Ball_s[2]
--print(X2_1)
if X2_1 >= 0.02 then
if Ball_s[2] <= -0.133 then
if X2_1 < 0.03 then
sim.setJointTargetVelocity(LR2,-5)
elseif X2_1 > 0.03 then
sim.setJointTargetVelocity(LR2,5)
end
Y2_1 = Y2_1*5
sim.setJointTargetVelocity(L2,Y2_1)
elseif Ball_s[2] > -0.133 then
if X2_1 < 0.03 then
sim.setJointTargetVelocity(LR2,-5)
elseif X2_1 > 0.03 then
sim.setJointTargetVelocity(LR2,5)
end
Y2_2 = Y2_2*5
sim.setJointTargetVelocity(L2,Y2_2)
end
end
Body_s4 = sim.getObjectPosition(Body4,-1)
X4_1 = Body_s4[1] - Ball_s[1]
Y4_1 = Body_s4[2] - Ball_s[2] - 0.15
Y4_2 = Body_s4[2] - Ball_s[2] + 0.15
if X4_1 >= 0.02 then
if Ball_s[2] <= -0.133 then
if X4_1 < 0.03 then
sim.setJointTargetVelocity(LR4,-5)
elseif X4_1 > 0.03 then
sim.setJointTargetVelocity(LR4,5)
end
Y4_1 = Y4_1*3
sim.setJointTargetVelocity(L4,Y4_1)
elseif Ball_s[2] > -0.133 then
if X4_1 < 0.03 then
sim.setJointTargetVelocity(LR4,-5)
elseif X4_1 > 0.03 then
sim.setJointTargetVelocity(LR4,5)
end
Y4_2 = Y4_2*3
sim.setJointTargetVelocity(L4,Y4_2)
end
end
end
FTB_Version(6):開始意識到最近版本中已加入球的彈性係數(對平面顯示較明顯)、電腦回擊系統'最初'完整版定型、縮短code及判斷式、將電腦回擊函式外移、加入上視圖攝影視角
.gif)
以下都更改於function sysCall_actuation()中
-------------------------------------
if (auxiliaryData[1]==2008) then
Roller_v = Roller_v + dVel*20
Roller_v2 = Roller_v2 + dVel*20
Roller_v3 = Roller_v3 + dVel*20
Roller_v4 = Roller_v4 + dVel*20
if (Roller_v < 0) then
Roller_v = 0
end
if (Roller_v2 < 0) then
Roller_v2 = 0
end
if (Roller_v3 < 0) then
Roller_v3 = 0
end
if (Roller_v4 < 0) then
Roller_v4 = 0
end
end
-----------------------------------------------
--computer--
Body_s = sim.getObjectPosition(Body,-1)
Ball_s = sim.getObjectPosition(Ball,-1)
X = Body_s[1] - Ball_s[1]
Y = Body_s[2] - Ball_s[2]
if 1 then
if X <= 0.02 and Y <= 0 then
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 and Y <= 0 then
sim.setJointTargetVelocity(LR1,2)
elseif X <= 0.02 and Y > 0 then
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 and Y > 0 then
sim.setJointTargetVelocity(LR1,2)
end
YYYYY = Y*7
sim.setJointTargetVelocity(L1,YYYYY)
end
Body_s2 = sim.getObjectPosition(Body2,-1)
X2_1 = Body_s2[1] - Ball_s[1]
Y2_1 = Body_s2[2] - Ball_s[2] - 0.15
Y2_2 = Body_s2[2] - Ball_s[2] + 0.15
if X2_1 >= 0.02 then
if Ball_s[2] <= -0.133 then
C_K_B_X2()
Y2_1 = Y2_1*5
sim.setJointTargetVelocity(L2,Y2_1)
elseif Ball_s[2] > -0.133 then
C_K_B_X2()
Y2_2 = Y2_2*5
sim.setJointTargetVelocity(L2,Y2_2)
end
end
Body_s4 = sim.getObjectPosition(Body4,-1)
X4_1 = Body_s4[1] - Ball_s[1]
Y4_1 = Body_s4[2] - Ball_s[2] - 0.15
Y4_2 = Body_s4[2] - Ball_s[2] + 0.15
if X4_1 >= 0.02 then
if Ball_s[2] <= -0.133 then
C_K_B_X4()
Y4_1 = Y4_1*3
sim.setJointTargetVelocity(L4,Y4_1)
elseif Ball_s[2] > -0.133 then
C_K_B_X4()
Y4_2 = Y4_2*3
sim.setJointTargetVelocity(L4,Y4_2)
end
end
--[[
test_s = sim.getObjectPosition(test,-1)
M = test_s[2]- Ball_s[2]
print(M)
--]]
Body_s3 = sim.getObjectPosition(Body3,-1)
X3_1 = Body_s3[1] - Ball_s[1]
Y3_1 = Body_s3[2] - Ball_s[2]
Y3_2 = Body_s3[2] - Ball_s[2] +0.2487
Y3_3 = Body_s3[2] - Ball_s[2] -0.2487
if X3_1 >= 0.02 then
if Ball_s[2] < -0.0028 and Ball_s[2] >= -0.2487 then
C_K_B_X3()
Y3_1 = Y3_1*1.5
sim.setJointTargetVelocity(L3,Y3_1)
elseif Ball_s[2] >= -0.0028 then
C_K_B_X3()
Y3_2 = Y3_2*1.5
sim.setJointTargetVelocity(L3,Y3_2)
elseif Ball_s[2] < -0.2487 then
C_K_B_X3()
Y3_3 = Y3_3*1.5
sim.setJointTargetVelocity(L3,Y3_3)
end
end
end
function C_K_B_X2()
if X2_1 < 0.03 then
sim.setJointTargetVelocity(LR2,-5)
elseif X2_1 > 0.03 then
sim.setJointTargetVelocity(LR2,5)
end
end
function C_K_B_X3()
if X3_1 < 0.03 then
sim.setJointTargetVelocity(LR3,-5)
elseif X3_1 > 0.03 then
sim.setJointTargetVelocity(LR3,5)
end
end
function C_K_B_X4()
if X4_1 < 0.03 then
sim.setJointTargetVelocity(LR4,-5)
elseif X4_1 > 0.03 then
sim.setJointTargetVelocity(LR4,5)
end
end
FTB_Version(7):於code加入部分註解、縮短電腦擊球判斷式、加入回球判斷式
.gif)
if 1 then --C_goalkeeper
if X <= 0.02 then
sim.setJointTargetVelocity(LR1,-5)
elseif X > 0.02 then
sim.setJointTargetVelocity(LR1,5)
end
end
----------------
if Ball_s[1] < -0.85 or Ball_s[1] >= 0.61 then
sim.setObjectPosition(Ball,-1,{-0.1429, -0.1334, 0.5})
end
FTB_Version(8):加入計分判斷式、更改回球判斷式
.gif)
--reborn_ball & count goal--
if Ball_s[1] < -0.85 then
Player_G = Player_G + 1
end
if Ball_s[1] >= 0.61 then
Computer_G = Computer_G+1
end
if Ball_s[1] < -0.85 or Ball_s[1] >= 0.61 then
sim.setObjectPosition(Ball,-1,{-0.1429, -0.1334, 0.5})
print[[Player:Computer]]
print(' '..Computer_G..' '..Player_G)
end
end
FTB_Version(9):小改輸入參數及刪除多餘code
FTB_Version(10):暫時更改場地設計、小改輸入參數
.gif)
FTB_Version(11):小改輸入參數、更改編寫方法
--reborn_ball & count goal--
if Ball_s[1] < -0.85 then
Player_G = Player_G + 1
sim.setObjectPosition(Ball,-1,{-0.13, -0.1334, 0.5})
end
if Ball_s[1] >= 0.61 then
Computer_G = Computer_G + 1
sim.setObjectPosition(Ball,-1,{-0.15, -0.1334, 0.5})
end
if Ball_s[1] < -0.85 or Ball_s[1] >= 0.61 then
print[[Player : Computer]]
print(' '..Computer_G..' '..Player_G)
end
end
function C_K_B_X2() --C_second_kick--
if X2_1 < 0.06 then
sim.setJointTargetVelocity(LR2,-5)
elseif X2_1 > 0.03 then
sim.setJointTargetVelocity(LR2,5)
end
end
function C_K_B_X3() --C_third_kcik--
if X3_1 < 0.06 then
sim.setJointTargetVelocity(LR3,-5)
elseif X3_1 > 0.03 then
sim.setJointTargetVelocity(LR3,5)
end
end
function C_K_B_X4() --C_fourth_kick--
if X4_1 < 0.06 then
sim.setJointTargetVelocity(LR4,-5)
elseif X4_1 > 0.03 then
sim.setJointTargetVelocity(LR4,5)
end
end
FTB_Version(12):更改桿件作動關係與桿件外觀、更改回位按鍵{R鍵}、參數修正
FTB_Version(13):加入導球機構以及他的作動code(測試中)
.gif)
function reborn_ball_count_goal()
if Ball_s[1] < -0.85 and Ball_s[3] > 0.12507 then
Player_G = Player_G + 1
-- sim.setObjectPosition(Ball,-1,{-0.13, -0.1334, 0.5})
end
if Ball_s[1] >= 0.61 and Ball_s[3] > 0.1251 then
Computer_G = Computer_G + 1
-- sim.setObjectPosition(Ball,-1,{-0.15, -0.1334, 0.5})
end
if Ball_s[3] > 0.1251 then
if Ball_s[1] < -0.85 or Ball_s[1] >= 0.61 then
print[[Player : Computer]]
print(' '..Computer_G..' '..Player_G)
end
end
print(Ball_s)
if Ball_s[1] > 0.905 and Ball_s[2] < -0.069 and Ball_s[3] < 0.036 then
sim.setJointTargetVelocity(Push_1,1)
end
if Ball_s[1] < -1.15 and Ball_s[2] < -0.123 and Ball_s[3] < 0.036 then
sim.setJointTargetVelocity(Push_2,-1)
end
if Ball_s[3] > 0.036 then
sim.setJointTargetVelocity(Push_1,-1)
sim.setJointTargetVelocity(Push_2,1)
end
FTB_Version(14):更改導球機構code、加入'類'回球code、更改場地顏色、小改參數、設定桿件與球與軌道的關係設定!!、導球機構新增上蓋、計分參數bug...
.gif)
function reborn_ball_count_goal()
if Ball_s[1] < -0.85 and Ball_s[3] > 0.12507 then
Player_G = Player_G + 1
-- sim.setObjectPosition(Ball,-1,{-0.13, -0.1334, 0.5})
end
if Ball_s[1] >= 0.61 and Ball_s[3] > 0.1251 then
Computer_G = Computer_G + 1
-- sim.setObjectPosition(Ball,-1,{-0.15, -0.1334, 0.5})
end
if Ball_s[3] > 0.1251 then
if Ball_s[1] < -0.85 or Ball_s[1] >= 0.61 then
print[[Player : Computer]]
print(' '..Computer_G..' '..Player_G)
end
end
if Ball_s[1] > 0.905 and Ball_s[2] < -0.069 and Ball_s[3] < 0.036 then
sim.setJointTargetVelocity(Push_1,1)
end
if Ball_s[1] < -1.15 and Ball_s[2] < -0.123 and Ball_s[3] < 0.036 then
sim.setJointTargetVelocity(Push_2,-1)
end
if Ball_s[3] > 0.036 then
sim.setJointTargetVelocity(Push_1,-1)
sim.setJointTargetVelocity(Push_2,1)
end
if Ball_s[1] < -1.156 and Ball_s[2] > 0.163 and Ball_s[3] > 0.058 then
sim.setObjectPosition(Ball,-1,{-0.20361, 0.2739, 0.15735})
end
if Ball_s[1] < -0.20361 and Ball_s[2] > 0.2740 and Ball_s[3] > 0.15735 then
sim.setObjectPosition(Ball,-1,{-0.2049, 0.23, 0.1482})
end
if Ball_s[1] > 0.9056 and Ball_s[2] < -0.4247 and Ball_s[3] > 0.0592 then
sim.setObjectPosition(Ball,-1,{-0.043425, -0.60401, 0.15735})
end
if Ball_s[1] > -0.04753 and Ball_s[2] < -0.5240 and Ball_s[3] > 0.15735 then
sim.setObjectPosition(Ball,-1,{-0.03667, -0.48443, 0.1482})
end
FTB_Version_Final:修改計分code、刪除大多的測試code
.gif)
function reborn_ball_count_goal()
if Ball_s[1] < -0.85 and Ball_s[1] > -0.87 then
Player_G = Player_G + 1
end
if Ball_s[1] > 0.61 and Ball_s[1] < 0.62 then
Computer_G = Computer_G + 1
end
if Ball_s[1] < -0.85 or Ball_s[1] > 0.61 then
print[[Player : Computer]]
print(' '..Computer_G..' '..Player_G)
end
FTB_Version_Final_EX:較EX=>extra,原本沒有要做的部分,不過只是改改參數正負號還蠻簡單的,屬於電腦打電腦,bug很多。
.gif)
function sysCall_init()
Ball=sim.getObjectHandle('ball')
--computer--
Body=sim.getObjectHandle('LSO1')
Body2=sim.getObjectHandle('LSO2')
Body3=sim.getObjectHandle('LSO3')
Body4=sim.getObjectHandle('LSO4')
LR1=sim.getObjectHandle('LR1')
LR2=sim.getObjectHandle('LR2')
LR3=sim.getObjectHandle('LL3')
LR4=sim.getObjectHandle('LR4')
L1=sim.getObjectHandle('L1')
L2=sim.getObjectHandle('L2')
L3=sim.getObjectHandle('L3')
L4=sim.getObjectHandle('L4')
--computer2--
Body_2=sim.getObjectHandle('RSO1')
Body2_2=sim.getObjectHandle('RSO2')
Body3_2=sim.getObjectHandle('RSO3')
Body4_2=sim.getObjectHandle('RSO4')
RR1=sim.getObjectHandle('RR1')
RR2=sim.getObjectHandle('RR2')
RR3=sim.getObjectHandle('RR3')
RR4=sim.getObjectHandle('RR4')
R1=sim.getObjectHandle('R1')
R2=sim.getObjectHandle('R2')
R3=sim.getObjectHandle('R3')
R4=sim.getObjectHandle('R4')
--goal--
Player_G = 0
Computer_G = 0
--reball--
Push_1=sim.getObjectHandle('Push_1')
Push_2=sim.getObjectHandle('Push_2')
end
function sysCall_actuation()
message,auxiliaryData=sim.getSimulatorMessage()
while message~=-1 do
if (message==sim.message_keypress) then
if (auxiliaryData[1]==114) then --"r"--restart
sim.setObjectPosition(Ball,-1,{-0.15, -0.1334, 0.5})
end
end
message,auxiliaryData=sim.getSimulatorMessage()
end
--computer--
Body_s = sim.getObjectPosition(Body,-1)
Ball_s = sim.getObjectPosition(Ball,-1)
X = Body_s[1] - Ball_s[1]
Y = Body_s[2] - Ball_s[2]
if 1 then --C_goalkeeper
if X <= 0.02 then
sim.setJointTargetVelocity(LR1,-5)
sim.setJointTargetVelocity(L1,0)
elseif X > 0.02 or X <= 0.01 then
sim.setJointTargetVelocity(LR1,5)
YYYYY = Y*7
sim.setJointTargetVelocity(L1,YYYYY)
end
end
Body_s2 = sim.getObjectPosition(Body2,-1)
X2_1 = Body_s2[1] - Ball_s[1]
Y2_1 = Body_s2[2] - Ball_s[2] - 0.15
Y2_2 = Body_s2[2] - Ball_s[2] + 0.15
if X2_1 >= 0.01 then --C_second--
if Ball_s[2] <= -0.133 then
C_K_B_X2()
Y2_1 = Y2_1*5
sim.setJointTargetVelocity(L2,Y2_1)
elseif Ball_s[2] > -0.133 then
C_K_B_X2()
Y2_2 = Y2_2*5
sim.setJointTargetVelocity(L2,Y2_2)
end
end
Body_s4 = sim.getObjectPosition(Body4,-1)
X4_1 = Body_s4[1] - Ball_s[1]
Y4_1 = Body_s4[2] - Ball_s[2] - 0.15
Y4_2 = Body_s4[2] - Ball_s[2] + 0.15
if X4_1 >= 0.01 then --C_third--
if Ball_s[2] <= -0.133 then
C_K_B_X4()
Y4_1 = Y4_1*3
sim.setJointTargetVelocity(L4,Y4_1)
elseif Ball_s[2] > -0.133 then
C_K_B_X4()
Y4_2 = Y4_2*3
sim.setJointTargetVelocity(L4,Y4_2)
end
end
Body_s3 = sim.getObjectPosition(Body3,-1)
X3_1 = Body_s3[1] - Ball_s[1]
Y3_1 = Body_s3[2] - Ball_s[2]
Y3_2 = Body_s3[2] - Ball_s[2] +0.2487
Y3_3 = Body_s3[2] - Ball_s[2] -0.2487
if X3_1 >= 0.01 then --C_fourth--
if Ball_s[2] < -0.0028 and Ball_s[2] >= -0.2487 then
C_K_B_X3()
Y3_1 = Y3_1*2.5
sim.setJointTargetVelocity(L3,Y3_1)
elseif Ball_s[2] >= -0.0028 then
C_K_B_X3()
Y3_2 = Y3_2*2.5
sim.setJointTargetVelocity(L3,Y3_2)
elseif Ball_s[2] < -0.2487 then
C_K_B_X3()
Y3_3 = Y3_3*2.5
sim.setJointTargetVelocity(L3,Y3_3)
end
end
--computer2--
Body_2_s = sim.getObjectPosition(Body_2,-1)
X_2 = Body_2_s[1] - Ball_s[1]
Y_2 = Body_2_s[2] - Ball_s[2]
if 1 then --C_goalkeeper
if X_2 > -0.02 then
sim.setJointTargetVelocity(RR1,-5)
sim.setJointTargetVelocity(R1,0)
Y_2 = 0
elseif X_2 < -0.02 or X_2 > -0.01 then
sim.setJointTargetVelocity(RR1,5)
YYYYY_2 = Y_2*-7
sim.setJointTargetVelocity(R1,YYYYY_2)
end
end
Body_2_s2 = sim.getObjectPosition(Body2_2,-1)
X2_1_2 = Body_2_s2[1] - Ball_s[1]
Y2_1_2 = Body_2_s2[2] - Ball_s[2] - 0.15
Y2_2_2 = Body_2_s2[2] - Ball_s[2] + 0.15
if X2_1_2 < -0.01 then --C_second--
if Ball_s[2] <= -0.133 then
C_K_B_X2_2()
Y2_1_2 = Y2_1_2*-5
sim.setJointTargetVelocity(R2,Y2_1_2)
elseif Ball_s[2] > -0.133 then
C_K_B_X2_2()
Y2_2_2 = Y2_2_2*-5
sim.setJointTargetVelocity(R2,Y2_2_2)
end
end
Body_2_s4 = sim.getObjectPosition(Body4_2,-1)
X4_1_2 = Body_2_s4[1] - Ball_s[1]
Y4_1_2 = Body_2_s4[2] - Ball_s[2] - 0.15
Y4_2_2 = Body_2_s4[2] - Ball_s[2] + 0.15
if X4_1_2 < -0.01 then --C_third--
if Ball_s[2] <= -0.133 then
C_K_B_X4_2()
Y4_1_2 = Y4_1_2*-3
sim.setJointTargetVelocity(R4,Y4_1_2)
elseif Ball_s[2] > -0.133 then
C_K_B_X4_2()
Y4_2_2 = Y4_2_2*-3
sim.setJointTargetVelocity(R4,Y4_2_2)
end
end
Body_2_s3 = sim.getObjectPosition(Body3_2,-1)
X3_1_2 = Body_2_s3[1] - Ball_s[1]
Y3_1_2 = Body_2_s3[2] - Ball_s[2]
Y3_2_2 = Body_2_s3[2] - Ball_s[2] +0.2487
Y3_3_2 = Body_2_s3[2] - Ball_s[2] -0.2487
if X3_1_2 < 0.01 then --C_fourth--
if Ball_s[2] < -0.0028 and Ball_s[2] >= -0.2487 then
C_K_B_X3_2()
Y3_1_2 = Y3_1_2*-2.5
sim.setJointTargetVelocity(R3,Y3_1_2)
elseif Ball_s[2] >= -0.0028 then
C_K_B_X3_2()
Y3_2_2 = Y3_2_2*-2.5
sim.setJointTargetVelocity(R3,Y3_2_2)
elseif Ball_s[2] < -0.2487 then
C_K_B_X3_2()
Y3_3_2 = Y3_3_2*-2.5
sim.setJointTargetVelocity(R3,Y3_3_2)
end
end
--reborn_ball & count goal--
reborn_ball_count_goal()
end
function C_K_B_X2() --C_second_kick--
if X2_1 < 0.06 then
sim.setJointTargetVelocity(LR2,-5)
elseif X2_1 > 0.03 then
sim.setJointTargetVelocity(LR2,5)
end
end
function C_K_B_X3() --C_third_kcik--
if X3_1 < 0.06 then
sim.setJointTargetVelocity(LR3,-5)
elseif X3_1 > 0.03 then
sim.setJointTargetVelocity(LR3,5)
end
end
function C_K_B_X4() --C_fourth_kick--
if X4_1 < 0.06 then
sim.setJointTargetVelocity(LR4,-5)
elseif X4_1 > 0.03 then
sim.setJointTargetVelocity(LR4,5)
end
end
function C_K_B_X2_2() --C_2_second_kick--
if X2_1_2 < -0.03 then
sim.setJointTargetVelocity(RR2,5)
elseif X2_1_2 > -0.03 then
sim.setJointTargetVelocity(RR2,-5)
end
end
function C_K_B_X3_2() --C_2_third_kcik--
if X3_1_2 < -0.03 then
sim.setJointTargetVelocity(RR3,5)
elseif X3_1_2 > -0.03 then
sim.setJointTargetVelocity(RR3,-5)
end
end
function C_K_B_X4_2() --C_2_fourth_kick--
if X4_1_2 < -0.03 then
sim.setJointTargetVelocity(RR4,5)
elseif X4_1_2 > -0.03 then
sim.setJointTargetVelocity(RR4,-5)
end
end
function reborn_ball_count_goal()
if Ball_s[1] < -0.85 and Ball_s[1] > -0.87 then
Player_G = Player_G + 1
end
if Ball_s[1] >= 0.61 and Ball_s[1] < 0.63 then
Computer_G = Computer_G + 1
end
if Ball_s[1] < -0.85 or Ball_s[1] >= 0.61 then
print[[Player : Computer]]
print(' '..Computer_G..' '..Player_G)
end
if Ball_s[1] > 0.905 and Ball_s[2] < -0.069 and Ball_s[3] < 0.036 then
sim.setJointTargetVelocity(Push_1,1)
elseif Ball_s[3] > 0.036 then
sim.setJointTargetVelocity(Push_1,-1)
end
if Ball_s[1] < -1.15 and Ball_s[2] < -0.123 and Ball_s[3] < 0.036 then
sim.setJointTargetVelocity(Push_2,-1)
elseif Ball_s[3] > 0.036 then
sim.setJointTargetVelocity(Push_2,1)
end
if Ball_s[1] < -1.156 and Ball_s[2] > 0.163 and Ball_s[3] > 0.058 then
sim.setObjectPosition(Ball,-1,{-0.20361, 0.2739, 0.15735})
end
if Ball_s[1] < -0.20361 and Ball_s[2] > 0.2740 and Ball_s[3] > 0.15735 then
sim.setObjectPosition(Ball,-1,{-0.2049, 0.23, 0.1482})
end
if Ball_s[1] > 0.9056 and Ball_s[2] < -0.4247 and Ball_s[3] > 0.0592 then
sim.setObjectPosition(Ball,-1,{-0.043425, -0.60401, 0.15735})
end
if Ball_s[1] > -0.04753 and Ball_s[2] < -0.5240 and Ball_s[3] > 0.15735 then
sim.setObjectPosition(Ball,-1,{-0.03667, -0.48443, 0.1482})
end
end
影片皆屬於後面幾個版本的,其餘影片於15周心得中
結論:很累...
會決定用Vrep內設的Lua編寫是因為他的運行速度較快以及編譯叫好懂,雖然有運算的上限。最一開始是從玩家的上下左右開始編寫,之後參考28號同學的電腦回擊寫法後也寫了一個類似的Lua版本但之後發現還可以再修短,之後慢慢地就把全部的code都寫好了,即使到現在計分的判斷還是會有bug原本是用範圍判定之後改成小範圍判定這樣就精準但還是會有多算的時候。
之後是最重要且最需要解釋的:我們的回球機構一開始就有問題所以才會寫一個過球門救回R點的code版本後來加入機構後嘗試寫個正常的版本,但距離太遠+斜度太過+球含有很0.75的彈性係數,這導致球根本上不去或是飛出軌道...我想到的解決方法是加上蓋子以及在球於軌道中時寫個判斷式讓球傳送到離洞口較近的下坡,想不到球一開始就過不了洞,之後又寫了個讓球能滾出去的code,這是偷吃步的方法也是利用程式輔助機構的方法,雖然很濺但確實可行。