40823251 CD2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • 個人作業
    • W1 新增LEO
    • W2 繪製圖檔
    • W3 程式模擬
    • W4 報告分工
      • 影片程式
    • W5 stage2討論
    • W6 主題修正
    • W7 stage2圖檔
    • W8 程式模擬
    • W9 期中作業
    • W10 個人task
      • 連接ipv4
      • task1
      • task2
    • W11 個人OBS直播
    • W12 個人直播
    • W13 個人gitlab
    • W14 robotDK測試
    • W15 影片翻譯
    • W16 取分進度
    • W17 2分鐘影片
    • W18 期末報告影片
  • 小組討論
    • W1 影片討論
    • W2 小組繪圖
    • W3 小組模擬
    • W4 小組報告
      • 影片時間
    • W5 stage2分工
    • W6 修正討論
    • W7 小組圖檔和模擬
    • W8 統整檔案
    • W9 小組成果
    • W10 小組task1
    • W11 上課直播
    • W12 小組直播
    • W13 w13、w14直播討論
    • W14 MTB測試
    • W15 小組翻譯
  • Task2測試區
    • 掃地機器人
    • 分球機
    • 堆高機
    • 夾爪機構
  • 筆記
    • SSH
    • 分組程式
    • cmsimde改版
    • 小組倉儲問題
    • Heroku建立
    • remote api筆記
    • Gogs建立
  • 個人影片
  • 上課直播區
  • W5
  • W16
task1 << Previous Next >> W11 個人OBS直播

task2

執行任務人員為:40823245
本人task2為透過小組協同網頁下載py檔和請教40823245已完成此任務。

第一版

說明:先將基本的程式對應到掃地機器人的軸,已達成可運作效果。

import sim as vrep

clientID = vrep.simxStart('192.168.192.112', 19997, True, True, 5000, 5)
 
if clientID != -1:
    print ('Connected to remote API server')
 
    res = vrep.simxAddStatusbarMessage(
        clientID, "text",
        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.")
else:
       print ('Failed connecting to remote API server')

class VrepLineFollower:
  def __init__(self):
    vrep.simxFinish(-1) # just in case, close all opened connections
    self.clientID = vrep.simxStart('192.168.192.112', 19997, True, True, 5000, 5)
    vrep.simxStartSimulation(self.clientID, vrep.simx_opmode_oneshot)
    
    self.wheelRadius = 0.027
    self.linearVelocityLeft  = 0.1
    self.linearVelocityRight = 0.1
    
    # vectors [left, right]
    self.direction_v = {
     'up':    [ 0.01,  0.01],
     'down':  [-0.01, -0.01],
     'left':  [-0.01,  0.01],
     'right': [ 0.01, -0.01]
    }

    res, self.leftJointDynamic  = vrep.simxGetObjectHandle(self.clientID, "LBMotor",  vrep.simx_opmode_oneshot_wait)
    res, self.rightJointDynamic = vrep.simxGetObjectHandle(self.clientID, "RBMotor", vrep.simx_opmode_oneshot_wait)

  # direction = 'up' | 'down' | 'left' | 'right'
  def to_direction(self, direction):
        direction_vector = self.direction_v[direction]
        self.linearVelocityLeft  += direction_vector[0]
        self.linearVelocityRight += direction_vector[1]
        self.set_motors()

  # private
  def set_motors(self):
        t_left  = self.linearVelocityLeft  / self.wheelRadius
        t_right = self.linearVelocityRight / self.wheelRadius
        vrep.simxSetJointTargetVelocity(self.clientID, self.leftJointDynamic,  t_left,  vrep.simx_opmode_oneshot_wait)
        vrep.simxSetJointTargetVelocity(self.clientID, self.rightJointDynamic, t_right, vrep.simx_opmode_oneshot_wait)

第二版

說明:利用api控制。

import sim as vrep

clientID = vrep.simxStart('192.168.192.112', 19997, True, True, 5000, 5)
 
if clientID != -1:
    print ('Connected to remote API server')
 
    res = vrep.simxAddStatusbarMessage(
        clientID, "text",
        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.")
else:
       print ('Failed connecting to remote API server')

class VrepLineFollower:
  def __init__(self):
    vrep.simxFinish(-1) # just in case, close all opened connections
    self.clientID = vrep.simxStart('192.168.192.112', 19997, True, True, 5000, 5)
    vrep.simxStartSimulation(self.clientID, vrep.simx_opmode_oneshot)
    
    self.wheelRadius = 0.027
    self.linearVelocityLeft  = 0.1
    self.linearVelocityRight = 0.1
    
    # vectors [left, right]
    self.direction_v = {
     'up':    [ 0.01,  0.01],
     'down':  [-0.01, -0.01],
     'left':  [-0.01,  0.01],
     'right': [ 0.01, -0.01]
    }

    res, self.leftJointDynamic  = vrep.simxGetObjectHandle(self.clientID, "LBMotor",  vrep.simx_opmode_oneshot_wait)
    res, self.rightJointDynamic = vrep.simxGetObjectHandle(self.clientID, "RBMotor", vrep.simx_opmode_oneshot_wait)

  # direction = 'up' | 'down' | 'left' | 'right'
  def to_direction(self, direction):
        direction_vector = self.direction_v[direction]
        self.linearVelocityLeft  += direction_vector[0]
        self.linearVelocityRight += direction_vector[1]
        self.set_motors()

  # private
  def set_motors(self):
        t_left  = self.linearVelocityLeft  / self.wheelRadius
        t_right = self.linearVelocityRight / self.wheelRadius
        vrep.simxSetJointTargetVelocity(self.clientID, self.leftJointDynamic,  t_left,  vrep.simx_opmode_oneshot_wait)
        vrep.simxSetJointTargetVelocity(self.clientID, self.rightJointDynamic, t_right, vrep.simx_opmode_oneshot_wait)




task1 << Previous Next >> W11 個人OBS直播

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