[592feb]: / MATLAB_tool / MuscleParOptTool / private / getIndipCoordAndJoint.m

Download this file

69 lines (58 with data), 3.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
%-------------------------------------------------------------------------%
% Copyright (c) 2019 Modenese L., Ceseracciu, E., Reggiani M., Lloyd, D.G.%
% %
% Licensed under the Apache License, Version 2.0 (the "License"); %
% you may not use this file except in compliance with the License. %
% You may obtain a copy of the License at %
% http://www.apache.org/licenses/LICENSE-2.0. %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or %
% implied. See the License for the specific language governing %
% permissions and limitations under the License. %
% %
% Author: Luca Modenese, August 2014 %
% email: l.modenese@imperial.ac.uk %
% ----------------------------------------------------------------------- %
%
% Function that given a dependent coordinate finds the independent
% coordinate and the associated joint. The function assumes that the
% constraint is a CoordinateCoupleConstraint as used by Arnold, Delp and
% LLLM. The function can be useful to manage the patellar joint for instance.
function [ind_coord_name, ind_coord_joint_name] = getIndipCoordAndJoint(osimModel, constraint_coord_name)
% importing OpenSim libraries
import org.opensim.modeling.*
% init state
s = osimModel.initSystem;
% get coordinate
constraint_coord = osimModel.getCoordinateSet.get(constraint_coord_name);
% double check: if not constrained then function returns
if ~(constraint_coord.isConstrained(s))
display([char(constraint_coord.getName),' is not a constrained coordinate.'])
return
end
% otherwise search through the constraints
for n = 0:osimModel.getConstraintSet.getSize-1
% get current constraint
curr_constr = osimModel.getConstraintSet.get(n);
% this function assumes that the constraint will be a coordinate
% coupler contraint ( Arnold's model and LLLM uses this)
% cast down constraint
curr_constr_casted = CoordinateCouplerConstraint.safeDownCast(curr_constr);
% get dep coordinate and check if it is the coord of interest
dep_coord_name = char(curr_constr_casted.getDependentCoordinateName());
if strncmp(constraint_coord_name,dep_coord_name,length(constraint_coord_name))
% if curr_constr_casted.getIndependentCoordinateNames().getSize
ind_coord_name_set = curr_constr_casted.getIndependentCoordinateNames();
% extract independent coordinate and independent joint to which the
% coordinate refers
if ind_coord_name_set.getSize==1
ind_coord_name = curr_constr_casted.getIndependentCoordinateNames().get(0);
ind_coord_joint_name = osimModel.getCoordinateSet.get(ind_coord_name).getJoint.getName;
return
elseif ind_coord_name_set.getSize>1
error('getIndipCoordAndJoint.m. The CoordinateCouplerConstraint has more than one indipendent coordinate and this is not managed by this function yet.')
end
end
end