Page 1 of 1

to acquire a value through a script

Posted: 08 Jun 2018, 11:56
by SIRX
Hi at all,
I made a little mass-damper model and I used a force sensor to measure the weight and publish it to a graph. All works! but I would not know how extract this measure and store inside a variable. I undestand that I have to write a script.
someone would indicate me the way to follow.
Thanks in advance

Re: to acquire a value through a script

Posted: 08 Jun 2018, 13:00
by coppelia
Hello,

the best is you have a look at the many scenes and example models, and check the attached scripts. Here a very simple example on how you can make the object where the child script is attached move in each simulation step:

Code: Select all

function sysCall_init()
    handle=sim.getObjectAssociatedWithScript(sim.handle_self)
    initialPosition=sim.getObjectPosition(handle,-1)
    velocity={0.01,0.02,0.005} -- in m/s
end

function sysCall_actuation()
    local dt=sim.getSimulationTimeStep()
    local p=sim.getObjectPosition(handle,-1)
    p[1]=p[1]+velocity[1]*dt
    p[2]=p[2]+velocity[2]*dt
    p[3]=p[3]+velocity[3]*dt
    sim.setObjectPosition(handle,-1,p)
end

function sysCall_cleanup()
    sim.setObjectPosition(handle,-1,initialPosition)
end
Cheers

Re: to acquire a value through a script

Posted: 12 Jun 2018, 17:42
by SIRX
thanks a lot