On the Problem of Parameter Position in the sim.addforce Function

Typically: "How do I... ", "How can I... " questions
Post Reply
jiaqiYu
Posts: 5
Joined: 20 Apr 2023, 04:16

On the Problem of Parameter Position in the sim.addforce Function

Post by jiaqiYu »

Code: Select all

sim.addForce(int shapeHandle,float[3] position,float[3] force)
The position parameter in this function is written as a relative position in the official document. Is this relative position based on the object coordinate system?I have some doubts about the position of the force applied by using this function. If you could provide an answer to this, I would greatly appreciate it.

The following is my code to apply a force to an object(a cuboid):

Code: Select all

function sysCall_init()
    -- do some initialization here
    hcuboid = sim.getObject('.')
end

function sysCall_actuation()
    --position=sim.getObjectPosition(hcuboid,sim.handle_world)
    --print(position)
    sim.addForce(hcuboid,{0,0,0},{2,0,0})
end
The script was placed on the block, but the object did not move at all after running the simulation. But if I set the position parameter to {0,0,0.05}, the block will move in a straight line. The size of the block is 0.1 * 0.1 * 0.1

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

Re: On the Problem of Parameter Position in the sim.addforce Function

Post by coppelia »

Hello,

the function sim.addForce applies a force relative to the center of mass, so if you have an offset, that will be relative to the center of mass.
In your first situation, the force is applied at the center of mass and just not large enough to make the cube slide. In the second situation, the force is applied at the top of the cube, which will generate additionally a moment of rotation, and that's why the cube will slide.

Best is to try in a situation where there is no gravity to get an idea of what happens.

Cheers

Post Reply