task1 <<
Previous Next >> task2-2-python Remote API程式控制機械手臂
task2-1
import sim as vrep
import sys
# child threaded script:
#simExtRemoteApiStart(19999)
vrep.simxFinish(-1)
clientID = vrep.simxStart('127.0.0.1', 19999, True, True, 5000, 5)
if clientID!= -1:
print("Connected to remote server")
else:
print('Connection not successful')
sys.exit('Could not connect')
errorCode, handle1=vrep.simxGetObjectHandle(clientID,'cd1',vrep.simx_opmode_oneshot_wait)
error_Code,handle2=vrep.simxGetObjectHandle(clientID,'cd2',vrep.simx_opmode_oneshot_wait)
errorCode,handle3=vrep.simxGetObjectHandle(clientID,'cd3',vrep.simx_opmode_oneshot_wait)
errorCode,handle4=vrep .simxGetObjectHandle(clientID,'cd4',vrep.simx_opmode_oneshot_wait)
errorCode,handle5=vrep.simxGetObjectHandle(clientID,'cd5',vrep.simx_opmode_oneshot_wait)
if errorCode == -1:
print('Can not find left or right motor')
sys.exit()
errorCode=vrep.simxSetJointTargetVelocity(clientID,handle1,1, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,handle2,0, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,handle3,1, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,handle4,0, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,handle5,0.02, vrep.simx_opmode_oneshot_wait)
task1 <<
Previous Next >> task2-2-python Remote API程式控制機械手臂