I am a beginner with OpenSim. I have a scaled upper-limb model with a marker set. I wanted to perform some simulations in which I move a particular joint with some prescribed functions, and wanted to get the paths traversed by the different markers over the entire joint movement. How do I go about doing this? Following the forums I have the following, but am not sure if I am doing it right.
Prescribing movement to the shoulder joint
Code: Select all
% get shoulder elevation and elv angle coordinate
elvAngleCoord.setDefaultValue(0.0);
elvAngleCoord.setDefaultIsPrescribed(1);
shoulderElvCoord.setDefaultValue(initialAngle);
shoulderElvCoord.setDefaultIsPrescribed(1);
% create time & joint angle arrays and add points to spline
for i = 1:numSteps
% create time and joint angle array elements
time_temp = (finalTime/numSteps)*i;
time.append(time_temp);
jointAngle_temp = ((finalAngle-initialAngle)/numSteps)*i;
shoulderElvAngle.append(jointAngle_temp);
% add time and joint angle elements to spline
spline.addPoint(time.get(i-1),shoulderElvAngle.get(i-1));
end
% prescribe motion for shoulder elevation
shoulderElvCoord.setPrescribedFunction(spline);
shoulderElvCoord.setDefaultIsPrescribed(1);
Code: Select all
% get marker set
markerSet = model.getMarkerSet();
numMarkers = markerSet.getSize();
% Initializing the model
states = model.initSystem();
% get global coordinates of markers
for i = 1:numMarkers
local_markerPos(i) = markerSet.get(i-1).getOffset();
markerParent(i) = markerSet.get(i-1).getBody();
markerName(i) = markerSet.get(i-1).getName();
model.getSimbodyEngine().getPosition(states,markerParent(i),local_markerPos(i),temp);
global_markerPos.push_back(temp);
end
Any help is appreciated.
With sincere regards,
Rejin
The full code I have right now is as follows:
Code: Select all
% import Opensim classes
import org.opensim.modeling.*
% load model
model = Model(['SSM_Ali_scaled.osim']);
global_markerPos = SimTKArrayVec3();
temp = Vec3();
time = ArrayDouble();
shoulderElvAngle = ArrayDouble();
elvAngle = ArrayDouble();
spline = SimmSpline();
%% Coordinate Set
coordinateSet = model.getCoordinateSet();
numCoordinates = coordinateSet.getSize();
for i = 1:numCoordinates
coordinateNames(i) = coordinateSet.get(i-1).getName();
if strcmp(coordinateNames(i),'elv_angle')
elv_angle_index = i;
end
if strcmp(coordinateNames(i),'shoulder_elv')
shoulder_elv_index = i;
end
end
shoulderElvCoord = coordinateSet.get(shoulder_elv_index-1);
elvAngleCoord = coordinateSet.get(elv_angle_index-1);
%% Movement Set
numSteps = 100;
finalTime = 5;
initialAngle = pi/6;
finalAngle = pi/2;
% get shoulder elevation and elv angle coordinate
elvAngleCoord.setDefaultValue(0.0);
elvAngleCoord.setDefaultIsPrescribed(1);
shoulderElvCoord.setDefaultValue(initialAngle);
shoulderElvCoord.setDefaultIsPrescribed(1);
% create time & joint angle arrays and add points to spline
for i = 1:numSteps
% create time and joint angle array elements
time_temp = (finalTime/numSteps)*i;
time.append(time_temp);
jointAngle_temp = ((finalAngle-initialAngle)/numSteps)*i;
shoulderElvAngle.append(jointAngle_temp);
% add time and joint angle elements to spline
spline.addPoint(time.get(i-1),shoulderElvAngle.get(i-1));
end
% prescribe motion for shoulder elevation
shoulderElvCoord.setPrescribedFunction(spline);
shoulderElvCoord.setDefaultIsPrescribed(1);
%% Marker Set (local and global coordinates)
% get marker set
markerSet = model.getMarkerSet();
numMarkers = markerSet.getSize();
% Initializing the model
states = model.initSystem();
% get global coordinates of markers
for i = 1:numMarkers
local_markerPos(i) = markerSet.get(i-1).getOffset();
markerParent(i) = markerSet.get(i-1).getBody();
markerName(i) = markerSet.get(i-1).getName();
model.getSimbodyEngine().getPosition(states,markerParent(i),local_markerPos(i),temp);
global_markerPos.push_back(temp);
end
%% Create splines based on F,SF,SR & R markers
%% Set up the visualizer to show the model and simulation
model.setUseVisualizer(false);
%% DEFINE SOME PARAMETERS FOR THE SIMULATION
% Define the new tool object which will be run
tool = ForwardTool(); %--> to see all properties which can be set type 'methodsview(tool)'
% Define the model which the forward tool will operate on
tool.setModel(model);
% Define the start and finish times for simulation
tool.setStartTime(0);
tool.setFinalTime(0.1);
tool.setSolveForEquilibrium(true);
% Define the name of the forward analysis
tool.setName('tendonAnalysisModel');
% Run the simulation
tool.run(); %--> rotate the view to see the tug of war simulation