40823202 cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Develop
  • HW
    • W2~W4
      • 第一版
      • 第二版
      • ppt和影片
    • w6~w8
      • 模擬
      • 檔案下載
    • w9~w18
      • w10
      • W11
      • W12
      • W13
      • W14
      • W15
      • W16
      • w17
  • W5
  • 問題
    • 救回commit
    • 沒辦法開python
    • PUSH 不了
  • 筆記
    • 協同推送
    • CoppeliaSim基本操作
W12 << Previous Next >> W14

W13

進行task2 remote API

程式碼:

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.43.111', 19997, True, True, 5000, 5)
    
if clientID !=-1:
    print ('Connected to remote API server')
     
    res = vrep.simxAddStatusbarMessage(
        clientID, "40823202",
        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,shaft1=vrep.simxGetObjectHandle(clientID,"shaft1",opmode)
    ret,shaft2=vrep.simxGetObjectHandle(clientID,"shaft2",opmode)
    ret,shaft3=vrep.simxGetObjectHandle(clientID,"shaft3",opmode)
  
    while True:
        if keyboard.is_pressed("w"):
            vrep.simxSetJointTargetVelocity(clientID,shaft1,2,opmode)
            print("w")
              
        if keyboard.is_pressed("s"):
            vrep.simxSetJointTargetVelocity(clientID,shaft1,0,opmode)
            print("s")
              
        if keyboard.is_pressed("a"):
            vrep.simxSetJointTargetVelocity(clientID,shaft2,2,opmode)
            print("a")
  
        if keyboard.is_pressed("b"):
            vrep.simxSetJointTargetVelocity(clientID,shaft2,0,opmode)
            print("b")
              
        if keyboard.is_pressed("c"):
            vrep.simxSetJointTargetVelocity(clientID,shaft3,0.1,opmode)
            print("c")
  
        if keyboard.is_pressed("z"):
            vrep.simxSetJointTargetVelocity(clientID,shaft3,0,opmode)
            print("z")           
else:
    print ('Failed connecting to  remote API server')
    print ('End')

模擬檔:https://drive.google.com/drive/u/0/my-drive


W12 << Previous Next >> W14

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