-
Notifications
You must be signed in to change notification settings - Fork 68
/
getFreeFloatingMassMatrix.m
55 lines (42 loc) · 1.68 KB
/
getFreeFloatingMassMatrix.m
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
function M = getFreeFloatingMassMatrix(KinDynModel)
% GETFREEFLOATINGMASSMATRIX retrieves the free floating mass matrix.
%
% This matlab function wraps a functionality of the iDyntree library.
% For further info see also: https://github.com/robotology/idyntree
%
% FORMAT: M = getFreeFloatingMassMatrix(KinDynModel)
%
% INPUTS: - KinDynModel: a structure containing the loaded model and additional info.
%
% OUTPUTS: - M: [6+ndof x 6+ndof] free floating mass matrix.
%
% Author : Gabriele Nava ([email protected])
%
% SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
% SPDX-License-Identifier: BSD-3-Clause
%% ------------Initialization----------------
% get the mass matrix
ack = KinDynModel.kinDynComp.getFreeFloatingMassMatrix(KinDynModel.dynamics.M_iDyntree);
% check for errors
if ~ack
error('[getFreeFloatingMassMatrix]: unable to retrieve the mass matrix from the reduced model.')
end
% convert to Matlab format
M = KinDynModel.dynamics.M_iDyntree.toMatlab;
% debug output
if KinDynModel.DEBUG
disp('[getFreeFloatingMassMatrix]: debugging outputs...')
% check mass matrix symmetry and positive definiteness
M_symm_error = norm(M -(M + M')/2);
M_symm_eig = eig((M + M')/2);
if M_symm_error > 0.1
error('[getFreeFloatingMassMatrix]: M is not symmetric')
end
for k = 1:length(M_symm_eig)
if M_symm_eig(k) < 0
error('[getFreeFloatingMassMatrix]: M is not positive definite')
end
end
disp('[getFreeFloatingMassMatrix]: done.')
end
end