-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensor.py
More file actions
76 lines (61 loc) · 1.66 KB
/
Copy pathSensor.py
File metadata and controls
76 lines (61 loc) · 1.66 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
class Sensor():
def __init__(self, battery, pos, range=0.5, status=0):
self.battery = battery
self.pos = pos
self.range = range
self.status = status
self.cover = set()
self.manage = set()
def __str__(self):
return 'Sensor: battery: {0}, position: ({1}), range: {2}, status: {3}'.format(self.battery, self.pos, self.range, self.status)
def __repr__(self):
return 'Sensor: battery: {0}, position: ({1}), range: {2}, status: {3}'.format(self.battery, self.pos, self.range, self.status)
def adjust_range(self, adjustment):
"""
given an adjustment, changes the range of the sensor. Also the range cannot go below 0
Arguments:
adjustment: value to change the range, can be a postive or negative value
"""
temp = self.range
if temp+adjustment>0:
self.range += adjustment
else:
self.range = 0
def distance(self, target):
"""
calculates the euclidean distance to a target from this sensor
Arguments:
target: target object
returns:
the distance
"""
return (self.pos[0] - target.pos[0])**2 + (self.pos[1] - target.pos[1])**2
def reachable(self, target_set):
"""
finds the reachable targets off a list of targets
Arguments:
target_set: a itarable containing targets
returns:
A list of reachable targets
"""
reachables = []
for target in target_set:
if self.distance(target) <= self.range:
reachables.append(target)
return reachables
def on(self):
"""
change status to on
"""
self.status = 1
print(self, 'turned on')
def off(self):
"""
change status to off
"""
self.status = 0
print(self, 'turned off')
def find_manage(self):
"""
find the managing targets for this sensor
"""