-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestKinematics.m
62 lines (49 loc) · 1.59 KB
/
testKinematics.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
56
57
58
59
60
61
62
% Main function
function tests = testKinematics
tests = functiontests(localfunctions);
end
% File fixture
function setupOnce(testCase)
% Add files to MATLAB PATH
initialize
% Create a serial link object - representing the robot arm
testCase.TestData.robot = actual;
% Define tolerance
testCase.TestData.tol = 1e-6;
end
% Test functions
function testDirectKinematics(testCase)
% Define number of tests
numTests = 10;
% Get the robot arm object
robot = testCase.TestData.robot;
% perform test
for i = 1:numTests
q = rand(size(robot.links, 2), 1) .* (robot.qlim(:,2) - ...
robot.qlim(:,1)) + robot.qlim(:,1);
Tee_computed = direct_kine(dh, q);
Tee_toolbox = double(robot.fkine(q));
% Check if the computed forward kinematics results are almost equal
verifyTrue(testCase, isequal(abs(Tee_computed - Tee_toolbox) < ...
testCase.TestData.tol, ones(size(Tee_computed))), ...
sprintf('Direct kinematics test %d failed.', i));
end
end
function testInverseKinematics(testCase)
% Define number of test
numTests = 10;
% Get the robot arm object
robot = testCase.TestData.robot;
% perform test
for i = 1:numTests
q = rand(size(robot.links, 2), 1) .* (robot.qlim(:,2) - ...
robot.qlim(:,1)) + robot.qlim(:,1);
Tee = direct_kine(dh, q);
qc = inv_kine(Tee, dh, q);
TeeComputed = direct_kine(dh, qc);
% Check if the computed inverse kinematics results are within tolerance
verifyTrue(testCase, isequal(abs(Tee - TeeComputed) < ...
testCase.TestData.tol, ones(size(TeeComputed))), ...
sprintf('Inverse kinematics test %d failed.', i));
end
end