-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpaceWise.m
More file actions
90 lines (72 loc) · 2.94 KB
/
Copy pathSpaceWise.m
File metadata and controls
90 lines (72 loc) · 2.94 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
classdef SpaceWise < SimulationObject
%ZONE Summary of this class goes here
% Detailed explanation goes here
properties
ID
Luminaires Luminaire
Perimeter
DimLevel = 0.2
DimAfter = duration(0,15,0)
end
methods
function generateState(obj)
arrayfun(@pGenState, obj)
function pGenState(obj)
% Determine if individual luminaires should be on 100%
onLuminaires(obj)
obj.dimLuminaires;
end
end
function onLuminaires(obj)
arrayfun(@(o)pOn(o),obj);
function pOn(aZone)
% Convert durations to number of points
epoch = mode(diff(aZone.SimRelTime));
nPad = round(aZone.DimAfter/epoch);
arrayfun(@(o)pSet(o, nPad), aZone.Luminaires);
end
function pSet(aLuminaire, nPad)
% Get sensor state
sensorState = aLuminaire.ActiveSensor.State;
% Pad sensor state
statePad = vertcat(false(nPad,1), sensorState, false(nPad,1));
% Shift sensor state in accordance with delay
stateShift = false(numel(statePad), nPad);
for iS = 1:nPad
stateShift(:,iS) = circshift(statePad, iS);
end
% Remove padding
stateShift(1+end-nPad:end,:) = [];
stateShift(1:nPad,:) = [];
% Collapse shifted sensor state
stateA = any(stateShift(:,1:nPad),2);
% Combine shifted state with original and assign to
% luminaire
aLuminaire.State = double(sensorState | stateA);
end
end
function dimLuminaires(obj)
arrayfun(@(o)pSync(o),obj);
function pSync(aZone)
% Determine if any luminaires are on
% Extract individual luminaire states
luminaireHandles = vertcat(aZone.Luminaires);
luminaireStates = horzcat(luminaireHandles.State);
% Collapse luminaire states
anyLuminaire = any(luminaireStates,2);
arrayfun(@(o)pSet(o, anyLuminaire, aZone.DimLevel), aZone.Luminaires);
end
function pSet(aLuminaire, dimState, dimLevel)
thisDimState = dimState & ~aLuminaire.State;
aLuminaire.State(thisDimState) = dimLevel;
end
end
function render(obj, sim, varargin)
if nargin == 3
render(vertcat(obj.Luminaires), sim, varargin{1});
else
render(vertcat(obj.Luminaires), sim);
end
end
end
end