Python to lua & 電腦對打
改寫code=python to lua並簡化優點:
python : 可執行運算值較大的編譯
lua : Vrep內部沿用 , 延遲現象較少
缺點:
python : 會有爆ping問題導致延遲
lua : 太多運算時直接停止
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| function sysCall_init() KickBallV = 10 R_KickBallVel = ( math.pi /180)*KickBallV B_KickBallVel = -( math.pi /180)*KickBallV Sphere_handle=sim.getObjectHandle( 'Sphere' ) BRod_handle=sim.getObjectHandle( 'BRod' ) BRev_handle=sim.getObjectHandle( 'BRev' ) BMo_handle=sim.getObjectHandle( 'BMo' ) -- RRod_handle=sim.getObjectHandle( 'RRod' ) RRev_handle=sim.getObjectHandle( 'RRev' ) RMo_handle=sim.getObjectHandle( 'RMo' ) end function sysCall_actuation() position_BR=sim.getObjectPosition(BRod_handle,-1) position_S=sim.getObjectPosition(Sphere_handle,-1) X =position_S[1] - position_BR[1] Y =position_S[2] - position_BR[2] if 1 then if X <= 0.02 and Y <= 0 then sim.setJointTargetVelocity(BRev_handle,B_KickBallVel) sim.setJointTargetVelocity(BRev_handle,-1) elseif X > 0.02 and Y <= 0 then sim.setJointTargetVelocity(BRev_handle,B_KickBallVel) sim.setJointTargetVelocity(BRev_handle,1) elseif X <= 0.02 and Y > 0 then sim.setJointTargetVelocity(BRev_handle,R_KickBallVel) sim.setJointTargetVelocity(BRev_handle,-1) elseif X > 0.02 and Y > 0 then sim.setJointTargetVelocity(BRev_handle,R_KickBallVel) sim.setJointTargetVelocity(BRev_handle,1) end YYYYY = Y*5 sim.setJointTargetVelocity(BMo_handle,YYYYY) end --- position_RR=sim.getObjectPosition(RRod_handle,-1) X =position_S[1] - position_RR[1] Y =position_S[2] - position_RR[2] if 1 then if X <= 0.02 and Y <= 0 then sim.setJointTargetVelocity(RRev_handle,B_KickBallVel) sim.setJointTargetVelocity(RRev_handle,-1) elseif X > 0.02 and Y <= 0 then sim.setJointTargetVelocity(RRev_handle,B_KickBallVel) sim.setJointTargetVelocity(RRev_handle,1) elseif X <= 0.02 and Y > 0 then sim.setJointTargetVelocity(RRev_handle,R_KickBallVel) sim.setJointTargetVelocity(RRev_handle,-1) elseif X > 0.02 and Y > 0 then sim.setJointTargetVelocity(RRev_handle,R_KickBallVel) sim.setJointTargetVelocity(RRev_handle,1) end YYYYY = Y*5 sim.setJointTargetVelocity(RMo_handle,YYYYY) end end --by 40623130-- |
原本要編寫切換鍵但於vrep中用io.clock等時間等待輸入雙命令時會出現運算值過大導致停止問題 , 所以先寫電腦打擊與跟蹤球
原python code出處(by 40623128):https://mdekmol.github.io/cd2019a-task1-2019cda_t1_g3_1/content/%E6%89%8B%E8%B6%B3%E7%90%83%E6%89%8B%E6%8E%A7%E8%88%87%E9%9B%BB%E8%85%A6%E5%B0%8D%E6%89%93.html
沒有留言:
張貼留言
請輸入...