task1 <<
Previous Next >> W11
task2
使用 Python remote API 進行操控 stage1 與 stage2 所完成的 coppeliasim 場景
YT :
Python remote API 程式 stage 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,boat_motor_handle=vrep.simxGetObjectHandle(clientID,'boat_motor',vrep.simx_opmode_oneshot_wait)
if errorCode == -1:
print('Can not find motor')
sys.exit()
errorCode=vrep.simxSetJointTargetVelocity(clientID,boat_motor_handle,0, vrep.simx_opmode_oneshot_wait)
Python remote API 程式 stage 2
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,left_m_handle=vrep.simxGetObjectHandle(clientID,'left_m',vrep.simx_opmode_oneshot_wait)
errorCode,right_m_handle=vrep.simxGetObjectHandle(clientID,'right_m',vrep.simx_opmode_oneshot_wait)
if errorCode == -1:
print('Can not find left or right motor')
sys.exit()
errorCode=vrep.simxSetJointTargetVelocity(clientID,left_m_handle,0, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,right_m_handle,0, vrep.simx_opmode_oneshot_wait)
task1 <<
Previous Next >> W11