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

CMC does not work with some models. #3522

Open
SietseAchterop opened this issue Jul 18, 2023 · 5 comments
Open

CMC does not work with some models. #3522

SietseAchterop opened this issue Jul 18, 2023 · 5 comments

Comments

@SietseAchterop
Copy link

This is a reformulation of issue #3345. There has been no response at all for half a year, and I am still stuck.
Therefore I will try to reformulate it to hopefully make it more clear.
It's a long story, so please bear with me.

The issue is about using (fast target) CMC when, also, using generalized coordinates, so (partly) no muscles.
But first some context.
The usecase is a rower in a rowing boat, or more generally, a person with an exo-skeleton.
My first attempt was one with very a simple person and rowing boat, all without muscles.
The idea is that the trajectory of the person is given and the simulation calculates the movement of the boat with its oars.

All attempts have failed so far, so I started to simplify the model as much as possible.
It now is reduced to a model with only one PinJoint and one BallJoint.
The model and setup can be found here: Test4.zip

In the video below the model and its behavior is shown until the point where it fails because forces become too high.

Test4_fail.webm

The trajectory is simple and only should keep the model in its initial position, apart from a little disturbance between 0.5 and 0.6 seconds.
If that disturbance (seen in the red line below) is not added the instability also arises, but only after 5 seconds.
In that case the instability probably arises from numerical rounding errors.
Here a plot of the behavior of the balljoint.

Run_away

It seems that, with uparmleft_up, there seems to be NO attempt to correct to the intended value.
It is as if the correction is done in the wrong direction!
This is what the log shows in the last step.

[info] CMC::computeControls, t = 1.796
[info] -- step size = 0.00200000, target time = 1.798
[info] ------------------------------
[info] CMC::computeControls, summary:
[info] ------------------------------
[info] -- Q = ~[0.149381 0.138471 3.33369 -39.9112 0]
[info] -- U = ~[-2.9615 4.35461 -5.78199 161.977]
[info] -- Z = ~[]
[info] -- Qdesired = 0.119718 0.934394 2.04204 -0.409413
[info] -- Udesired = 3.43429e-16 -8.55612e-15 1.09897e-14 5.49486e-15
[info] -- Qcorrection = 0.0296631 -0.795922 1.29166 -39.5017
[info] -- Ucorrection = -2.9615 4.35461 -5.78199 161.977
[info] ------------------------------

So CMC just isn't working in this model.

What could be the problem here?
Is there something with the balljoint or with the fast target formulation in the case of (only) using generalised coordinates?
Is there anyone that can help me with this CMC problem?

Thanks in advance, Sietse.

@mrrezaie
Copy link
Contributor

mrrezaie commented Aug 5, 2023

@SietseAchterop
Copy link
Author

I tried the above, but regrettably there was no place for me.
Are there going to be other opportunities?
I really don't know what to do next. I really had big plans wih this project,
but I am completely stuck now!

I reduced my problem to a very simple one, see Test4.zip above.
Because of the simplicity of the model and that it obviously fails makes me think that it would be an interesting example to be investigated.
Why don't simple models just work, why doesn't the PD-control part kick in, what is wrong with CMC?
The model not only becomes unstable, there seems to be no effort to correct anything if the model deviates from the intended trajectory.

Is there really nobody that can at least confirm that it fails and that I didn't do something really stupid?

@mrrezaie
Copy link
Contributor

mrrezaie commented Jan 5, 2024

Hi @SietseAchterop, I'm not expert, but I found that if you replace the BallJoint with CustomJoint, CMC will track the desired kinematics as expected. Perhaps CMC doesn't support the former joint type or it requires extra elements (developers may confirm). I executed the tool with all default parameters. Here is an example to define a CustomJoint in your code:

sp= osim.SpatialTransform()
arr = osim.ArrayStr()
arr.append('uarmleft_out')
sp.updTransformAxis(0).setCoordinateNames(arr)
sp.updTransformAxis(0).set_function(osim.LinearFunction())
arr = osim.ArrayStr()
arr.append('uarmleft_trn')
sp.updTransformAxis(1).setCoordinateNames(arr)
sp.updTransformAxis(1).set_function(osim.LinearFunction())
arr = osim.ArrayStr()
arr.append('uarmleft_up')
sp.updTransformAxis(2).setCoordinateNames(arr)
sp.updTransformAxis(2).set_function(osim.LinearFunction())

uarmlJoint = osim.CustomJoint("upper_arm_left_Joint",
                            lowerb,
                            osim.Vec3(0, backl/2, 0),
                            osim.Vec3(0, 0, pi/2),
                            upperal,
                            osim.Vec3(0, -uarml/2, 0),
                            osim.Vec3(0, 0, 0), sp)

Hope this helps,
-Mohammadreza

@SietseAchterop
Copy link
Author

Thanks alot, this works!
I now am trying to get my more complicated models to work which had 4 balljoints, but hopefully the change to Customjoint solves these instabilities.
When that works I will close the issue.
Thanks again!
Sietse

@mrrezaie
Copy link
Contributor

But why this happens? I thought BallJoint is the same as CustomJoint without translations.

This is the only note I could find about this joint. Is this the reason?

- 2021-01-11: An Exception is now thrown if the model includes joints whose
generalized speeds do not match the derivative of the generalized
coordinates (i.e., BallJoint, FreeJoint, EllipsoidJoint, and
ScapulothoracicJoint).

If there is some contraindication, it would be great if you address this in the docs. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants