Ipuch / bioNC

Natural Coordinates with python for biomechanics
MIT License
11 stars 4 forks source link

No mass_matrix creation when using SegmentTemplate. #96

Closed ANaaim closed 1 year ago

ANaaim commented 1 year ago

When creating a segment in a model using the following :

    model["RSHANK"] = SegmentTemplate(
        natural_segment=NaturalSegmentTemplate(
            u_axis=AxisFunctionTemplate(
                function=lambda m, bio: MarkerTemplate.normal_to(m, bio, right_knee_joint(m, bio), "RFAL", "RTAM")
            ),
            proximal_point=right_knee_joint,
            # the knee joint computed from the medial femoral epicondyle and the lateral femoral epicondyle
            distal_point=lambda m, bio: MarkerTemplate.middle_of(m, bio, "RFAL", "RTAM"),
            w_axis=AxisTemplate(start="RTAM", end="RFAL"),
        ),
        inertia_parameters=InertiaParametersTemplate(mass=1,
            center_of_mass=np.array([0, -0.5, 0]),  # in segment coordinates system
            inertia=np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

    )

The inertia parameters are not given to the natural segment later on. I have the following error later on in the code (in inverse_dynamic class):

  File "----------------------------------------\bioNC\bioNC\bionc\bionc_casadi\natural_segment.py", line 768, in inverse_dynamics
    (self.mass_matrix @ Qddoti)
     ~~~~~~~~~~~~~~~~~^~~~~~~~

because self.mass_matrix is None.

Should the segment constructed differently or a specific command should be run for the segmentTemplate to update the different value ? I saw that for the examples three_link_pendulum.py, you are directly creating natural segment with the inertia properties which is different from creating from c3d data i suppose.

I will continue to investigate ... 🕵️

Thanks

Ipuch commented 1 year ago

Get a look into the update function at the end of the script. There's a todo left inside.

Indeed I do not add the inertial parameters. This feature is not ready yet. 🙈

That's why I mainly use the model builder from scratch.

My concerns about the c3d builder was to give the easiest and comprehensive way to build a model. And that time, I didn't have a clear view of what should be done.

ANaaim commented 1 year ago

Ok for me ^^' at least i am not crazy 🤪. Sometime difficult to know if i just did not understand the way stuff are getting around or if it is just not implemented.

So it will be nedded if we want to compare result from real analysis. Let's go :)

Ipuch commented 1 year ago

A work around can be to set it, after building the model.

For example

Model.segments["thigh"].mass=xx

ANaaim commented 1 year ago

This command generate such error message :

Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm 2023.1.4\plugins\python\helpers\pydev_pydevd_bundle\pydevd_exec2.py", line 3, in Exec exec(exp, global_vars, local_vars) File "", line 1, in AttributeError: property 'mass' of 'NaturalSegment' object has no setter

Ipuch commented 1 year ago

I think I can close this as it is an expected behavior.