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
to acquire a value through a script
Re: to acquire a value through a script
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:
Cheers
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:
- Add a dummy to the scene
- Attach a non-threaded child script to it
- enter following code:
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