stage3-bg5

  • Home
    • Site Map
    • reveal
    • blog
  • 首頁
  • 每周進度
    • W10 新增Stage1、2 工作分配
      • stage1
      • stage2
    • W11 討論小組主題
    • W12 無障礙越野車繪製
    • W13 無障礙越野車修改
    • W12-13coppelia模擬
    • W14coppelia模擬
    • W15coppelia模擬
  • 直播影片
    • w12
    • w13
    • w14
    • w15
  • Task2
    • Stage 1
    • Stage 2
    • Stage 3
  • 期末報告 PDF
  • 小組個人心得
    • 40823204 賴惟嘉
    • 40823205 李詩涵
    • 40823220 黃彥維
    • 40823221 陳柏翰
    • 40823228 丁偉倫
    • 40823237 吳青諭
    • 40823242 游子建
    • 40823250 張哲瑀
    • 40832244 林晉廷
  • 筆記
    • coppelia啟動教學
    • lua語法和按鍵介紹
Task2 << Previous Next >> Stage 2

Stage 1

stage1-bg14

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, "40823242",
        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,"1",opmode)#設定軸對應名稱
 
    while True:
        #keyboard "w" 前進
     if keyboard.is_pressed("w"):
            print("up")
            
            vrep.simxSetJointTargetVelocity(clientID,vertical_handle,-0.01,opmode)
     if keyboard.is_pressed("s"):#keyboard "s" 後退
            print("down")
            
            vrep.simxSetJointTargetVelocity(clientID,vertical_handle,0.01,opmode)
 
     if keyboard.is_pressed("q"):#keyboard "q" 前進後退停止
            print("stop")
            
            vrep.simxSetJointTargetVelocity(clientID,vertical_handle,0,opmode)
      
else:
    print ('Failed connecting to  remote API server')
print ('End')

stage1-bg16

stage1-bg24

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.50.217', 19997, True, True, 5000, 5)
   
if clientID !=-1:
    print ('Connected to remote API server')
    
    res = vrep.simxAddStatusbarMessage(
        clientID, "40823204",
        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
    STREAMING = vrep.simx_opmode_streaming
      
    vrep.simxStartSimulation(clientID, opmode)
     
     
    ret,joint0=vrep.simxGetObjectHandle(clientID,"joint0",opmode)
    ret,joint1=vrep.simxGetObjectHandle(clientID,"joint1",opmode)
    dy=0
    dr=0
    vrep.simxSetJointTargetPosition(clientID,joint0,dy,opmode)
    vrep.simxSetJointTargetPosition(clientID,joint1,dr,opmode)
     
    while True:
        #Clockwise
        if keyboard.is_pressed("2"):
            dy=dy-0.1
            dr=dr+0.1
            vrep.simxSetJointTargetPosition(clientID,joint0,dy,opmode)
            vrep.simxSetJointTargetPosition(clientID,joint1,dr,opmode)
            print("go")
  
else:
    print ('Failed connecting to  remote API server')
    print ('End')


Task2 << Previous Next >> Stage 2

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