task1 <<
Previous Next >> task3
task2
05/04 利用remoteApi控制stage1小組作業(分球機)旋轉軸速度
第一版
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('172.20.10.2', 19997, True, True, 5000, 5)
if clientID !=-1:
print ('Connected to remote API server')
res = vrep.simxAddStatusbarMessage(
clientID, "40823208",
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, "joint",opmode)
vrep.simxSetJointTargetVelocity(clientID,wristHandle,5,opmode)
else:
print ('Failed connecting to remote API server')
print ('End')
05/12 新增鍵盤控制分球機轉速
第二版
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.83', 19997, True, True, 5000, 5)
if clientID !=-1:
print ('Connected to remote API server')
res = vrep.simxAddStatusbarMessage(
clientID, "40823208",
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, "joint",opmode)
while True:
if keyboard.is_pressed("Q"):
print("Velocity=5")
vrep.simxSetJointTargetVelocity(clientID,wristHandle,5,opmode)
#Q可以讓轉速=5
if keyboard.is_pressed("W"):
print("Velocity=10")
vrep.simxSetJointTargetVelocity(clientID,wristHandle,10,opmode)
#W可以讓轉速=10
if keyboard.is_pressed("E"):
print("Velocity=0")
vrep.simxSetJointTargetVelocity(clientID,wristHandle,0,opmode)
#E可以讓轉速=0
else:
print ('Failed connecting to remote API server')
print ('End')
task1 <<
Previous Next >> task3