better sigmoid sensor unit testing
This commit is contained in:
@@ -10,8 +10,11 @@ function value = sensorPerformance(obj, agentPos, agentPan, agentTilt, targetPos
|
|||||||
value (:, 1) double;
|
value (:, 1) double;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% compute direct distance and distance projected onto the ground
|
||||||
d = vecnorm(agentPos - targetPos, 2, 2); % distance from sensor to target
|
d = vecnorm(agentPos - targetPos, 2, 2); % distance from sensor to target
|
||||||
x = vecnorm(agentPos(1:2) - targetPos(:, 1:2), 2, 2); % distance from sensor nadir to target nadir (i.e. distance ignoring height difference)
|
x = vecnorm(agentPos(1:2) - targetPos(:, 1:2), 2, 2); % distance from sensor nadir to target nadir (i.e. distance ignoring height difference)
|
||||||
|
|
||||||
|
% compute tilt angle
|
||||||
tiltAngle = (180 - atan2d(x, targetPos(:, 3) - agentPos(3))) - agentTilt; % degrees
|
tiltAngle = (180 - atan2d(x, targetPos(:, 3) - agentPos(3))) - agentTilt; % degrees
|
||||||
|
|
||||||
% Membership functions
|
% Membership functions
|
||||||
|
|||||||
@@ -33,20 +33,29 @@ classdef test_sigmoidSensor < matlab.unittest.TestCase
|
|||||||
betaDist = 3;
|
betaDist = 3;
|
||||||
alphaTilt = 15; % degrees
|
alphaTilt = 15; % degrees
|
||||||
betaTilt = 3;
|
betaTilt = 3;
|
||||||
|
h = 1e-6;
|
||||||
tc.testClass = tc.testClass.initialize(alphaDist, betaDist, NaN, NaN, alphaTilt, betaTilt);
|
tc.testClass = tc.testClass.initialize(alphaDist, betaDist, NaN, NaN, alphaTilt, betaTilt);
|
||||||
|
|
||||||
% Plot
|
% Plot
|
||||||
tc.testClass.plotParameters();
|
tc.testClass.plotParameters();
|
||||||
|
|
||||||
% Performance at current position should be maximized (1)
|
% Anticipate perfect performance for a point directly below and
|
||||||
% some wiggle room is needed for certain parameter conditions,
|
% extremely close
|
||||||
% e.g. small alphaDist and betaDist produce mu_d slightly < 1
|
tc.verifyEqual(tc.testClass.sensorPerformance([0, 0, h], NaN, 0, [0, 0, 0]), 1, 'RelTol', 1e-3);
|
||||||
tc.verifyEqual(tc.testClass.sensorPerformance(zeros(1, 3), NaN, 0, zeros(1, 3)), 1, 'AbsTol', 1e-3);
|
|
||||||
% It looks like mu_t can max out at really low values like 0.37
|
% It looks like mu_t can max out at really low values like 0.37
|
||||||
% when alphaTilt and betaTilt are small, which seems wrong
|
% when alphaTilt and betaTilt are small, which seems wrong
|
||||||
|
|
||||||
% Performance at distance alphaDist should be 1/2
|
% Performance at nadir point, distance alphaDist should be 1/2 exactly
|
||||||
tc.verifyEqual(tc.testClass.sensorPerformance([0, 0, alphaDist], NaN, 0, [0, 0, 0]), 1/2, 'AbsTol', 1e-3);
|
tc.verifyEqual(tc.testClass.sensorPerformance([0, 0, alphaDist], NaN, 0, [0, 0, 0]), 1/2);
|
||||||
|
|
||||||
|
% Performance at (almost) 0 distance, alphaTilt should be 1/2
|
||||||
|
tc.verifyEqual(tc.testClass.sensorPerformance([0, 0, h], NaN, 0, [tand(alphaTilt)*h, 0, 0]), 1/2, 'RelTol', 1e-3);
|
||||||
|
|
||||||
|
% Performance at great distance should be 0
|
||||||
|
tc.verifyEqual(tc.testClass.sensorPerformance([0, 0, 10], NaN, 0, [0, 0, 0]), 0, 'AbsTol', 1e-9);
|
||||||
|
|
||||||
|
% Performance at great tilt should be 0
|
||||||
|
tc.verifyEqual(tc.testClass.sensorPerformance([0, 0, h], NaN, 0, [5, 5, 0]), 0, 'AbsTol', 1e-9);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user