stage1四驅車延伸 <<
Previous Next >> python remote api 控制
鍵盤控制
使用lua程式控制車子前進、後退和停止
lua程式碼▼
function sysCall_init()
left_front_handle= sim.getObjectHandle('s11')
left_back_handle= sim.getObjectHandle('s11')
right_back_handle= sim.getObjectHandle('s22')
right_front_handle= sim.getObjectHandle('s22')
MaxVel=27
leftvelocity=0
rightvelocity=0
dVel=2.7;
--sim.setJointTargetVelocity(left_front_handle,leftvelocity)
sim.setJointTargetVelocity(left_back_handle,leftvelocity)
sim.setJointTargetVelocity(right_back_handle,rightvelocity)
--sim.setJointTargetVelocity(right_front_handle,rightvelocity)
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
leftvelocity=0
rightvelocity=0
sim.setJointForce(left_front_handle, 0)
sim.setJointForce(left_back_handle, 0)
sim.setJointForce(right_back_handle, 0)
sim.setJointForce(right_front_handle, 0)
break
else
--sim.setJointForce(left_front_handle, 10000)
sim.setJointForce(left_back_handle, 10000)
sim.setJointForce(right_back_handle, 10000)
--sim.setJointForce(right_front_handle, 10000)
end
if (auxiliaryData[1]==2008) then
-- up key
leftvelocity=(leftvelocity+rightvelocity)/2
rightvelocity=leftvelocity
leftvelocity=leftvelocity+dVel
rightvelocity=rightvelocity+dVel
end
if (auxiliaryData[1]==2007) then
-- down key
leftvelocity=(leftvelocity+rightvelocity)/2
rightvelocity=leftvelocity
leftvelocity=leftvelocity-dVel
rightvelocity=rightvelocity-dVel
end
end
message,auxiliaryData=sim.getSimulatorMessage()
end
if leftvelocity>MaxVel then
leftvelocity=MaxVel
end
if leftvelocity<-MaxVel then
leftvelocity=-MaxVel
end
if rightvelocity>MaxVel then
rightvelocity=MaxVel
end
if rightvelocity<-MaxVel then
rightvelocity=-MaxVel
end
sim.setJointTargetVelocity(left_back_handle,leftvelocity)
sim.setJointTargetVelocity(right_back_handle,rightvelocity)
end
成果影片▼
stage1四驅車延伸 <<
Previous Next >> python remote api 控制