Skip to content

Commit

Permalink
Add controls test (#34)
Browse files Browse the repository at this point in the history
* Add controls test

* updating workflow to run Controls tests on CI

* minor update to wecSimAppTest

---------

Co-authored-by: kmruehl <[email protected]>
  • Loading branch information
jtgrasb and kmruehl authored Jul 10, 2023
1 parent e45ca73 commit 1c51d7d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
release: [R2020b, latest]
folder: [Body-to-Body_Interactions,
Cable,
Controls,
End_Stops,
Free_Decay,
Generalized_Body_Modes,
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run-tests-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
release: [R2020b, latest]
folder: [Body-to-Body_Interactions,
Cable,
Controls,
End_Stops,
Free_Decay,
Generalized_Body_Modes,
Expand Down
4 changes: 2 additions & 2 deletions Controls/MPC/wecSimInputFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
controller(1).modelPredictiveControl.maxPTOForceChange = 1.5e6; % (`float`) Maximum Change in PTO Force (N/s)
controller(1).modelPredictiveControl.maxPos = 4; % (`float`) Maximum Position (m)
controller(1).modelPredictiveControl.maxVel = 3; % (`float`) Maximum Velocity (m/s)
controller(1).modelPredictiveControl.rScale = 4e-8; % (`float`) Scale for penalizing PTO force rate of change
controller(1).modelPredictiveControl.rScale = 1e-7; % (`float`) Scale for penalizing PTO force rate of change
controller(1).modelPredictiveControl.Ho = 200; % (`float`) Number of timesteps before MPC begins
controller(1).modelPredictiveControl.predictionHorizon = 15; % (`float`) Future time period predicted by plant model (s)
controller(1).modelPredictiveControl.coeffFile = 'coeff.mat'; % (`string`) File containing frequnecy dependent coeffcients
controller(1).modelPredictiveControl.plantFile = 'makePlantModel.m'; % (`string`) File used to create plant model
controller(1).modelPredictiveControl.predictFile = 'makePredictiveModel.m'; % (`string`) File used to create prediction model
controller(1).modelPredictiveControl.dt = 0.25; % (`float`) Timestep in which MPC is applied (s)
controller(1).modelPredictiveControl.dt = 0.5; % (`float`) Timestep in which MPC is applied (s)
controller(1).modelPredictiveControl.order = 4; % (`float`) Order of the plant model
controller(1).modelPredictiveControl.yLen = 3; % (`float`) Length of the output variable

Expand Down
74 changes: 74 additions & 0 deletions Controls/TestControls.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
classdef TestControls < matlab.unittest.TestCase

properties
OriginalDefault
testDir
h5Dir = "hydroData"
h5Name = 'sphere.h5'
outName = 'sphere.out'
end

methods (Access = 'public')
function obj = TestControls
obj.testDir = fileparts(mfilename('fullpath'));
end
end

methods (TestMethodSetup)
function killPlots (~)
set(0,'DefaultFigureVisible','off');
end
end

methods(TestClassSetup)
function captureVisibility(testCase)
testCase.OriginalDefault = get(0,'DefaultFigureVisible');
end
function runBemio(testCase)
cd(testCase.h5Dir);
if isfile(testCase.h5Name)
fprintf('runBemio skipped, *.h5 already exists\n')
else
bemio
end
cd(testCase.testDir)
end
end

methods(TestMethodTeardown)
function returnHome(testCase)
cd(testCase.testDir)
end
end

methods(TestClassTeardown)
function checkVisibilityRestored(testCase)
set(0,'DefaultFigureVisible',testCase.OriginalDefault);
testCase.assertEqual(get(0,'DefaultFigureVisible'), ...
testCase.OriginalDefault);
end
end

methods(Test)
function testPassive(testCase)
cd('Passive (P)')
wecSim
end
function testReactive(testCase)
cd('Reactive (PI)')
wecSim
end
function testLatching(testCase)
cd('Latching')
wecSim
end
function testDeclutching(testCase)
cd('Declutching')
wecSim
end
function testMPC(testCase)
cd('MPC')
wecSim
end
end
end
4 changes: 4 additions & 0 deletions wecSimAppTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
% results = wecSimAppTest(testsPath)
% returns a matlab.unittest.TestResult object for the tests
% located under the given path
%
% runtests <testDirectory>
% runs a specific test directory (e.g., Controls)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
arguments
testsPath string = "."
Expand Down

0 comments on commit 1c51d7d

Please sign in to comment.