Skip to content

Commit e54050f

Browse files
committed
Added unit test on Examples directly
1 parent 2ffab1f commit e54050f

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
% This is intended to verify the matrices (Minimal_Basis and Perp_Basis) obtained from
2+
% "RPNA_URDF_Examples.m".
3+
clear;
4+
clc;
5+
6+
RPNA_Examples()
7+
save('RPNA_Examples_Results.mat','Perp_Basis','Minimal_Basis');
8+
9+
clear;
10+
clc;
11+
RPNA_URDF_Example()
12+
save('RPNA_URDF_Example_Results.mat','Perp_Basis','Minimal_Basis');
13+
14+
clear;
15+
clc;
16+
%%
17+
[model_URDF, robotics_toolbox_robot] = URDF_to_spatialv2_model("panda_arm_no_fixed.urdf");
18+
19+
dof = robotics_toolbox_robot.NumBodies;
20+
W = cell(dof,1);
21+
for i = 1:dof
22+
Ixx = robotics_toolbox_robot.Bodies{1,i}.Inertia(1);
23+
Iyy = robotics_toolbox_robot.Bodies{1,i}.Inertia(2);
24+
Izz = robotics_toolbox_robot.Bodies{1,i}.Inertia(3);
25+
Iyz = robotics_toolbox_robot.Bodies{1,i}.Inertia(4);
26+
Ixz = robotics_toolbox_robot.Bodies{1,i}.Inertia(5);
27+
Ixy = robotics_toolbox_robot.Bodies{1,i}.Inertia(6);
28+
m = robotics_toolbox_robot.Bodies{1,i}.Mass;
29+
Cx = robotics_toolbox_robot.Bodies{1,i}.CenterOfMass(1);
30+
Cy = robotics_toolbox_robot.Bodies{1,i}.CenterOfMass(2);
31+
Cz = robotics_toolbox_robot.Bodies{1,i}.CenterOfMass(3);
32+
W{i,1} = [ m , m*Cx, m*Cy, m*Cz, Ixx, Iyy, Izz, Iyz, Ixz, Ixy]';
33+
end
34+
W = cell2mat(W);
35+
36+
model_DH = Panda_model(W);
37+
robotics_toolbox_robot.DataFormat = 'column';
38+
robotics_toolbox_robot.Gravity = [0 0 -9.81]';
39+
%% load basis results of Panda robot modeled by DH or URDF
40+
41+
% panda basis from DH
42+
load RPNA_Examples_Results.mat
43+
Perp_Basis_DH = Perp_Basis;
44+
Minimal_Basis_DH = Minimal_Basis;
45+
46+
% panda basis from URDF
47+
load RPNA_URDF_Example_Results.mat
48+
Perp_Basis_URDF = Perp_Basis;
49+
Minimal_Basis_URDF = Minimal_Basis;
50+
51+
%% Verification loop
52+
timeDuration = 2.5;
53+
currentTime = 0;
54+
timeStep = 0.005;
55+
for i =0:timeDuration/timeStep
56+
q = -cos(currentTime)*ones(dof,1);
57+
qd = sin(currentTime)*ones(dof,1);
58+
qdd = cos(currentTime)*ones(dof,1);
59+
qd_r = qd;
60+
disp("===============================================")
61+
62+
tau1 = inverseDynamics(robotics_toolbox_robot, q, qd, qdd);
63+
64+
[tau2, ~] = ID( model_DH, q, qd, qdd );
65+
checkValue('ID with model from DH',tau2, tau1, 1e-5);
66+
67+
[tau3, ~] = ID( model_URDF, q, qd, qdd );
68+
checkValue('ID with model from URDF',tau3, tau1, 1e-5);
69+
70+
[Y_DH, ~] = RegressorClassical( model_DH, q, qd,qdd);
71+
tau4 = Y_DH*W;
72+
checkValue('Torque of model from DH',tau4, tau1, 1e-5);
73+
74+
tau5 = Y_DH * Minimal_Basis_DH * Perp_Basis_DH' *W;
75+
checkValue('Torque of model from DH with basis',tau5, tau1, 1e-5);
76+
77+
[Y_URDF, ~] = RegressorClassical( model_URDF, q, qd,qdd);
78+
tau6 = Y_URDF*W;
79+
checkValue('Torque of model from URDF',tau6, tau1, 1e-5);
80+
81+
tau7 = Y_URDF * Minimal_Basis_URDF * Perp_Basis_URDF' *W;
82+
checkValue('Torque of model from URDF with basis',tau7, tau1, 1e-5);
83+
84+
currentTime = currentTime + timeStep;
85+
end
86+
87+
function checkValue(name, v1, v2, tolerance)
88+
if nargin == 3
89+
tolerance = sqrt(eps);
90+
end
91+
value = norm(v1(:)-v2(:));
92+
fprintf('%s \t %e\n',name,value);
93+
if value > tolerance
94+
error('%s is out of tolerance',name);
95+
end
96+
end

0 commit comments

Comments
 (0)