stage2-ag1

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • Work Distribution
  • Cooperation
  • Weekly progress
    • W5
    • W6
    • W7 Keyboard Control
      • 模擬問題與排解
    • W8 Sensor Control
      • Sensor模擬問題與排解
    • W9
  • Product Install
模擬問題與排解 << Previous Next >> Sensor模擬問題與排解

W8 Sensor Control

增加接近傳感器使產品自動行走時,不會撞到障礙物

(🔽程式碼)

function sysCall_init()
    
    
end

function sysCall_actuation()
    
end

function sysCall_sensing()
    
end

function sysCall_cleanup()
    
end



function sysCall_afterDelete(inData)
    for key,value in pairs(inData.objectHandles) do
        print("Object with handle "..key.." was deleted")
    end
    
end

function sysCall_afterCreate(inData)
    for key,value in pairs(inData.objectHandles) do
        print("Object with handle "..value.." was created")
    end
end
--]]
function speedChange_callback(ui,id,newVal)
    speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*newVal/100
end

function sysCall_init()
    
    bubbleRobBase=sim.getObjectAssociatedWithScript(sim.handle_self) 
    leftMotor=sim.getObjectHandle("bubbleRob_leftMotor") 
    rightMotor=sim.getObjectHandle("bubbleRob_rightMotor") 
    noseSensor=sim.getObjectHandle("bubbleRob_sensingNose") 
    minMaxSpeed={120*math.pi/180,300*math.pi/180} 
    backUntilTime=-1 
   
        xml = ''..[[
        
        
        
        ]]
    ui=simUI.create(xml)
    speed=(minMaxSpeed[1]+minMaxSpeed[2])*1
    simUI.setSliderValue(ui,1,100*(speed-minMaxSpeed[1])/(minMaxSpeed[2]-minMaxSpeed[1]))
end

function sysCall_actuation()
    result=sim.readProximitySensor(noseSensor) 
    
    if (result>0) then backUntilTime=sim.getSimulationTime()+4 end 

    if (backUntilTime<sim.getSimulationTime()) then
        
        sim.setJointTargetVelocity(leftMotor,speed)
        sim.setJointTargetVelocity(rightMotor,speed)
    else
        
        sim.setJointTargetVelocity(leftMotor,-speed/5)
        sim.setJointTargetVelocity(rightMotor,-speed/200)
    end
end

function sysCall_cleanup()
	simUI.destroy(ui)
end


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

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