Cancelling Gravity Using addForce

Typically: "How do I... ", "How can I... " questions
Post Reply
CroCr
Posts: 82
Joined: 29 Dec 2022, 01:47

Cancelling Gravity Using addForce

Post by CroCr »

My project requires the use of force sensors. An end-effector kuka arm has been attached with a capsulate shape using force sensor joint. Although the sensor provides readings, there is some offset due to the capsulate's weight (i.e. 0.06kg). I need to get rid of this bias. I came across two solutions in https://forum.coppeliarobotics.com/view ... hp?t=10056

1- Manually compute the capsulate's center, its mass, and express them plus the gravity vector in the sensor's frame.
2- adding an anti-gravity force using sim.addForce.

As the robot moves, it appears the first solution is not suitable. How can I use the second option? Are there other solutions considering I'm controlling the robot using kinematic control schemes?

For the second option, I did

Code: Select all

function sysCall_sensing()
local cap = sim.getObjectPosition(capsuleHandle,sim.handle_world)
sim.addForce(CapsuleHandle,cap,{0,0,0.06*9.81})
end
The sensor still provides measurements. Notice: part of the capsule shape is inside the sensor's frame (i.e. the capsule shape and the end-effector shape overlap).

I'm using CoppeliaSim 4.5.1 Ubuntu 18.04.

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

Re: Cancelling Gravity Using addForce

Post by coppelia »

Hello,

both solutions work fine, but the second is a bit simpler. In your case you could just do:

Code: Select all

sim.addForceAndTorque(CapsuleHandle,{0,0,0.06*9.81})
sim.addForceAndTorque applies the force (and possibly a torque) at the center of mass of the shape, where the force vector is expressed in the absolute frame, relative to the origine frame.

sim.addForce on the other hand allows to add a non-central force that is applied with an offset, with the offset and force vector is expressed relative to the inertia frame.

Cheers

CroCr
Posts: 82
Joined: 29 Dec 2022, 01:47

Re: Cancelling Gravity Using addForce

Post by CroCr »

coppelia wrote: 20 Jun 2024, 13:37 Hello,

both solutions work fine, but the second is a bit simpler. In your case you could just do:

Code: Select all

sim.addForceAndTorque(CapsuleHandle,{0,0,0.06*9.81})
sim.addForceAndTorque applies the force (and possibly a torque) at the center of mass of the shape, where the force vector is expressed in the absolute frame, relative to the origine frame.

sim.addForce on the other hand allows to add a non-central force that is applied with an offset, with the offset and force vector is expressed relative to the inertia frame.

Cheers

As far as static cases are concerned, the method is effective. It is, however, not reliable when the arm falls down since it measures force. Check out this picture where I paused the simulation during the fall of the arm. You can see this picture

Image


I've tried to call sim.addForceAndTorque in sysCall_actuation(), sysCall_sensing(), and sysCall_dyn(inData). The worst case with sysCall_dyn(). Although the first two methods are similar, they are not same. Where should I call addForceAndTorque() function?

A minimal working example is attached.

https://www.dropbox.com/t/Po5q7cKzX9my7tXl

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

Re: Cancelling Gravity Using addForce

Post by coppelia »

Well, when the beam falls, then there is not just gravity to compensate, since inertia (translational and rotational) of the attached cube generates additional forces/torques.

To compensate for that would probably be quite challenging, if you do not want to incure a vicious action/reaction loop (my guess).

In any case, best would be to do that in each dynamics step, i.e. in sysCall_dyn:

Code: Select all

function sysCall_dyn(inData)
    if inData.afterStep ~= true then
        -- Compensate gravity:
        sim.addForceAndTorque(ToolHandle | sim.handleflag_resetforce,{0,0,1.25*9.81})

        -- Compensate for inertia:
        result, forceVector, torqueVector = sim.readForceSensor(ForceSensor)
        -- compute compensationVector and compensationTorque here
        sim.addForceAndTorque(ToolHandle, compensationVector, compensationTorque)
    end
end
Computing compensationVector and compensationTorque is the challenging thing if trying to derive that from the sensor reading. You'd have to first convert the read force and torque into absolute coordinates.

Cheers

Post Reply