Java Exception error when adding a force
Posted: 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)
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');