Adding Prescribed Force to my model

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
In Bae Chung
Posts: 19
Joined: Mon Jan 14, 2019 11:46 pm

Adding Prescribed Force to my model

Post by In Bae Chung » Mon Sep 23, 2019 10:24 pm

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.

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Adding Prescribed Force to my model

Post by Dimitar Stanev » Tue Sep 24, 2019 12:26 am

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

User avatar
In Bae Chung
Posts: 19
Joined: Mon Jan 14, 2019 11:46 pm

Re: Adding Prescribed Force to my model

Post by In Bae Chung » Tue Sep 24, 2019 1:24 am

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 536 times
I wonder if there are any examples of .osim files that has Prescribed Force working correctly?

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Adding Prescribed Force to my model

Post by Dimitar Stanev » Tue Sep 24, 2019 6:18 am

Maybe it is not enclosed in the ForceSet correctly:

Code: Select all

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

User avatar
In Bae Chung
Posts: 19
Joined: Mon Jan 14, 2019 11:46 pm

Re: Adding Prescribed Force to my model

Post by In Bae Chung » Wed Sep 25, 2019 12:24 am

Thank you for the tip.
error.JPG
error.JPG (37.02 KiB) Viewed 504 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>


User avatar
Charles David Sasportes
Posts: 15
Joined: Thu Jan 23, 2020 6:36 am

Re: Adding Prescribed Force to my model

Post by Charles David Sasportes » Wed Feb 26, 2020 2:53 am

This code should work if you remove the <function> and </function> around the constants as they are not recognized as objects by the software.

POST REPLY