biorbd icon indicating copy to clipboard operation
biorbd copied to clipboard

Bug in ID with ExternalForceSet ?

Open fbailly opened this issue 1 year ago • 2 comments

Hi Benjamin,

When using the ExternalForceSet feature, I might be encountering a bug when computing the Inverse Dynamics. It looks like the Point of Application of the Spatial Vector is not accounted for. MWE below :

model_path = "./cube.bioMod"

q = np.array([0.5, 0.5, 0.5]) dq = np.array([1., 1., 1.]) ddq = np.array([1., 1., 1.])

sv = np.array([1., 1., 1., 1., 1., 1.]) sv = biorbd.SpatialVector(sv) biomodel = biorbd.Model(model_path)

model_external_force_set0 = biorbd.ExternalForceSet(biomodel, True, True) contact_point_vector0 = biorbd.Vector3d(0.0, 0.0, 0.0) model_external_force_set0.addInSegmentReferenceFrame('Seg1', sv, contact_point_vector0) id0 = biomodel.InverseDynamics(q, dq, ddq, model_external_force_set0).to_array()

model_external_force_set1 = biorbd.ExternalForceSet(biomodel, True, True) contact_point_vector1 = biorbd.Vector3d(1., 1., 1.) model_external_force_set1.addInSegmentReferenceFrame('Seg1', sv, contact_point_vector1) id1 = biomodel.InverseDynamics(q, dq, ddq, model_external_force_set1).to_array()

id2 = biomodel.InverseDynamics(q, dq, ddq).to_array()

print(f"ID with spatial vector = {sv.to_array()} and contact point = {contact_point_vector0.to_array()} = {id0}") print(f"ID with spatial vector = {sv.to_array()} and contact point = {contact_point_vector1.to_array()} = {id1}") print(f"ID without ExternalForceSet = {id2}")

cube.bioMod :

version 4

// Seg1 segment Seg1 translations xz rotations y rangesQ -0.70 2.30 -3 3 -pi pi mass 1 inertia 1 0 0 0 1 0 0 0 1 com 0 0 0 endsegment

fbailly avatar Nov 23 '23 10:11 fbailly

Hi there! You are probably on biorbd 1.10.1, can you update to 1.10.2?

pariterre avatar Nov 23 '23 14:11 pariterre

I am on 1.10.2

fbailly avatar Nov 23 '23 14:11 fbailly

I confirm this is still the case in 1.11.1

Ipuch avatar Apr 25 '24 17:04 Ipuch

I infirm this is not still the case in 1.11.1

pariterre avatar Apr 25 '24 19:04 pariterre

@fbailly

Changing

sv = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])

I get :

ID with spatial vector = [1. 2. 3. 4. 5. 6.] and contact point = [0. 0. 0.] = [-5.38688348 7.46220678 -1. ] ID with spatial vector = [1. 2. 3. 4. 5. 6.] and contact point = [1. 1. 1.] = [-5.38688348 7.46220678 1. ] ID without ExternalForceSet = [ 1. 10.81 1. ]

The torque along z is changed, but because you had only one DOF in rotation and your case was a special one. You could not see the effect of changing the application point.

Ipuch avatar Apr 25 '24 19:04 Ipuch

Yes thanks @Ipuch . This was actually the conclusion we agreed on with @pariterre months ago. The issue should have been closed before. Thanks for the follow up !

fbailly avatar Apr 25 '24 21:04 fbailly