cd2021 40823236

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Stage1-bg7
    • W1
    • W2(零件)
    • W3(模擬)
    • W4
  • W5
  • Stage2-bg9
    • W5 討論主題
    • W7零件繪製
    • W7~W8CoppeliaSim程式模擬
    • W9小組報告及影片
  • Stage3-bg3
    • W9
      • Stage1
      • Stage2
    • W10
      • task1
      • task2
    • W11
      • 小組討論內容
    • W12 零件
      • 火車
      • 彈珠檯
      • 迷宮
    • W13
    • W15
    • W16 吸盤手臂
      • Onshape 繪圖
      • MTB robot 場景
      • 手臂末端加入吸盤
      • 逆向運算學函式
      • Python remote API
  • 直播影片
    • W11直播
    • W12直播
    • W13直播
    • W15直播
  • 心得
task1 << Previous Next >> W11

task2

使用白窗控制Coppeliasim

程式碼參考第一組成員40823245~

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.111', 19997, True, True, 5000, 5)
   
if clientID !=-1:
    print ('Connected to remote API server')
    
    res = vrep.simxAddStatusbarMessage(
        clientID, "40823231",
        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,"shaft_1",opmode)
    ret,shaft2=vrep.simxGetObjectHandle(clientID,"shaft_2",opmode)
    ret,shaft3=vrep.simxGetObjectHandle(clientID,"shaft_3",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')

task1 << Previous Next >> W11

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