Page 1 of 1

Adding Prescribed Force to my model

Posted: Mon Sep 23, 2019 10:24 pm
by inbae908
Hi all,

I have a fullbody model in OpenSIM and have a .mot file of the model raising its arm.
I wanted to implement the motion with force attached to the model's hand in the -y direction so that it can be seen as the model is lifting a heavy object. I figured out that PrescribedForce can be a solution to this and added the following code under ForceSet in my .osim file.

Code: Select all

		
    <!--Forces in the model (includes Actuators).-->
    <ForceSet name="forceset">
    <PrescribedForce name="prescribedF">
      <!--Flag indicating whether the force is disabled or not. Disabled means that the force is not active in subsequent dynamics realizations.-->
      <isDisabled>false</isDisabled>
      <!--Name of the body the force is applied to.-->
      <body>hand_r</body>
      <!--Flag indicating whether the point (specified in pointFunctions) is in global frame.-->
      <pointIsGlobal>false</pointIsGlobal>
      <!--Flag indicating whether the quantities (specified in force/torqueFunctions) is in global frame.-->
      <forceIsGlobal>true</forceIsGlobal>
      <!--Three functions describing the force to be applied.-->
      <FunctionSet name="forceFunctions">
        <forceFunctions>
          <function>
            <Constant name="forceX">
              <value>0</value>
            </Constant>
          </function>
          <function>
            <Constant name="forceY">
              <value>-100</value>
            </Constant>
          </function>
          <function>
            <Constant name="forceZ">
              <value>0</value>
            </Constant>
          </function>
        </forceFunctions>
      </FunctionSet>
      <!--Three functions describing the location at which the force is applied.-->
      <FunctionSet name="pointFunctions">
        <pointFunctions>
          <function>
            <Constant name="pointX">
              <value>0</value>
            </Constant>
          </function>
          <function>
            <Constant name="pointY">
              <value>0</value>
            </Constant>
          </function>
          <function>
            <Constant name="pointZ">
              <value>0</value>
            </Constant>
          </function>
        </pointFunctions>
      </FunctionSet>
    </PrescribedForce>
The code seems to be right, but there's no difference in the results. I've checked the ForceReporter in the Analyze Tool and tried plotting the joint moment of the motion with/without the Prescribed Force, but the results are same. Can someone help me in successfully applying Prescribed Force? Thank you in advance.

Re: Adding Prescribed Force to my model

Posted: Tue Sep 24, 2019 12:26 am
by mitkof6
Can you see the force in the model's navigation tab? Does the model load correctly?

You can also attach a body on the hand with variable inertia and mass properties, using a WeldJoint.

Examples: https://github.com/opensim-org/opensim- ... ribedForce

Re: Adding Prescribed Force to my model

Posted: Tue Sep 24, 2019 1:24 am
by inbae908
Thank you for your reply.

I guess I can try using a WeldJoint as a second option in case Prescribed Force doesn't work.
Currently, the model loads without error in OpenSIM, but I cannot see the force in the model's navigation tab.
navigationtab.JPG
navigationtab.JPG (24.96 KiB) Viewed 884 times
I wonder if there are any examples of .osim files that has Prescribed Force working correctly?

Re: Adding Prescribed Force to my model

Posted: Tue Sep 24, 2019 6:18 am
by mitkof6
Maybe it is not enclosed in the ForceSet correctly:

Code: Select all

<ForceSet name="forceset">
    <objects>
    ...Add force set here.
    </objects>
    <groups />
</ForceSet>

Re: Adding Prescribed Force to my model

Posted: Wed Sep 25, 2019 12:24 am
by inbae908
Thank you for the tip.
error.JPG
error.JPG (37.02 KiB) Viewed 852 times
The error above kept showing up, and I managed to solve it by substituting

Code: Select all

<body>../../bodyset/hand_r </body>
with

Code: Select all

<socket_frame>../../bodyset/hand_r</socket_frame>
Now I can find 'prescribedForce' in the Navigator tab, but can't visualize it. Again, I checked the ForceReporter and tried plotting the joint moment of the motion, but there wasn't any difference even after I added the PrescribedForce. Is there something that can be done to have the PrescribedForce in effect? Below is the part in my .osim file where I added the PrescribedForce code.

Code: Select all


<ForceSet name="forceset">
	<objects>
		<PrescribedForce name="prescribedForce">
			<isDisabled>false</isDisabled>
			<socket_frame>../../bodyset/hand_r</socket_frame>
			<FunctionSet name="forceFunctions">
				<objects>
              				<function>
                					<Constant name="forceX">
                  						<value>0</value>
                					</Constant>
              				</function>
              				<function>
                					<Constant name="forceY">
                  						<value>-10000</value>
                					</Constant>
              				</function>
              				<function>
                					<Constant name="forceZ">
                  						<value>0</value>
                					</Constant>
              				</function>
				</objects>
				<groups />
			</FunctionSet>

			<FunctionSet name="pointFunctions">
           				<objects>
           					<function>
           						<Constant name="pointX">
           							<value>0</value>
           						</Constant>
					</function>
              				<function>
                					<Constant name="pointY">
                  						<value>0</value>
                					</Constant>
              				</function>
              				<function>
                					<Constant name="pointZ">
                  						<value>0</value>
                					</Constant>
              				</function>
            			</objects>
            			<groups />
          			</FunctionSet>
		</PrescribedForce>


Re: Adding Prescribed Force to my model

Posted: Wed Feb 26, 2020 2:53 am
by cdsasportes
This code should work if you remove the <function> and </function> around the constants as they are not recognized as objects by the software.