W4 <<
Previous Next >> W6
W5
第五週分組專案開始,分組以第一次分組兩兩合併為主。
組別為:stage2-ag1
組員:
40823108-cd2021
40823109-cd2021
40823112-cd2021
40823145-cd2021
本次專案沿用stage1-ag1之專案,為了讓模型能夠按照我們的意思做動,我們嘗試編寫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
因部分語法有誤,日後待除錯。
W4 <<
Previous Next >> W6