檔案:new football
V-REP程式模擬結果
PYTHON程式碼
import vrep import keyboard import time import sys, math vrep.simxFinish(-1) clientID = vrep.simxStart("127.0.0.1", 19997, True, True, 5000, 5) KickBoV = 360 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') err,Sphere_handle=vrep.simxGetObjectHandle(clientID,'Sphere',vrep.simx_opmode_oneshot_wait) err,Pole_handle=vrep.simxGetObjectHandle(clientID,'Pole',vrep.simx_opmode_oneshot_wait) err,Revolute_handle=vrep.simxGetObjectHandle(clientID,'Revolute',vrep.simx_opmode_oneshot_wait) err,Prismatic_handle=vrep.simxGetObjectHandle(clientID,'Prismatic',vrep.simx_opmode_oneshot_wait) err,Revolute2_handle=vrep.simxGetObjectHandle(clientID,'Revolute2',vrep.simx_opmode_oneshot_wait) err,Prismatic2_handle=vrep.simxGetObjectHandle(clientID,'Prismatic2',vrep.simx_opmode_oneshot_wait) err,Pole2_handle=vrep.simxGetObjectHandle(clientID,'Pole2',vrep.simx_opmode_oneshot_wait) if err == -1: print('Can not find left or right motor') sys.exit() def speed(handle,speed): err = vrep.simxSetJointTargetVelocity(clientID,handle,speed,vrep.simx_opmode_oneshot_wait) def start(): err=vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot_wait) while True: err,position_LR=vrep.simxGetObjectPosition(clientID,Revolute2_handle,-1,vrep.simx_opmode_oneshot) err,position_S=vrep.simxGetObjectPosition(clientID,Sphere_handle,-1,vrep.simx_opmode_oneshot) err,position_RR=vrep.simxGetObjectPosition(clientID,Revolute_handle,-1,vrep.simx_opmode_oneshot) LP =position_S[1] - position_LR[1] LPP =position_S[0] - position_LR[0] RP =position_S[1] - position_RR[1] RPP =position_S[0] - position_RR[0] print(position_S) if LPP <-0.015: speed(Revolute2_handle,R_KickBoV) elif LPP >= -0.015: speed(Revolute2_handle,L_KickBoV) else: pass if RPP >0.015: speed(Revolute_handle, L_KickBoV) elif RPP <= 0.015: speed(Revolute_handle,R_KickBoV) else: pass Pv = LP*3 PPV=RP*3 vrep.simxSetJointTargetVelocity(clientID,Prismatic2_handle,Pv,vrep.simx_opmode_oneshot_wait) vrep.simxSetJointTargetVelocity(clientID,Prismatic_handle,Pv,vrep.simx_opmode_oneshot_wait) vrep.simxSetJointTargetVelocity(clientID,Prismatic_handle,0,vrep.simx_opmode_oneshot_wait) vrep.simxSetJointTargetVelocity(clientID,Prismatic2_handle,0,vrep.simx_opmode_oneshot_wait) start()