Setting relative weight factors in a AnyStdJoint

AnyParamFun

Hi,

I try to make a AnyStdJoint as a soft-type constraint.

Here is an example:

AnyStdJoint LeftHandJoint=
{
        AnyRefNode &ref1= Main.Model.EnvironmentModel.Segs.LeftHandle.LeftHandleNode;
        AnyRefNode &ref2= Main.Model.SWHumanRefNodes.refLeftGlove.SWLeftPalmNode;
        Constraints.CType={Soft,Soft,Soft,Soft,Soft,Soft};
        Constraints.WeightFun = {1.0, 1.0, 1.0, 0.7, 0.7, 0.7};
};

But this code invoked errors. I guess that the code about setting the weight factors may be wrong.

I searched the AnyBody reference document. Then I found that I have to use AnyParamFun object.

So would you please show an example about how to use AnyParamFun for constant weight factors?

Best regards and thanks in advance,
Moonki

Hi Moonki,
something like this should work:
AnyFunConst W1 = {Value ={1,1,1,1,0.7,0.7};};

and inside the Joint:
Constraints.WeightFun = {&…W1};
Best regards,
Sebastian

Hi Sebastian,

It works very well! Thank you very much!

Best regards,
Moonki

Hello,

For a soft constrained 1DoF knee joint (AnyRevoluteJoint) I would like to use a weight on the other two rotational DoF that depends on the actual deformation in a non linear way (e.g. scale the weight exponentially with the constraint violation (for the code, see below).

However, i get the problem that I can only calculate this weight until moment 'PosVar’. I’ve tried many things using if statements and such, to make sure that I will not use a kinematic measure before the initialisation is finished and actual kinematics starts. For example using an if statement (iffun) where t is compared to tStart, and thus the relative weight is only calculated when the kinematics are running (when t > tStart). But as soon as I link the cost function value in some way to the kinematics, I get the same problem:

…/Jnt.any : ‘Value’ : Expression evaluation failed at moment ‘DesignVar’ :
…\Jnt.any(48) : Weigth : argument will not be ready for evaluation until moment ‘PosVar’

Now I noticed ‘Value’ is a ‘DesignVar’, does this mean it should be a constant and what I’m trying to do is not possible? If not, could you help me solve this problem.

Thanks in advance and kind regards,

Bart Koning

Code for adaptation ofthe knee joint taken from the GaitLowerExtremity AMMRV1.2 repository model (AnyBody version : 4.2.1.1614):

AnyRevoluteJoint Knee = {
Axis = z;
AnyRefNode &ThighNode = …Seg.Thigh.KneeJoint;
AnyRefNode &ShankNode = …Seg.Shank.KneeJoint;

Constraints.CType = {Hard,Hard,Hard,Soft,Soft};
Constraints.WeightFun= {&JointSoftContraint2};

AnyFunConst JointSoftContraint2 = {

  AnyFloat Weigth = exp(.Constraints.Pos[4]);
   Value = {1,1,1,Weigth ,0.7};
 };

}; // End of knee

Hi Moonki,

Please see this small example on how to do this:

Main = {

AnyFolder MyModel = {

AnyFixedRefFrame GlobalRef = { };  // Global reference frame

AnySeg Mass={
  Mass=0;
  Jii={0,0,0};
};


AnyFunConst WeightFun ={Value = {1.0, 1.0, 1.0, 0.7, 0.7, 0.7};};

AnyStdJoint Joint={
  AnyFixedRefFrame &ref1=.GlobalRef;
  AnySeg &ref2=.Mass;
  Constraints.CType={Soft,Soft,Soft,Soft,Soft,Soft};
  Constraints.WeightFun ={&.WeightFun};
};

}; // MyModel

AnyBodyStudy MyStudy = {
InitialConditions.SolverType = KinSolOverDeterminate;
Kinematics.SolverType = KinSolOverDeterminate;
AnyFolder &Model = .MyModel;
Gravity = {0.0, -9.81, 0.0};
};

}; // Main

If you have any questions please ask again.

Best regards
Søren

Hi Moonki,

Please disregards last posting by mistake i answer your first posting:)

