|
39 | 39 | coordsModel = osimModel.updCoordinateSet(); |
40 | 40 | N_coordsModel = coordsModel.getSize(); |
41 | 41 |
|
| 42 | +% checking is kinematics matches coordinates order |
| 43 | +[out, missing_coords_list] = isKinMatchingModelCoords(osimModel, kinStruct.colheaders); |
| 44 | + |
| 45 | +% correct if there are generalised coordinates not computed in IK (e.g. |
| 46 | +% models modified after running IK) |
| 47 | +% NB: not tested!! |
| 48 | +if ~out |
| 49 | + for n_m = 1:length(missing_coords_list) |
| 50 | + missing_coords_vals(n_m) = coordsModel.get(coordName).getDefaultValue; |
| 51 | + end |
| 52 | +else |
| 53 | + missing_coords_vals = []; |
| 54 | +end |
| 55 | +% if needed |
| 56 | +% kinStruct.colheader = [kinStruct.colheaders, missing_coords_list]; |
| 57 | + |
| 58 | +% account for time column in data structure |
| 59 | +if any(strcmp('time', kinStruct.colheaders)) |
| 60 | + kin_state_angles = [kinStruct.data(n_frame, 2:end), missing_coords_vals]; |
| 61 | +else |
| 62 | + kin_state_angles = [kinStruct.data(n_frame, :), missing_coords_vals]; |
| 63 | +end |
| 64 | + |
42 | 65 | % looping thought coordinates to assign them a value |
43 | | -for n_StateCoord = 0:N_coordsModel-1 |
44 | | - |
45 | | - %%%%%% updating pose of the model %%%%% |
46 | | - %extracting the column for the state variable of interest |
47 | | - coordName = char(coordsModel.get(n_StateCoord).getName()); |
| 66 | +for n_modelCoords = 0:N_coordsModel-1 |
48 | 67 |
|
49 | | - % check if the coordinates as an equivalent in storage. |
50 | | - CoordInd_in_kinStorage = getMatStructColumn(kinStruct, coordName); |
51 | | - |
52 | | - if isempty(CoordInd_in_kinStorage) |
53 | | - % this is the case when a coordinate is not in the storage file |
54 | | - if n_frame==0 |
55 | | - warndlg([coordName,' not found in storage. Default value will be assigned.']) |
56 | | - end |
57 | | - % assign default value |
58 | | - currentCoordValue = coordsModel.get(coordName).getDefaultValue; |
59 | | - else |
60 | | - coordColumValues = getMatStructColumn(kinStruct, coordName); |
61 | | - % Value of the state variable at that frame |
62 | | - currentCoordValue = coordColumValues(n_frame); |
63 | | - end |
| 68 | + % Value of the state variable at that frame |
| 69 | + cur_coordValue = kin_state_angles(n_modelCoords+1); |
64 | 70 |
|
65 | 71 | % assigning the coordinates depending on their motion type |
66 | | - switch char(coordsModel.get(n_StateCoord).get_motion_type()) |
| 72 | + switch char(coordsModel.get(n_modelCoords).get_motion_type()) |
67 | 73 | case 'rotational' |
68 | 74 | % transform to radiant for angles |
69 | | - coordsModel.get(n_StateCoord).setValue(state,currentCoordValue*pi/180); |
| 75 | + coordsModel.get(n_modelCoords).setValue(state,cur_coordValue*pi/180); |
70 | 76 | case 'translational' |
71 | 77 | % not changing linear distances |
72 | | - coordsModel.get(n_StateCoord).setValue(state,currentCoordValue); |
| 78 | + coordsModel.get(n_modelCoords).setValue(state,cur_coordValue); |
73 | 79 | case 'coupled' |
74 | | - error('motiontype ''coupled'' is not managed by this function'); |
| 80 | + error('motiontype ''coupled'' is not managed by realizeMatStructKinematics.m'); |
75 | 81 | otherwise |
76 | | - error('motion type not recognized. Error due to OpenSim update?') |
| 82 | + error('motion type not recognized. Please check OpenSim model (maybe update error?') |
77 | 83 | end |
78 | 84 | end |
79 | 85 |
|
|
0 commit comments