week7測試物件
測試用Vrep呼叫方向鍵的指令(內建程式推不上去改用截圖放)
------------------------------------------------------------------------------------------------------------
測試方向鍵於手足球的人偶自由度&code設定 :
RJ1 : 為人偶前後踢球的軸代稱 \ RJ2 : 為控制人偶左右的桿子的軸代稱
樹狀圖為gif中所表示
下方為Lua code --->用於Vrep3.6.1版本中
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
59
60
61
62
63
64
| function sysCall_init() right_left_handle= sim.getObjectHandle( 'RJ1' ) up_down_handle= sim.getObjectHandle( 'RJ2' ) MaxVel=5 right_left_velocity=0 up_down_velocity=0 dVel=0.5; sim.setJointTargetVelocity(right_left_handle,right_left_velocity) sim.setJointTargetVelocity(up_down_handle,up_down_velocity) end function sysCall_actuation() message,auxiliaryData=sim.getSimulatorMessage() while message~=-1 do if (message==sim.message_keypress) then if (auxiliaryData[1]==32) then -- right key right_left_velocity=0 up_down_velocity=0 sim.setJointForce(right_left_handle, 0) sim.setJointForce(up_down_handle, 0) break else sim.setJointForce(right_left_handle, 10000) sim.setJointForce(up_down_handle, 10000) end if (auxiliaryData[1]==2007) then -- left key right_left_velocity=right_left_velocity+dVel*1.3 end if (auxiliaryData[1]==2008) then -- right key right_left_velocity=right_left_velocity-dVel*1.3 end if (auxiliaryData[1]==2009) then -- up key up_down_velocity=up_down_velocity+dVel/10 end if (auxiliaryData[1]==2010) then -- down key up_down_velocity=up_down_velocity-dVel/10 end end message,auxiliaryData=sim.getSimulatorMessage() end if right_left_velocity>MaxVel then right_left_velocity=-5 end if right_left_velocity<-MaxVel then right_left_velocity=5 end if up_down_velocity>MaxVel then up_down_velocity=0 end if up_down_velocity<-MaxVel then up_down_velocity=0 end sim.setJointTargetVelocity(right_left_handle,right_left_velocity) sim.setJointTargetVelocity(up_down_handle,up_down_velocity) end |
沒有留言:
張貼留言
請輸入...