40823122

  • Home
    • Site Map
    • reveal
    • blog
  • stage1-ag13
    • w2
      • 網頁建立以及偕同修改
    • w3
      • 分組網站
      • 產品
    • w4
    • w5
  • stage2-ag7
    • w6
    • w7
      • 整合分組網頁
      • v-rep模擬
  • w8
  • stage3-ag6
    • w10
      • task1
      • task2
    • w13
    • w14
    • w15
      • MTB_robort
      • 字幕整理
    • w16
      • 成果
    • w17
      • 籃框移動控制
      • 程式
      • 導入w16的機械手臂
    • w18
籃框移動控制 << Previous Next >> 導入w16的機械手臂

程式

function sysCall_init()
    -- do some initialization here
     joint=sim.getObjectHandle('Revolute_joint')--定義軸跟四條感測器
     proximity = sim.getObjectHandle("Proximity_sensor")--
     proximity0 = sim.getObjectHandle("Proximity_sensor0")--
     proximity1 = sim.getObjectHandle("Proximity_sensor1")--
     proximity2 = sim.getObjectHandle("Proximity_sensor2")--
     ball = sim.getObjectHandle("ball")
     ball2 = sim.getObjectHandle("Sphere")
     boallDummy = sim.getObjectHandle("Dummy")
     --sim.sJointTargetVelocity(joint,5.5)
     axis3=sim.getObjectHandle('slide')
     distance3 = 0
     number=-16
     a = 0
     --print(auxiliaryData[1])
     --if (auxiliaryData[1]==string.byte(' ')) then
      
 
end
function sysCall_actuation()
    --定義四根感測器的名稱
    local res = sim.readProximitySensor(proximity)
    local res0 = sim.readProximitySensor(proximity0)
    local res2 = sim.readProximitySensor(proximity2)
    local res1 = sim.readProximitySensor(proximity1)
     --當球經過四條感測器,只要其中一條的值為1對a初始值進行運算
     if res == 1 or res0 == 1 or res1 == 1 or res2 == 1 then
     a = a+1
     print(a)--同時顯示出a現在的值
     end
 message,auxiliaryData=sim.getSimulatorMessage()
 if (message==sim.message_keypress) then
      if (auxiliaryData[1]==2007) then--按下方向鍵上,擊球桿的主動軸順時針旋轉
      sim.setJointTargetVelocity(joint,number)
      end
      if (auxiliaryData[1]==32) then--按下空白建,擊球桿的主動軸速度為0
      sim.setJointTargetVelocity(joint,0)
      end
      if (auxiliaryData[1]==2008) then--按下方向鍵下,擊球桿的主動軸逆時針旋轉且速度為1
      sim.setJointTargetVelocity(joint,1)
      end
      if (auxiliaryData[1]==114) then --r/重新添加球
      local insertedObjects = sim.copyPasteObjects({ball,ball2,ballDummy},0)
      -- local disturbedCoordinates = {-2,0.02,4}
      -- local disturbedCoordinates = {1,0,1}
      local disturbedCoordinates = {4,-2.35,1.5}
      sim.setObjectPosition(insertedObjects[1],-1,disturbedCoordinates)
      end
 end   
 
 
end
function sysCall_sensing()
    -- put your sensing code here
end
 
function sysCall_cleanup()
    -- do some clean-up here
end
 
-- See the user manual or the available code snippets for additional callback functions and details



四條感應器的擺法


籃框移動控制 << Previous Next >> 導入w16的機械手臂

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