stage3-bg3

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • 每周進度
    • W9
      • Stage1
      • Stage2
    • W10
      • task1
    • w11
      • task2
    • w12
      • 小組討論內容
    • w13
      • robodk測試
    • w14
      • python學習
  • 零件圖
    • 彈珠檯
    • 迷宮
    • 火車
      • 火車改版(第一版)
      • 火車改版(最終板)
  • 直播影片
  • 模擬
    • 彈珠檯模擬
    • 火車模擬
  • W15
    • 影片整理
彈珠檯模擬 << Previous Next >> W15

火車模擬

coppeliasim 場景檔

程式碼:

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.110', 19997, True, True, 5000, 5)
   
if clientID !=-1:
    print ('Connected to remote API server')
    
    res = vrep.simxAddStatusbarMessage(
        clientID, "all start",
        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,wheel1=vrep.simxGetObjectHandle(clientID,"wheel_1",opmode)
    ret,wheel2=vrep.simxGetObjectHandle(clientID,"wheel_2",opmode)
    ret,wheel3=vrep.simxGetObjectHandle(clientID,"wheel_3",opmode)
    ret,wheel4=vrep.simxGetObjectHandle(clientID,"wheel_4",opmode)
 
    while True:
        if keyboard.is_pressed("g"):
            vrep.simxSetJointTargetVelocity(clientID,wheel1,20,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel2,20,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel3,20,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel4,20,opmode)
            print("go")
             
        if keyboard.is_pressed("r"):
            vrep.simxSetJointTargetVelocity(clientID,wheel1,-20,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel2,-20,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel3,-20,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel4,-20,opmode)
            print("back")
             
        if keyboard.is_pressed("s"):
            vrep.simxSetJointTargetVelocity(clientID,wheel1,0,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel2,0,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel3,0,opmode)
            vrep.simxSetJointTargetVelocity(clientID,wheel4,0,opmode)
            print("stop")
         
else:
    print ('Failed connecting to  remote API server')
    print ('End')

彈珠檯模擬 << Previous Next >> W15

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