40823235

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • stage1-bg2
    • 圖檔
    • w2
    • w4
    • 問題與討論
  • stage2-bg2
    • W5
    • 問題
    • 凸輪繪製
    • W7
      • 模擬一
      • 模擬二
    • W8
      • 模擬三
    • W9
  • stage3-bg1
    • TASK1
    • TASK2
      • 分球機
      • 夾爪
      • 掃地機器人
  • W15
    • 影片一
    • 影片二
  • W16
    • coppelisim
    • onshape
  • 期末報告
分球機 << Previous Next >> 掃地機器人

夾爪

ㄑㄑ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('127.0.0.1', 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 >> 掃地機器人

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