-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sensor.m
80 lines (58 loc) · 1.41 KB
/
Sensor.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
63
64
65
66
classdef Sensor < hgsetget
properties(GetAccess = public)
id
x
y
end
properties (Dependent)
dx
dy
end
properties (Hidden)
lastReadTimeDx
lastReadTimeDy
end
methods
function obj = Sensor(sens)
%constructor; initializes everything to zeroes
fprintf('Creating %s sensor\n',sens)
obj.id = sens;
obj.dx = 0;
obj.dy = 0;
obj.x = 0;
obj.y = 0;
obj.lastReadTimeDx = hat;
obj.lastReadTimeDy = hat;
end
end
methods % SET & GET
function set.dx(obj,newDx)
% Adds dx to x
obj.x = obj.x + newDx;
end
function set.dy(obj,newDy)
% Adds dy to y
obj.y = obj.y + newDy;
end
function dxval = get.dx(obj)
timeSinceLastRead = hat - obj.lastReadTimeDx;
dxval = obj.x / timeSinceLastRead;
obj.lastReadTimeDx = hat;
end
function dyval = get.dy(obj)
timeSinceLastRead = hat - obj.lastReadTimeDy;
dyval = obj.y / timeSinceLastRead;
obj.lastReadTimeDy = hat;
end
function xval = get.x(obj)
% Resets x to zero
xval = obj.x;
obj.x = 0;
end
function yval = get.y(obj)
% Resets y to zero
yval = obj.y;
obj.y = 0;
end
end
end