40823112 cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • Collaboration
  • Stage 1
    • W1
      • 利用SSH維護倉儲
      • 建立倉儲
      • 建立Leo編輯Palican
      • 協同倉儲
    • W2
      • Project production
      • 手繪草稿
      • 初步設計與討論
    • W3
      • 錯誤排解 齒輪方向與速度
      • 錯誤排解 傳動改正
      • 產品簡化
      • 完成品
    • W4
      • 2D工程圖
      • 3D爆炸圖
      • 產品設計報告與影片
  • Stage 2
    • W5
      • Stage2 Grouping
      • 進度規劃
    • W6
      • 討論
    • W7
      • Coppeliasim方向鍵操控模擬
      • 模擬問題與排解
    • W8
      • Coppeliasim避障自走車
      • 模擬問題和排解
    • W9
      • 產品報告與模擬影片
  • Stage 3
    • W10
      • Task 1
    • W11
      • task 2-1
      • task 2-2
    • W12
      • 上課直播
    • W13
      • 小組meeting直播
      • RobotDK
    • W14
      • MTB_Robot
    • W15
      • Geometry Translation
      • Algebra Translation
    • W18
    • Final Project
  • W16
  • Product Install
    • stage1-ag10
    • stage2-ag1
    • stage3-ag1
W7 << Previous Next >> 模擬問題與排解

Coppeliasim方向鍵操控模擬

(🔽程式碼)

function sysCall_init() 
    left_handle= sim.getObjectHandle('left_m')
    right_handle= sim.getObjectHandle('right_m')
    MaxVel=2
    leftvelocity=0
    rightvelocity=0
    dVel=0.5;
    sim.setJointTargetVelocity(left_handle,leftvelocity)
    sim.setJointTargetVelocity(right_handle,rightvelocity)
end
 
function sysCall_actuation() 
    message,auxiliaryData=sim.getSimulatorMessage()
    while message~=-1 do
        if (message==sim.message_keypress) then
            if (auxiliaryData[1]==32) then
                -- right key
                leftvelocity=0
                rightvelocity=0
                sim.setJointForce(left_front_handle, 0)
                sim.setJointForce(right_front_handle, 0)
                break
            else
                sim.setJointForce(left_handle, 10000)
                sim.setJointForce(right_handle, 10000)
            end
            if (auxiliaryData[1]==2007) then
                -- up key
                leftvelocity=(leftvelocity+rightvelocity)/2
                rightvelocity=leftvelocity
                leftvelocity=leftvelocity+dVel
                rightvelocity=rightvelocity+dVel
            end
            if (auxiliaryData[1]==2008) then
                -- down key
                leftvelocity=(leftvelocity+rightvelocity)/2
                rightvelocity=leftvelocity
                leftvelocity=leftvelocity-dVel
                rightvelocity=rightvelocity-dVel
            end
            if (auxiliaryData[1]==2009) then
                -- left key
                leftvelocity=leftvelocity-dVel
                rightvelocity=rightvelocity+dVel
            end
            if (auxiliaryData[1]==2010) then
                -- right key
                leftvelocity=leftvelocity+dVel
                rightvelocity=rightvelocity-dVel
            end
        end
        message,auxiliaryData=sim.getSimulatorMessage()
    end
     
    if leftvelocity>MaxVel then
        leftvelocity=MaxVel
    end
    if leftvelocity<-MaxVel then
        leftvelocity=-MaxVel
    end
     
    if rightvelocity>MaxVel then
                rightvelocity=MaxVel
    end
    if rightvelocity<-MaxVel then
                rightvelocity=-MaxVel
    end
     
    sim.setJointTargetVelocity(left_handle,leftvelocity)
    sim.setJointTargetVelocity(right_handle,rightvelocity)
     
end

W7 << Previous Next >> 模擬問題與排解

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