How to move an object by a slider

Typically: "How do I... ", "How can I... " questions
Post Reply
SIRX
Posts: 16
Joined: 17 Mar 2018, 15:22

How to move an object by a slider

Post by SIRX »

Hi at all,
I am trying to move an object (simply cuboid) through a prismatic joint (torque/force mode) of which I want setting up the position by a slider (UI). The script does not return errors, but it does not work. Someone has suggestions.
Thanks a lot
Sirx

Code: Select all

function PosChange_callback(ui,id,newVal)
pos=newVal*100
end

function sysCall_init()
    -- This is executed exactly once, the first time this script is executed
    Cuboid=sim.getObjectAssociatedWithScript(sim.handle_self) -- this is bubbleRob's handle
    leftMotor=sim.getObjectHandle("Prismatic_joint") -- Handle of the left motor
   
    minMaxSpeed={0.1,1} -- 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(Cuboid)..' pos" closeable="false" resizeable="false" activate="false">'..
[[
        <hslider minimum="0" maximum="100" onchange="PosChange_callback" id="1"/>
        <label text="" style="* {margin-left: 200px;}"/>


        </ui>
        ]]
    ui=simUI.create(xml)
    pos=0
    simUI.setSliderValue(ui,1,0)
 
end

function sysCall_actuation()
sim.setJointTargetPosition(leftMotor,pos)
     
end

function sysCall_cleanup()
	simUI.destroy(ui)
end

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: How to move an object by a slider

Post by fferri »

the slider value is an integer value from 0 to 100.
you are multiplying that value by 100, and using it for setting the object position, so you are setting the position in increments of 100 meters.

SIRX
Posts: 16
Joined: 17 Mar 2018, 15:22

Re: How to move an object by a slider

Post by SIRX »

Hi fferri,
Now it works.
Thanks
Sirx

Post Reply