Typically: "How do I... ", "How can I... " questions
vrepUser1
Posts: 10
Joined: 22 Oct 2016, 16:20

Hello,
I'm a bit confused about simAddForce. In the description added forces are cumulative (within a timestep??) and the force will be reset to zero after one dynamic timestep by default or I have to set the handleflag? How it works when I want to add a force within each dynamic timestep in my c++ plugin?

Thank you!
Best,
vrepUser1

coppelia
Posts: 7450
Joined: 14 Dec 2012, 00:25

Hello,

if you use sim.addForce (or sim.addForceAndTorque) within a non-specific function, then forces are cumulative within a given time step. E.g. following compensates for gravity, once per simulation step:

Code: Select all

function sysCall_init()
h=sim.getObjectAssociatedWithScript(sim.handle_self)
m=sim.getShapeMassAndInertia(h)
end

function sysCall_actuation()
local accel=sim.getArrayParameter(sim.arrayparam_gravity)
end
Above will set the force/torque for the given simulation step. By default, a simulation step contains 10 dynamics simulation steps. If you want to adjust the force/torque for each of the individual dynamics simulation steps, use a dynamics callback function. In this case, it is important to explicitely reset the accumulated force:

Code: Select all

function sysCall_init()
h=sim.getObjectAssociatedWithScript(sim.handle_self)
m=sim.getShapeMassAndInertia(h)
end

function sysCall_dynCallback(inData)
local accel=sim.getArrayParameter(sim.arrayparam_gravity)
end

function sysCall_actuation()
end
Cheers

vrepUser1
Posts: 10
Joined: 22 Oct 2016, 16:20

Thank you very much. It is much clearer now. One question arises now. I will call sim.addForce on a body B in my c++ plugin. How I reset the accumulated force within the c++ plugin?

Note: I'm using version 3.5.0 rev.4.

Best,
vrepuser1

coppelia
Posts: 7450
Joined: 14 Dec 2012, 00:25

if you want to do this from within a plugin, I would do it like:

Have your plugin register a custom Lua function simMyPlugin.dynCallback.
Then have a child script with following:

Code: Select all

function sysCall_dynCallback(inData)
...
end
Basically your child script will call a function in your plugin to get the desired force/torque, and apply it in the child script.
Also, make sure to upgrade to V3.6.0 rev1

Cheers

vrepUser1
Posts: 10
Joined: 22 Oct 2016, 16:20

I tried the way like you suggested, but its a lot of code I would generate in dynCallback. Anyway its working for this:

Code: Select all

function sysCall_dynCallback(inData)
....
end

But as far I try to reset the accumulated force with only the resetforce flag or together with both flags:

Code: Select all

function sysCall_dynCallback(inData)
....
end

I receive an error that the object doesnt exist.
EDIT: Ok updated to 3.6.0. Now this works.

Is not possible to do it directly in plugin? If I would do it like you suggest, I had to maintain a lot of entities, which are inside the plugin and not the child script itself. This is the way I really want to do it.

Best,
vrepuser1

coppelia