Basically you are trying to make the kinematics solution depend on the results of a kinematic analysis… this is not possible

The kinematic constraint violation in not known until the kinematics has been resolved so you can not use a constraint violation as a weight in any way since it is not known at that point.

i am not sure if it fits your setup but you may run the one model first and dump out the constraint violations then you could use these as a weights as a function of time, would this be useful?

Best regards
Søren

Hi Søren,

Thank you for your quick reply!

It is a possibility, but I presume the contraint I want to impose will influence the simulation a lot. So in that case I would need to do multiple iterative simulations to get to the final solution.

Isn’t there the possibility to use the previous time step contraint violation in the weighting funtion. This does still means the costfunction ‘Value’ can be treated as a variable, but it is a variable that is known at the time it is calculated (except for t = 0 off course).

Kind regards,

Bart

Hi Bart!

What you are trying to do is not possible in AnyScript. What you are trying to do is to use an AnyScript expression to construct a time-varying weight. If we were only interested in doing position analysis, this would be possible, but since we also need to be able to do velocity and acceleration analysis, the system must also know the first and second time-derivatives of the weights (i.e. they must be differentiable). These are not available for AnyScript expressions. Right now, you can only use parameter functions (AnyParamFun) as weights as for these, we have implemented the time-derivatives.

Could you please explain a little more about what you are trying to achieve with this setup? There may be other ways of doing something similar.

Best regards
Michael Skipper Andersen
The AnyBody Research Project

Hi,

First, what am I trying to do:
I am comparing the motion obtained from AnyBody and an inertial motion capturing system. There are some typical differences, of which some I contribute to joint constraint implementation; in the inertial motion capture device both ankle and knee are ball socket joints with a soft constraint (or penalty) for non flexion deformation that increases (e.g. exponentially) with this non flexion angle. To identify which differences in predicted motion arise from the joint constraint implementation, I am now trying to apply the same constraints in AnyBody.

If I understand it correctly, the first and second derivative of the weight function values are used to weight the velocity and acceleration of the constraint violation as well and they are access denied members. And because they are access denied, I cannot make them dependant of the kinematics themselves, right? But if they are Optional-Initialization Members, would this mean I could define them myself from previous time steps?

I must say that I am not sure if I fully understand the motion optimisation, so it could be that I am missing something here that makes my whole strategy impossible. If so, just tell me to study your (Michael Skipper Andersen) PhD thesis in more detail ;).

I hope this gives enough information to answer your questions about my goal(s) and that there is any way you could help me.

Kind regards,

Bart Koning

Hi Bart!

The short answer is that what you are trying to do is not currently possible in AnyBody for a couple of reasons. 1) Weight functions cannot depend on kinematics, only as pure functions of time (not the system coordinates). 2) We do not currently have any other options to combine multiple measures into one than the linear and norm combination measures. However, neither of these can produce what you want. It may be possible to produce something similar using multiple linear and norm combination measures, but it is probably going to be tricky to implement.

How wrong do you think it would be to simply introduce a high constant weight for the out of plane joint angles (introduced in the optimization problem as soft constraints) such that you obtain a solution where these joint angles are low? I.e. a linear pernalty of these joint angles. This you can implement with the current facilities.

I apologize for the inconvenience.

Best regards
Michael Skipper Andersen
The AnyBody Research Project

Hi,

Thanks again for the quick reply.

To answer your question, I’ve actually applied different linear weights (ranging from 0.1 to 1) and neither gives similar results to the kinematics from the inertial motion system. It seems that even a weight of 0.1 in AnyBody is too low, which is expected if you compare it to a exponential weight; where penalties are minimal for low constraint violations.

In two weeks there will be a meeting in Nijmegen for the TLEMsafe project, in which I am slightly evolved as the room mate of the two Twente PhD students and attendant to weekly musculoskeletal modelling meetings. After deliberation with my supervisor (Koopman), we thought that I could attend this meeting as well to discuss this topic with the representatives of AnyBody (Søren?). Is that all right?

Kind regards,

Bart Koning

Hi Bart,

Sure no problem.

Best regards
Søren