prescribeMotionInModel Question

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Henry Hernandez
Posts: 1
Joined: Thu Jul 09, 2015 3:42 pm

prescribeMotionInModel Question

Post by Henry Hernandez » Wed Jun 29, 2016 9:56 pm

Good Morning;
I have a question, in prescribeMotionInModel.m for matlab in script example, ¿Can I change the "End time", from matlab code?, I tried with this code (See Down), but when the Model generated by matlab is load in Opensim, the "End time" don't change. I have .mot files of different sizes and need change the time in preescriptedModel. ¿Is This possible?

My code is this:

import org.opensim.modeling.*
[Model_In, modelpath] = uigetfile('.osim', 'Please select a model file');
[Mot_In, motpath] = uigetfile('.mot', 'Please select a motion file');
fileoutpath = [Model_In(1:end-5),'_Prescribed.osim'];
modelfilepath = [modelpath Model_In];
motfilepath = [motpath Mot_In];
coordinateSto=Storage(motfilepath);
tool = ForwardTool(); %--> to see all properties which can be set type 'methodsview(tool)'
tool.setModel(osimModel);
tool.setStartTime(0);
tool.setFinalTime(2.5);
tool.run();
osimModel.addController(tool);
osimModel.addAnalysis(tool);
modelCoordSet = osimModel.getCoordinateSet();
nCoords = modelCoordSet.getSize();
for i=0:nCoords-1
Time=ArrayDouble();
coordvalue = ArrayDouble();
currentcoord = modelCoordSet.get(i);
coordinateSto.getTimeColumn(Time);
coordinateSto.getDataColumn(currentcoord.getName(),coordvalue);
motion = currentcoord.getMotionType();
Spline = SimmSpline();
if strcmp(motion,'Rotational')
% if the motion type is rotational we must convert to radians from degrees
for j = 0:coordvalue.getSize()-1
Spline.addPoint(Time.getitem(j),coordvalue.getitem(j)/(180/pi));
end
else % else we assume it's translational and can be left 'as is'
for j = 0:coordvalue.getSize()-1
Spline.addPoint(Time.getitem(j),coordvalue.getitem(j));
end
end
currentcoord.setPrescribedFunction(Spline);
currentcoord.setDefaultIsPrescribed(1);
end
osimModel.print(fileoutpath);
disp(['The new model has been saved at ' fileoutpath]);

Thanks For Alles.

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

Re: prescribeMotionInModel Question

Post by jimmy d » Wed Jul 20, 2016 10:48 am

You don't set time on the model, just the tool. Why would you expect that the model is storing information about an tool/analysis you want to run? You are changing the end time on the tool, not on the model

POST REPLY