檔案:new football
V-REP模擬結果
PYTHON程式碼
import vrep
import keyboard
from time import sleep
import sys, math
vrep.simxFinish(-1)
clientID = vrep.simxStart("127.0.0.1", 19997, True, True, 5000, 5)
KickBoV = 90
n=1
L_KickBoV = (math.pi/180)*KickBoV
R_KickBoV = -(math.pi/180)*KickBoV
if clientID!= -1:
print('connect successfully')
else:
print('connect failed')
vrep.simxFinish(clientID)
print('program ended')
errorCode,Sphere_handle=vrep.simxGetObjectHandle(clientID,'Sphere',vrep.simx_opmode_oneshot_wait)
errorCode,Pole_handle=vrep.simxGetObjectHandle(clientID,'Pole',vrep.simx_opmode_oneshot_wait)
errorCode,Revolute_handle=vrep.simxGetObjectHandle(clientID,'Revolute',vrep.simx_opmode_oneshot_wait)
errorCode,Prismatic_handle=vrep.simxGetObjectHandle(clientID,'Prismatic',vrep.simx_opmode_oneshot_wait)
errorCode,Revolute2_handle=vrep.simxGetObjectHandle(clientID,'Revolute2',vrep.simx_opmode_oneshot_wait)
errorCode,Prismatic2_handle=vrep.simxGetObjectHandle(clientID,'Prismatic2',vrep.simx_opmode_oneshot_wait)
errorCode,Pole2_handle=vrep.simxGetObjectHandle(clientID,'Pole2',vrep.simx_opmode_oneshot_wait)
if errorCode == -1:
print('Can not find left or right motor')
sys.exit()
def start():
errorCode = vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot_wait)
while True:
try:
if keyboard.is_pressed('r'):
vrep.simxSetJointTargetVelocity(clientID,Revolute_handle,R_KickBoV,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('t'):
vrep.simxSetJointTargetVelocity(clientID,Revolute_handle,L_KickBoV,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('q'):
vrep.simxSetJointTargetVelocity(clientID,Prismatic_handle,0.05,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('w'):
vrep.simxSetJointTargetVelocity(clientID,Prismatic_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('e'):
vrep.simxSetJointTargetVelocity(clientID,Prismatic_handle,-0.05,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('.'):
vrep.simxSetJointTargetVelocity(clientID,Revolute2_handle,L_KickBoV,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('/'):
vrep.simxSetJointTargetVelocity(clientID,Revolute2_handle,R_KickBoV,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('b'):
vrep.simxSetJointTargetVelocity(clientID,Prismatic2_handle,0.05,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('n'):
vrep.simxSetJointTargetVelocity(clientID,Prismatic2_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('m'):
vrep.simxSetJointTargetVelocity(clientID,Prismatic2_handle,-0.05,vrep.simx_opmode_oneshot_wait)
else:
pass
except:
break
start()