堆高機 <<
Previous Next >> 遊樂設施
夾爪機構
測試人員:40823234 日期:2021/05/05
第一版
第一版
import sim as vrep
import math
import random
import time
print ('Start')
# Close eventual old connections
vrep.simxFinish(-1)
# Connect to V-REP remote server
clientID = vrep.simxStart('192.168.1.114', 19997, True, True, 5000, 5)
if clientID !=-1:
print ('Connected to remote API server')
res = vrep.simxAddStatusbarMessage(
clientID, "40823234",
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
vrep.simxStartSimulation(clientID, opmode)
ret, wristHandle = vrep.simxGetObjectHandle(clientID, "VerticalJoint",opmode)
vrep.simxSetJointTargetVelocity(clientID,wristHandle,1,opmode)
ret, wristHandle = vrep.simxGetObjectHandle(clientID, "SpiritJoint",opmode)
vrep.simxSetJointTargetVelocity(clientID,wristHandle,1,opmode)
ret, wristHandle = vrep.simxGetObjectHandle(clientID, "joint",opmode)
vrep.simxSetJointTargetVelocity(clientID,wristHandle,1,opmode)
else:
print ('Failed connecting to remote API server')
print ('End')
測試人員:40823234 日期:2021/05/10
第二版 使用python keyboard 檔案下載:remote api.zip
使用keyboard程式:
import sim as vrep
import math
import random
import time
import keyboard
print ('Start')
# Close eventual old connections
vrep.simxFinish(-1)
# Connect to V-REP remote server
clientID = vrep.simxStart('192.168.1.114', 19997, True, True, 5000, 5)
if clientID !=-1:
print ('Connected to remote API server')
res = vrep.simxAddStatusbarMessage(
clientID, "40823234",
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
vrep.simxStartSimulation(clientID, opmode)
ret,vertical_handle=vrep.simxGetObjectHandle(clientID,"VerticalJoint",opmode)#設定軸對應名稱
ret,spirit_handle=vrep.simxGetObjectHandle(clientID,"SpiritJoint",opmode)
ret,cam_handle=vrep.simxGetObjectHandle(clientID,"joint",opmode)
while True:
#keyboard "w" 前進
if keyboard.is_pressed("w"):
print("You pressed w")
vrep.simxSetJointTargetVelocity(clientID,vertical_handle,0.1,opmode)
if keyboard.is_pressed("s"):#keyboard "s" 後退
print("You pressed s")
vrep.simxSetJointTargetVelocity(clientID,vertical_handle,-0.1,opmode)
if keyboard.is_pressed("a"):#keyboard "a"向左
print("You pressed a")
vrep.simxSetJointTargetVelocity(clientID,spirit_handle,0.1,opmode)
if keyboard.is_pressed("d"):#keyboard "d" 向右
print("You pressed d")
vrep.simxSetJointTargetVelocity(clientID,spirit_handle,-0.1,opmode)
if keyboard.is_pressed("q"):#keyboard "q" 前進後退停止
print("You pressed q")
vrep.simxSetJointTargetVelocity(clientID,vertical_handle,0,opmode)
if keyboard.is_pressed("e"):#keyboard "e" 左右停止
print("You pressed e")
vrep.simxSetJointTargetVelocity(clientID,spirit_handle,0,opmode)
if keyboard.is_pressed("r"):#keyboard "r" 凸輪轉動
print("You pressed r")
vrep.simxSetJointTargetVelocity(clientID,cam_handle,1,opmode)
if keyboard.is_pressed("f"):#keyboard "f" 凸輪停止
print("You pressed f")
vrep.simxSetJointTargetVelocity(clientID,cam_handle,0,opmode)
else:
print ('Failed connecting to remote API server')
print ('End')
堆高機 <<
Previous Next >> 遊樂設施