stage2-ag1

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

W7 Keyboard Control

利用鍵盤操控物體行走

(🔽程式碼)

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="" pre="">


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

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