Vrep UI滑条的值改变时内部的处理理解

function sysCall_init()
    a=0    
    -- This is executed exactly once, the first time this script is executed
    bubbleRobBase=sim.getObjectAssociatedWithScript(sim.handle_self) -- this is bubbleRob's handle
    leftMotor=sim.getObjectHandle("bubbleRob_leftMotor") -- Handle of the left motor
    rightMotor=sim.getObjectHandle("bubbleRob_rightMotor") -- Handle of the right motor
    noseSensor=sim.getObjectHandle("bubbleRob_sensingNose") -- Handle of the proximity sensor
    minMaxSpeed={50*math.pi/180,300*math.pi/180} -- Min and max speeds for each motor
    backUntilTime=-1 -- Tells whether bubbleRob is in forward or backward mode
    -- Create the custom UI:
    xml = '<ui title="'..sim.getObjectName(bubbleRobBase)..' linmianhaospeed" closeable="false" resizeable="false" activate="false">'..[[

                <label text=" speed: " style="* {margin-right: 300px;}" id="2"/>
                <hslider minimum="0" maximum="100" on-change="speedChange_callback" id="1"/>
                            
        </ui>
        ]]
    ui=simUI.create(xml)
    speed=(minMaxSpeed[1]+minMaxSpeed[2])*0.5
    simUI.setSliderValue(ui,1,150*(speed-minMaxSpeed[1])/(minMaxSpeed[2]-minMaxSpeed[1]))
    --simUI.setLabelText(ui,2,speed)
    --simUI.setLabelText(ui,2,'speed: '..a..' velocity')
  
    --simUI.setSliderValue(ui,2,100*(speed-minMaxSpeed[1])/(minMaxSpeed[2]-minMaxSpeed[1]))
end
function speedChange_callback(ui,id,newVal)
    speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*newVal/100
    simUI.setLabelText(ui,2,'speed: '..speed..' velocity')
end

1.on-change

当滑动滑条改变滑条的值的时候就会触发speedChange_callback()这个函数,滑条的值就是newValue,然后在

speedChange_callback()这个函数里处理,改变speed的值,同时在label里显示速度的值。代码如下所示:

on-change="speedChange_callback"
Name of a Lua function to handle the change event. Arguments of the function are: (uiHandle, id, newValue).
function speedChange_callback(ui,id,newVal)
    speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*newVal/100
    simUI.setLabelText(ui,2,'speed: '..speed..' velocity')
end


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值