cd2021 - 40823109

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Stage1
    • W1
      • SSH setup
      • set website
    • W2
      • 草圖繪製
      • 3D圖繪製
    • W3
      • 3D爆炸圖與工作圖
      • 傳動設計修改
    • W4
  • stage2
    • W5
    • W6
    • W7
    • W8
    • W9
  • stage3
    • W10
      • task1
      • task2
    • W11
      • task 3
    • W13
    • W15
      • using geometry
      • using algebra
    • W16
      • 1. Onshape 零組件繪製
      • 2.建立 CoppeliaSim 4.1.0 MTB robot 場景
      • 3.手臂末端加入吸盤
      • 4.逆向運動學函式
      • 5.Python remote API 逆向運動學函式
    • 專案成果
  • w18
    • 期末報告影片
  • Questions and answers
    • ValueError
    • pip無法使用
    • leo 無法使用
W6 << Previous Next >> W8

W7

經過前兩週的測試,這週我們成功使機器人可以用方向鍵進行操控。

模擬圖 :

第三次Lua程式 (成功)

function sysCall_init() 
    left_front_handle= sim.getObjectHandle('left_m')
    left_back_handle= sim.getObjectHandle('left_m')
    right_back_handle= sim.getObjectHandle('right_m')
    right_front_handle= sim.getObjectHandle('right_m')
    MaxVel=2
    leftvelocity=0
    rightvelocity=0
    dVel=0.5;
    --sim.setJointTargetVelocity(left_front_handle,leftvelocity)
    sim.setJointTargetVelocity(left_back_handle,leftvelocity)
    sim.setJointTargetVelocity(right_back_handle,rightvelocity)
    --sim.setJointTargetVelocity(right_front_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(left_back_handle, 0)
                sim.setJointForce(right_back_handle, 0)
                sim.setJointForce(right_front_handle, 0)
                break
            else
                --sim.setJointForce(left_front_handle, 10000)
                sim.setJointForce(left_back_handle, 10000)
                sim.setJointForce(right_back_handle, 10000)
                --sim.setJointForce(right_front_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_front_handle,leftvelocity)
    sim.setJointTargetVelocity(left_back_handle,leftvelocity)
    sim.setJointTargetVelocity(right_back_handle,rightvelocity)
    --sim.setJointTargetVelocity(right_front_handle,rightvelocity)
    
end 

已成功使用方向鍵控制模型,下週將會加入視覺傳感器與力傳感器,讓模型在遇到物體時可以自動避開。


W6 << Previous Next >> W8

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