40823234 CD2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • work
    • w2 零件繪製
    • w3 CoppeliaSim 模擬
    • w4
  • 問題與解決方法
  • W5
  • Stage2
    • W7第一次模擬
    • W8第二次模擬
    • W9第三次模擬
  • stage3
    • task2
      • 分球機
      • task2 夾爪機構
  • W15
  • w16
分球機 << Previous Next >> W15

task2 夾爪機構

測試人員: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 >> W15

Copyright © All rights reserved | This template is made with by Colorlib