Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any function to calculate automatically Qdot and Qddot from an experimental Q (or post optim) ? #95

Open
ANaaim opened this issue Oct 4, 2023 · 5 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@ANaaim
Copy link
Contributor

ANaaim commented Oct 4, 2023

Hello,

I do not found any function to automatically calculate naturalVelocities and naturalAccelerations from a naturalsegment (from experimental data). Is there any ? I might have not looked properly.

If not might be interesting for beginner user in order to have them only to give the Q extracted in the inverse function. In that case we would calculate ourselve the qdot and qddot.

Best regards

@Ipuch
Copy link
Owner

Ipuch commented Oct 4, 2023

Can you show me, how should it look like? i.e. how would you like to use it in bioNC ?

What are the computational steps behind ?

The most close feature I see, is the method _Q_from markers that estimates Q from marker locations in global.

This fonctions are set when building the model.

@ANaaim
Copy link
Contributor Author

ANaaim commented Oct 4, 2023

That would be to do something like that for doing inverse dynamics :

    cut_freq = 6

    w = cut_freq / (freq / 2)  # Normalize the frequency
    b, a = signal.butter(4, w, 'low')

    Qdopt_sqp = np.gradient(Qopt_sqp,1/freq, axis=1)
    Qdopt_sqp_filt = signal.filtfilt(b, a, Qdopt_sqp, axis=1)
    Qddopt_sqp = np.gradient(Qdopt_sqp_filt,1/freq, axis=1)
    Qddopt_sqp_filt = signal.filtfilt(b, a, Qddopt_sqp, axis=1)

    for ind_frame in range(0,Qopt_sqp.shape[1]):
        tuple_of_Q = [
            SegmentNaturalCoordinates.from_components(
                u=Qopt_sqp[i*12:i*12+3,ind_frame], rp=Qopt_sqp[i*12+3:i*12+6, ind_frame], rd=Qopt_sqp[i*12+6:i*12+9, ind_frame], w=Qopt_sqp[i*12+9:i*12+12, ind_frame]
            )
            for i in range(0, model.nb_segments)
        ]

        tuple_of_Qddot = [
            SegmentNaturalAccelerations.from_components(
                uddot=Qddopt_sqp_filt[i * 12:i * 12 + 3, ind_frame], rpddot=Qddopt_sqp_filt[i * 12 + 3:i * 12 + 6, ind_frame],
                rdddot=Qddopt_sqp_filt[i * 12 + 6:i * 12 + 9, ind_frame], wddot=Qddopt_sqp_filt[i * 12 + 9:i * 12 + 12, ind_frame]
            )
            for i in range(0, model.nb_segments)
        ]

        Q = NaturalCoordinates.from_qi(tuple(tuple_of_Q))
        Qddot = NaturalAccelerations.from_qddoti(tuple(tuple_of_Qddot))

        torques, forces, lambdas = model.inverse_dynamics(Q=Q, Qddot=Qddot)

@Ipuch
Copy link
Owner

Ipuch commented Oct 4, 2023

There is a thin line to determine what should bioNC do.

I was initially more focus on the physical part. So handling the equation Of motion.

My point is that embedding automatic filtering options, I am not convinced yet.

However we could have differentiation module in coordinates class such as:

NaturalCoordinate.differentiate(method="central",dt=...)

And return NaturalVelocity object. :)

As there was two features presented in your post let's start with this one first.

We will see for the other one later.

Also if your priority is to make an example of ID. You can choose to push it entirely and choose to treat this issue later on. If ID example is in the example folder I have no problem to push a code that include custom functionalities.

@ANaaim
Copy link
Contributor Author

ANaaim commented Oct 4, 2023

Currently, i would rather focus to the inverse dynamics (in a way i have to go deeper in the code and it is good to do). Let's keep this for later :)

But at least, it was normal to not found such function :)

@Ipuch Ipuch added enhancement New feature or request question Further information is requested labels Oct 4, 2023
@Ipuch
Copy link
Owner

Ipuch commented Oct 4, 2023

Great !

Don't hesistate to open your pull request.

We'll need to open an issue (a good first) based on our conversation too 👌🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants