Point Kinematic Analysis isEqualTo
Posted: Thu Oct 14, 2021 6:56 am
Hi all,
I am using OpenSim 4.3 and MatLab to try and write a snipit of code that will detect if an analysis is a point kinematics analysis and if so to then extract the first and last state vector.
To do this I am using the isEqualTo() command, and if that returns true to then get the desired state vectors.
However after running a forward dynamics simulation the isEqualTo() command always returns false when querying if an analysis is a point kinematics.
I have put an example of the code below.
If after the forward simulation I mannual assign the which Analysis to get it returns the first and last state vectors, so the point kinematic analysis is still there and working as it should so it seems to be strickly related to the isEqualTo() command. It seems to be related to running the forward dynamics simulation as the isEqualTo() command returns true for the Point Kinematics when applied with the same implmentation before running the forward dynamics simulations (so I dont ask for the state vectors).
Although I can achieve the same result with a minor modification to the implmentation using getConcreteClassName(), I'm curious to understand where I have gone wrong/why the isEqualTo() does not work here
Thanks,
Samuele
I am using OpenSim 4.3 and MatLab to try and write a snipit of code that will detect if an analysis is a point kinematics analysis and if so to then extract the first and last state vector.
To do this I am using the isEqualTo() command, and if that returns true to then get the desired state vectors.
However after running a forward dynamics simulation the isEqualTo() command always returns false when querying if an analysis is a point kinematics.
I have put an example of the code below.
Code: Select all
% Creation of model and forward tool (not included for brevity)
% Add point kinematics analysis to model
pk1 = PointKinematics();
myModel.addAnalysis(pk1);
pk1.setInDegrees(1)
pk1.setBody(myModel.getBodySet.get(1));
pk1.setRelativeToBody(myModel.getGround)
pk1.setPointName('PointKinematics_1')
pk1.setPoint(Vec3(1, 1, 1));
%
% --------------------------- Run simulation ---------------------------- %
%
myModel.initSystem();
FDTool.run();
% ------------------- Get first and last state vector ------------------ %
% Get number of analysis
NumAnalysis = myModel.getAnalysisSet().getSize();
PointTranslations = cell(NumAnalysis,2);
% Get first and last state vector of all the point analysis
% Run through all the analysis that are present in model
for ii = 1:NumAnalysis
% Check if model is a PointKinematics
if myModel.getAnalysisSet().get(ii-1).isEqualTo(PointKinematics())
% get name of point
PointTranslations{ii,1} = PointKinematics.safeDownCast(myModel.getAnalysisSet().get(ii-1)).getPointName();
% get storage data
PointPos = PointKinematics.safeDownCast(myModel.getAnalysisSet().get(ii-1)).getPositionStorage();
% Get initial position
PointTranslations{ii,2}(1,:)=osimVec3ToArray(PointPos.getStateVector(0).getData().getAsVec3());
% Get final position
PointTranslations{ii,2}(2,:)=osimVec3ToArray(PointPos.getLastStateVector().getData().getAsVec3());
end
end
Although I can achieve the same result with a minor modification to the implmentation using getConcreteClassName(), I'm curious to understand where I have gone wrong/why the isEqualTo() does not work here
Thanks,
Samuele