to acquire a value through a script

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

to acquire a value through a script

Post by SIRX » 08 Jun 2018, 11:56

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

coppelia
Site Admin
Posts: 6617
Joined: 14 Dec 2012, 00:25

Re: to acquire a value through a script

Post by coppelia » 08 Jun 2018, 13:00

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

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

Re: to acquire a value through a script

Post by SIRX » 12 Jun 2018, 17:42

thanks a lot

Post Reply