吸盤測試 <<
Previous Next >> 鍵盤控制方塊取放
Python remote API
模擬檔案下載:點我.
api.py 程式碼:
import sim as vrep
import math
import random
import time
import math
def moving (x,y):
a=0.4
b=0.4
c=math.pow((math.pow(x,2)+math.pow(y,2)),0.5)
s=(a+b+c)/2
area=math.pow((s*(s-a)*(s-b)*(s-c)),0.5)
h=2*area/c
deg1_base=math.atan(x/y)
if x<0 and y<0 :
deg1_base=deg1_base+math.pi
end
print ('Start')
vrep.simxFinish(-1)
clientID = vrep.simxStart('192.168.9.16', 19997, True, True, 5000, 5)
if clientID != -1:
print ('Connected to remote API server')
res = vrep.simxAddStatusbarMessage(
clientID, "This is teach by 40823214 ",
vrep.simx_opmode_oneshot)
if res not in (vrep.simx_return_ok, vrep.simx_return_novalue_flag):
print("Could not add a message to the status bar.")
opmode = vrep.simx_opmode_oneshot_wait
STREAMING = vrep.simx_opmode_streaming
vrep.simxStartSimulation(clientID, opmode)
ret,joint01=vrep.simxGetObjectHandle(clientID,"joint1",opmode)
ret,joint02=vrep.simxGetObjectHandle(clientID,"joint2",opmode)
ret,joint03=vrep.simxGetObjectHandle(clientID,"joint3",opmode)
ret,jointz=vrep.simxGetObjectHandle(clientID,"jointz",opmode)
vrep.simxSetJointTargetPosition(clientID,joint01,0,opmode)
vrep.simxSetJointTargetPosition(clientID,joint02,0,opmode)
vrep.simxSetJointTargetPosition(clientID,joint03,0,opmode)
vrep.simxSetIntegerSignal(clientID,"pad_switch",1,opmode)
vrep.simxSetJointTargetPosition(clientID,jointz,-0.09,opmode)
time.sleep(4)
vrep.simxSetJointTargetPosition(clientID,jointz,0,opmode)
moving(0.2,0.7)
time.sleep(9)
vrep.simxSetIntegerSignal(clientID,"pad_switch",0,opmode)
time.sleep(4)
vrep.simxSetIntegerSignal(clientID,"pad_switch",1,opmode)
vrep.simxSetJointTargetPosition(clientID,jointz,-0.09,opmode)
time.sleep(4)
vrep.simxSetJointTargetPosition(clientID,jointz,0,opmode)
moving(-0.3,-0.55)
vrep.simxSetJointTargetPosition(clientID,jointz,0,opmode)
moving(0.2,0.7)
time.sleep(9)
vrep.simxSetIntegerSignal(clientID,"pad_switch",0,opmode)
time.sleep(4)
vrep.simxSetIntegerSignal(clientID,"pad_switch",1,opmode)
vrep.simxSetJointTargetPosition(clientID,jointz,-0.09,opmode)
time.sleep(4)
vrep.simxSetJointTargetPosition(clientID,jointz,0,opmode)
吸盤測試 <<
Previous Next >> 鍵盤控制方塊取放