期末彈珠台導入設定加模擬
圖檔:onshape
vrep:彈珠台
程式:
import vrep import keyboard import time import sys, math # child threaded script: # 內建使用 port 19997 若要加入其他 port, 在 serve 端程式納入 #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) KickBallV = 360 R_KickBallVel = (math.pi/180)*KickBallV B_KickBallVel = -(math.pi/180)*KickBallV if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Sphere_handle=vrep.simxGetObjectHandle(clientID,'Sphere',vrep.simx_opmode_oneshot_wait) errorCode,bbb1_handle=vrep.simxGetObjectHandle(clientID,'bbb1',vrep.simx_opmode_oneshot_wait) errorCode,Rt_handle=vrep.simxGetObjectHandle(clientID,'Rt',vrep.simx_opmode_oneshot_wait) errorCode,Ra_handle=vrep.simxGetObjectHandle(clientID,'Ra',vrep.simx_opmode_oneshot_wait) vrep.simxSetJointTargetVelocity(clientID,bbb1_handle,0,vrep.simx_opmode_oneshot_wait) vrep.simxSetJointTargetVelocity(clientID,Ra_handle,0,vrep.simx_opmode_oneshot_wait) vrep.simxSetJointTargetVelocity(clientID,Rt_handle,0,vrep.simx_opmode_oneshot_wait) def con(): errorCode = vrep.simxSetJointTargetVelocity(clientID,Rt_handle,R_KickBallVel,vrep.simx_opmode_oneshot_wait) def clo(): errorCode = vrep.simxSetJointTargetVelocity(clientID,Ra_handle,B_KickBallVel,vrep.simx_opmode_oneshot_wait) def up(): errorCode = vrep.simxSetJointTargetVelocity(clientID,bbb1_handle,100,vrep.simx_opmode_oneshot_wait) vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot_wait) while True: try: if keyboard.is_pressed('a'): con() else: vrep.simxSetJointTargetVelocity(clientID,Rt_handle,B_KickBallVel,vrep.simx_opmode_oneshot_wait) if keyboard.is_pressed('l'): clo() else: vrep.simxSetJointTargetVelocity(clientID,Ra_handle,R_KickBallVel,vrep.simx_opmode_oneshot_wait) if keyboard.is_pressed('up'): up() else: vrep.simxSetJointTargetVelocity(clientID,bbb1_handle,-50,vrep.simx_opmode_oneshot_wait) except: break