Java Exception error when adding a force

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Yong Cho
Posts: 27
Joined: Wed Sep 21, 2016 4:45 pm

Java Exception error when adding a force

Post by Yong Cho » Tue Jul 11, 2017 6:18 am

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');

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Java Exception error when adding a force

Post by jimmy d » Tue Jul 11, 2017 6:38 am

Are you using the 3.3 or 4.0 (Beta) API?

User avatar
Yong Cho
Posts: 27
Joined: Wed Sep 21, 2016 4:45 pm

Re: Java Exception error when adding a force

Post by Yong Cho » Tue Jul 11, 2017 6:40 am

3.3

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Java Exception error when adding a force

Post by jimmy d » Tue Jul 11, 2017 6:53 am

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.

User avatar
Yong Cho
Posts: 27
Joined: Wed Sep 21, 2016 4:45 pm

Re: Java Exception error when adding a force

Post by Yong Cho » Tue Jul 11, 2017 7:18 am

I see, thank you!

POST REPLY