stage2 <<
Previous Next >> W6
W5
Stage2 開始執行,討論後決定以第一組的專題主題繼續進行下去。
組別 : stage2-ag1
組員 : 40823145、40823108、40823112、40823109
為了讓模型能夠按照我們的意思做動,嘗試著編寫Lua程式並以方向鍵進行控制。
下方為第一次測試的程式
Lua程式:
threadFunction=function()
-- put your actuation code here
while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
-- Read the keyboard messages (make sure the focus is on the main window, scene view):
message,auxiliaryData=sim.getSimulatorMessage()
while message~=-1 do
if (message==sim.message_keypress) then
if (auxiliaryData[1]==2007) then
-- up key
velocity=1000
torque=10000
Shape4 = 1000
Shape7 = 1000
end
if (auxiliaryData[1]==2008) then
-- down key
velocity=1000
torque=10000
Shape4 = 1000
Shape7 = 1000
end
if (auxiliaryData[1]==2009) then
-- left key
velocity=1000
torque=10000
Shape4 = 1000
Shape7 = 1000
end
if (auxiliaryData[1]==2010) then
-- right key
velocity=1000
torque=10000
Shape4 = 1000
Shape7 = 1000
end
end
message,auxiliaryData=sim.getSimulatorMessage()
end
if Shape4 == 1
then sim.setJointPosition(joint_1, 1000, orientation)
if Shape7 == 1
then sim.setJointPosition(joint_2, 1000, orientation)
end
sim.setJointTargetVelocity(joint,velocity)
end
joint_1=sim.getObjectHandle('joint_1')
joint_2=sim.getObjectHandle('joint_2')
Shape4=sim.getObjectHandle('Shape4')
Shape7=sim.getObjectHandle('Shape7')
velocity=0
torque=0
Shape4 = 0
Shape7 = 0
end
因部分語法有誤,日後待除錯。
stage2 <<
Previous Next >> W6