Page 1 of 1

Java Exception error when adding a force

Posted: Tue Jul 11, 2017 6:18 am
by ync8yy
Hello, I am trying to add a force to a certain part of a arm however, I am getting this error below when I try to use the code "model.addForce(force)". The code I have for now is below the error. What am I doing wrong?

Error using arm26Force (line 24)
Java exception occurred:
java.lang.RuntimeException: ModelComponent: Cannot include subcomponent after addToSystem().

at org.opensim.modeling.opensimModelJNI.Model_private_addForce(Native Method)

at org.opensim.modeling.Model.private_addForce(Model.java:291)

at org.opensim.modeling.Model.addForce(Model.java:88)

Code: Select all

import org.opensim.modeling.*

model = Model('C:\Users\Yong Cho\Documents\OpenSim 3.3\Models\Arm26\arm26.osim');
cSet = model.getCoordinateSet()
initState = model.initSystem()

r_shoulder_elevation = cSet.get(0)
r_elbow_flex = cSet.get(1)

r_shoulder_elevation.setDefaultLocked(1)
r_elbow_flex.setDefaultLocked(1)


body  = model.getBodySet().get('r_ulna_radius_hand');
force = PrescribedForce(body);

force.setForceFunctions(Constant(15), Constant(0), Constant(0));
force.setPointFunctions(Constant(0), Constant(-0.180496), Constant(0))


force.setPointIsInGlobalFrame(0);
force.setForceIsInGlobalFrame(0);

model.addForce(force)  % line 24 where the error happens

model.print('C:\Users\Yong Cho\Documents\OSFolder\arm26e2PrescribedForce1.osim');

Re: Java Exception error when adding a force

Posted: Tue Jul 11, 2017 6:38 am
by jimmy
Are you using the 3.3 or 4.0 (Beta) API?

Re: Java Exception error when adding a force

Posted: Tue Jul 11, 2017 6:40 am
by ync8yy
3.3

Re: Java Exception error when adding a force

Posted: Tue Jul 11, 2017 6:53 am
by jimmy

Code: Select all

Java exception occurred:
java.lang.RuntimeException: ModelComponent: Cannot include subcomponent after
addToSystem().

	at org.opensim.modeling.opensimModelJNI.Model_private_addForce(Native
    Method)

	at org.opensim.modeling.Model.private_addForce(Model.java:291)

	at org.opensim.modeling.Model.addForce(Model.java:88)

ModelComponent: Cannot include subcomponent after addToSystem().
initSystem() invokes addToSystem(); you can't add components once this is invoked. You are trying to add a component to the model after you have built the system.

To fix, just put initSystem() in after you have added all the things you want to add to the model.

Re: Java Exception error when adding a force

Posted: Tue Jul 11, 2017 7:18 am
by ync8yy
I see, thank you!