Adding a force through matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
shayan moradkhani
Posts: 41
Joined: Fri May 05, 2017 5:12 pm

Re: Adding a force through matlab

Post by shayan moradkhani » Thu Jun 29, 2017 5:06 am

tkuchida wrote:
I am just trying to learn how to modulate opensim by using Matlab since I am new to this.
There might be some helpful information on the "Scripting with Matlab" page in the documentation (http://simtk-confluence.stanford.edu:80 ... ith+Matlab).
I am trying to find a way to a add a force to the r_humerus of the model arm26.osim in the (1,0,0) direction.
Thank you for clarifying. The class you're looking for is OpenSim::PrescribedForce (https://simtk.org/api_docs/opensim/api_ ... Force.html). Here's a code snippet:

Code: Select all

import org.opensim.modeling.*

model = Model('arm26.osim');
body  = model.getBodySet().get('r_humerus');

force = PrescribedForce('myForce', body);
force.setForceFunctions(Constant(1), Constant(0), Constant(0));
model.addForce(force);

model.print('arm26_withPrescribedForce.osim');
when i apply the same code (of course after modifying it) i get : "No constructor 'org.opensim.modeling.PrescribedForce' with matching signature found."
here is my code:
%% Reset
clear all; close all; clc

%% Import
import org.opensim.modeling.*;

%% Open a Model by name
foot1 = Model('C:\OpenSim 3.3\Models/foot1.osim');

%% Use the visualizer (must be done before the call to init system)
foot1.setUseVisualizer(true);

%% Getting the body

foot = foot1.getBodySet().get('foot');

%% Prescribedforce

force=PrescribedForce('forceonfoot',foot);


regards
Shayan

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Adding a force through matlab

Post by Thomas Uchida » Thu Jun 29, 2017 5:24 am

That code snippet was written in OpenSim 4.0. The 3.3 doxygen can be found here: https://simtk.org/api_docs/opensim/api_ ... Force.html; here's the analogous code in 3.3:

Code: Select all

import org.opensim.modeling.*

model = Model('arm26.osim');
body  = model.getBodySet().get('r_humerus');

force = PrescribedForce(body);
force.setName('myForce');
force.setForceFunctions(Constant(1), Constant(0), Constant(0));
model.addForce(force);

model.print('arm26_withPrescribedForce.osim');
You just need to change force = PrescribedForce('myForce', body); to force = PrescribedForce(body); force.setName('myForce');. The "No constructor 'org.opensim.modeling.PrescribedForce' with matching signature found" error message means there is no PrescribedForce constructor that takes the arguments you have provided.

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

Re: Adding a force through matlab

Post by Yong Cho » Thu Jun 29, 2017 7:43 am

I have two areas of confusion in the code. First, what exactly is 'myForce' of the code force = PrescribedForce('myForce', body); and what am I supposed to write in that area? Secondly, how do you determine the location of where the force is acting at. Are we assuming that the added prescribed force is acting on the center of mass of the body? I'm not sure if this will help, but I am as of now trying to do static optimization. Thank you for all your help.

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

Re: Adding a force through matlab

Post by jimmy d » Thu Jun 29, 2017 8:40 am

First, what exactly is 'myForce' of the code force = PrescribedForce('myForce', body); and what am I supposed to write in that area?
In OpenSim 4.0 (in alpha development), one of the PrescribedForce constructors takes a String and a Body (object). 'MyForce' is the name that is given to the instantiated PrescribedForce object. It is just a string.

This is not the same in OpenSim 3.3 which just takes a body in the constructor; https://simtk.org/api_docs/opensim/api_ ... Force.html
Secondly, how do you determine the location of where the force is acting at. Are we assuming that the added prescribed force is acting on the center of mass of the body?
You can change the force, point of application, and torque. Please see the documentation;https://simtk.org/api_docs/opensim/api_ ... Force.html

User avatar
Srihari A
Posts: 3
Joined: Sun Jun 16, 2019 11:38 pm

Adding a force using notepad

Post by Srihari A » Sun Jun 30, 2019 10:54 pm

Hi Thomas!

I want to add a prescribed force of 100 N on the femur. But I am not using Matlab. I opened the .osim model on Notepad and I am changing the code. I am attaching the screenshot of the code which I've opened on Notepad.

My question is , how do I add a prescribed force within this code?
Attachments
Capture.JPG
Capture.JPG (221.5 KiB) Viewed 264 times

POST REPLY