40823231 cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • stage1
    • w1製作討論
    • W2~W3製圖及模擬
      • 零件圖繪製
      • CoppeliaSim程式模擬
    • W4報告影片
  • W5
  • stage2
    • W6製作分工討論
    • W7~W8零件圖
    • W8~W9CoppeliaSim程式模擬
  • stage3
    • task1
    • task2
    • task3
      • 第11週
      • 第12週
      • 第13週
      • 第15週
    • 模擬影片
  • W15
    • 影片整理1
    • 影片整理2
  • W16
    • lua程式碼
    • 鍵盤指令程式
    • python remoteApi程式
    • require
    • 吸盤程式
第15週 << 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')

第15週 << Previous Next >> W15

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