Constraints violated when computing state derivatives

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Adrian Lai
Posts: 46
Joined: Tue Mar 13, 2012 11:33 am

Re: Constraints violated when computing state derivatives

Post by Adrian Lai » Thu Jan 11, 2018 2:44 pm

Perfect! Thanks for the great explanation Chris.

I'll try it now and let you know if it works.

Adrian

User avatar
Ross Miller
Posts: 373
Joined: Tue Sep 22, 2009 2:02 pm

Re: Constraints violated when computing state derivatives

Post by Ross Miller » Thu Jan 11, 2018 3:38 pm

chrisdembia wrote:I think solving direct collocation with musculoskeletal systems that contain kinematic constraints would be a fairly novel contribution to the field, so I'm not sure we know yet how to do this well (correct me if I am wrong, Ross).
This would be novel to my knowledge, at least in biomechanics, and would make a nice technical paper. I don't have a vast knowledge of the DC literature outside of biomechanics and a bit of the robotics work. Ton may know better if he sees this thread.

I briefly tried running DC simulations of walking using a very-high-dimensional model [it had 49 DoF =O] using MotionGenesis and IPOPT, with the thought that I could then just "lock" the DoF I didn't want for a particular use case using equality constraints and would only ever need one model. It did not work well unfortunately (IPOPT wouldn't converge) and I gave up quickly. I should try again sometime.

User avatar
Adrian Lai
Posts: 46
Joined: Tue Mar 13, 2012 11:33 am

Re: Constraints violated when computing state derivatives

Post by Adrian Lai » Fri Jan 12, 2018 1:27 pm

Hi Chris and Ross,

I was able to call getQErr and get the model constraint errors for the location and orientations specified in the constraint set I set in the model file. I've added them as path constraints but it does add a considerable amount of extra path constraints to the optimisation (no. of model constraints * no. of collocation nodes), which I guess is inevitable.

However, now my DC doesn't converge because it doesn't seem to be able to reduce these new model constraints. My other path constraints are all lower than the tolerance I set 1e-6.

Any ideas?

Thanks!

Adrian

User avatar
Ross Miller
Posts: 373
Joined: Tue Sep 22, 2009 2:02 pm

Re: Constraints violated when computing state derivatives

Post by Ross Miller » Fri Jan 12, 2018 4:13 pm

IPOPT handles large numbers of constraints well in my experience. Actually sometimes it seems to work better (converges more consistently) with more constraints, as long as the initial guess doesn't have large constraint violations.

The first thing that comes to mind is maybe you need to scale the new constraints. For example if a constraint is something like:

Q1 - Q2 = 0

and Q1 and Q2 have units of meters in the problem, 1e-6 meters is a very small tolerance (1/1000th of a millimeter) and maybe the model can't meet that.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Constraints violated when computing state derivatives

Post by Christopher Dembia » Fri Jan 12, 2018 6:08 pm

Related to Ross' comment, I think you could safely loosen the tolerance.

I suggest you first try a simple problem, perhaps a point mass with a constant distance constraint, which gives you a pendulum.

User avatar
Adrian Lai
Posts: 46
Joined: Tue Mar 13, 2012 11:33 am

Re: Constraints violated when computing state derivatives

Post by Adrian Lai » Tue Jan 16, 2018 9:19 pm

Just an update. My problem hasn't converged yet but I've fixed my constraints. I forgot to reformulate and recalculate my approximations in my Jacobian for the new constraints. It hasn't converged yet but I don't get errors when I perform the derivative check via IPOPT.

I have another somewhat related question. I realised today that my problem is no longer a closed loop but rather an open loop problem with a kinematic constraint. So previously, I only had 1 DOF (e.g. crank rotation) and all I needed to solve for was the crank angle and all the corresponding muscle forces to account for reaction forces. But now I have to solve for all the DOFs to achieve possibly the same result but takes considerably longer. I was just wondering if anyone had any other ideas of how to close the model loop without using a constraint and/or if there might be another way to ensure the constraints are met before I compute the state derivatives.

Thanks for your help!

Adrian

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Constraints violated when computing state derivatives

Post by Christopher Dembia » Tue Jan 16, 2018 10:11 pm

The only way to close a loop is with a constraint. In 4.0, even if you do not have any constraints in your model, OpenSim adds in a loop closure constraint for you.

It's great that you got the derivatives to be correct; sounds like more than half the battle :)

User avatar
Irina Wils
Posts: 11
Joined: Sun Jun 30, 2019 1:02 am

Re: Constraints violated when computing state derivatives

Post by Irina Wils » Mon Apr 06, 2020 4:47 am

mitkof6 wrote:
Thu Jan 04, 2018 12:25 am
Hi,

Do you perform Forward Dynamics or Inverse? OpenSim ignores constraints during Inverse Dynamics. Also make sure that the initial state is consistent with the constraints.

Best
Hi,

I am currently working on a jaw model. I defined it as the skull with two children, namely the left and right part of the mandible and then a weld constraint in between them. When doing the Inverse Dynamics I indeed saw that the constraint is ignored. Do you have any suggestion how to solve this problem?

Thanks in advance
Irina

POST REPLY