SOLVED -- Closed Kinematic Chain: MoCo Solver Initialization Error

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Tyler Morrison
Posts: 9
Joined: Wed Nov 06, 2019 7:00 am

SOLVED -- Closed Kinematic Chain: MoCo Solver Initialization Error

Post by Tyler Morrison » Sun Oct 18, 2020 3:11 pm

I'm wondering if anyone has experience with this error and can guide me to resolve it. This is sort of the simplest version of the problem that I am encountering.

Let's say that I want to build a four-bar linkage in OpenSim and solve a minimum effort point-to-point movement (torque actuator on one joint, goal to move from initial to position to final position).

I have built the OSIM model in a MATLAB script. No issues there. I can open it in the OpenSim GUI and simulate forward dynamics to see that everything is working.

Now I want to build a MoCo problem to solve the minimum effort optimal control problem. I import the OSIM model, use a ModelProcessor to add it to the problem (just like in example2DWalking.m), and finish setting up the problem. However, when I initialize the solver (either CasADI or Tropter) I get the following error message:

Error using FourBarP2P (line 44)
Java exception occurred:
java.lang.RuntimeException: Component 'linkC_slave_0_weld' of type WeldConstraint has no owner and is not the root.
Verify that finalizeFromProperties() has been invoked on the root Component or that this Component is not a clone, which has
not been added to another Component.
Thrown at Component.cpp:1681 in initComponentTreeTraversal().

at org.opensim.modeling.opensimMocoJNI.MocoStudy_initTropterSolver(Native Method)

at org.opensim.modeling.MocoStudy.initTropterSolver(MocoStudy.java:117)


However, if I run

Code: Select all

c = model.findComponent('linkC_slave_0_weld');
c.hasOwner()
I get 'true'. Which doesn't match what the error message is telling me.

If I break the kinematic loop by building the same model without one of the joints in the linkage (no longer a closed chain linkage), I do not get the error. Instead I get a one single pendulum and one double pendulum and the problem is solved for a trivial solution with no issues.

Is there a step that I am missing in the process for a model that has a closed kinematic chain? Is it possible this is a bug? I can provide the model file, and MATLAB script to anyone interested.
Last edited by Tyler Morrison on Wed Oct 21, 2020 5:35 pm, edited 1 time in total.

User avatar
Nicholas Bianco
Posts: 1057
Joined: Thu Oct 04, 2012 8:09 pm

Re: Closed Kinematic Chain: MoCo Solver Initialization Error

Post by Nicholas Bianco » Tue Oct 20, 2020 4:43 pm

Hi Tyler,

I'm not sure exactly what's going wrong. Are you building the model programmatically? Sending the model file could be helpful here.

Best,
-Nick

User avatar
Tyler Morrison
Posts: 9
Joined: Wed Nov 06, 2019 7:00 am

Re: Closed Kinematic Chain: MoCo Solver Initialization Error

Post by Tyler Morrison » Tue Oct 20, 2020 5:03 pm

Yes, I am building the model programmatically. It's a simpler test case of something I am working on. I have attached a ZIP file which contains the OSIM file, an M file for building that OSIM file, and an M file for the MoCo problem.
FourBarLinkage.zip
(4.14 KiB) Downloaded 12 times
I'm most suspicious that there is a simple additional step that I should be doing to resolve the constraints that close the mechanism loop before initializing the solver, but I haven't been able to figure that out yet.

Thanks for your interest Nick! This project is fantastic.
-Tyler

User avatar
Nicholas Bianco
Posts: 1057
Joined: Thu Oct 04, 2012 8:09 pm

Re: Closed Kinematic Chain: MoCo Solver Initialization Error

Post by Nicholas Bianco » Wed Oct 21, 2020 10:10 am

Thanks for sending the files. (And for the clean code, made this easy to debug.)

After looking through them for a bit, I think I've found our problem. You're trying to create a four-bar linkage using only OpenSim Joints, but OpenSim doesn't allow closed kinematic chains without using constraints. Instead of a WeldJoint, you should use a WeldConstraint. The WeldConstraint is showing up in the error message I think because internally OpenSim tries to resolve the kinematic loop by replacing the joint with a constraint. But if you start with constraint when building the model, you can avoid that issue.

Let me know if you need help figuring out how to add the WeldConstraint.

Best,
-Nick

User avatar
Tyler Morrison
Posts: 9
Joined: Wed Nov 06, 2019 7:00 am

Re: Closed Kinematic Chain: MoCo Solver Initialization Error

Post by Tyler Morrison » Wed Oct 21, 2020 5:34 pm

Thank you for the suggestion! That did the trick. I don't know if the way I did it is the best way to do it, but basically I just created a ground link and attached that to one side of the mechanism, and then another ground link and attached that to the other side. Then I used WeldConstraint to close the kinematic loop.

After doing this, the problem solved relatively easily even for a poor initial guess.

For anyone interested in this thread, I have attached the final -- working -- OSIM model, model builder script, and MoCo problem script.

This seems like a relatively basic piece of OpenSim knowledge I should have figured out on my own. These OpenSim workshop slides that I just found and should have looked at earlier show exactly what Nick said about closing the loop with constraints on Slide #8:
https://simtk-confluence.stanford.edu:8 ... 924&api=v2
Attachments
FourBarLinkage.zip
(5.84 KiB) Downloaded 22 times

POST REPLY