|
2 | 2 | import config |
3 | 3 | from algorithms.helpers.measurement import Measurement |
4 | 4 | from algorithms.algorithm import Vector2 |
| 5 | +from algorithms.helpers.direct_triangulation import DirectTriangulation |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class Node: |
@@ -48,17 +49,6 @@ def set_pipe(self, pipe_in): |
48 | 49 | self.piping = True |
49 | 50 |
|
50 | 51 | def start_new_cycle(self): |
51 | | - # for other_node in self.communicate_list: |
52 | | - # key = other_node.id |
53 | | - # if key not in self.measurement_history: |
54 | | - # # Add a new list to keep track of measures from this new node |
55 | | - # self.measurement_history[key] = [] |
56 | | - # if self.measurements: |
57 | | - # for meas in self.measurements: |
58 | | - # if meas.node1 == self: |
59 | | - # self.measurement_history[key].append(meas) |
60 | | - # if len(self.measurement_history[key]) > config.MAX_HISTORY: |
61 | | - # self.measurement_history[key].pop(0) |
62 | 52 | self.measurements = [] |
63 | 53 | self.triangulate_list = [] |
64 | 54 | if not self.is_base: |
@@ -90,37 +80,9 @@ def add_measurement(self, node_b, dist, std=None): |
90 | 80 | # self.add_to_communicate_list(node_b) |
91 | 81 | print(f"Discarded meas with {dist} distance to node {node_b.id} due to bounding error.") |
92 | 82 |
|
93 | | - # def add_to_communicate_list(self, node_b): |
94 | | - # if node_b not in self.communicate_list: |
95 | | - # self.communicate_list.append(node_b) |
96 | | - # key = node_b.id |
97 | | - # if key not in self.measurement_history: |
98 | | - # # Add a new list to keep track of measures from this new node |
99 | | - # self.measurement_history[key] = [] |
100 | | - |
101 | 83 | def is_resolved(self): |
102 | 84 | return self.resolved |
103 | 85 |
|
104 | | - # def set_position(self, x, y): |
105 | | - # avg = self.get_avg_position() |
106 | | - # cur_pos = Vector2(avg[0], avg[1]) |
107 | | - # new_pos = Vector2(x, y) |
108 | | - # offset = cur_pos - new_pos |
109 | | - # d = offset.magnitude() |
110 | | - # if d <= Node.max_move_per_cycle: |
111 | | - # self.x = x |
112 | | - # self.y = y |
113 | | - # else: |
114 | | - |
115 | | - # self.x = avg[0] |
116 | | - # self.y = avg[1] |
117 | | - # self.extrapolate = True |
118 | | - |
119 | | - # self.resolved = True |
120 | | - |
121 | | - # self.position_history.append((x, y)) |
122 | | - # if len(self.position_history) > Node.max_history: |
123 | | - # self.position_history.pop(0) |
124 | 86 |
|
125 | 87 | def get_last_position(self): |
126 | 88 | if len(self.position_history) == 0: |
@@ -154,38 +116,44 @@ def get_triangulations(self): |
154 | 116 |
|
155 | 117 | def display_triangulations(self): |
156 | 118 | for dt in self.triangulate_list: |
157 | | - dt.displayTriangulation((self.x, self.y)) |
| 119 | + dt.display_triangulation((self.x, self.y)) |
158 | 120 |
|
159 | 121 | def set_position_vec(self, pos): |
160 | | - last = self.get_last_position() |
161 | | - if last is None: |
162 | | - last_pos = pos |
163 | | - else: |
164 | | - last_pos = Vector2(last[0], last[1]) |
165 | | - offset = last_pos - pos |
166 | | - d = offset.magnitude() |
| 122 | + # last = self.get_last_position() |
| 123 | + # if last is None: |
| 124 | + # last_pos = pos |
| 125 | + # else: |
| 126 | + # last_pos = Vector2(last[0], last[1]) |
| 127 | + # offset = last_pos - pos |
| 128 | + # d = offset.magnitude() |
167 | 129 |
|
168 | 130 | # print(d) |
169 | 131 |
|
| 132 | + # if d <= Node.max_move_per_cycle: |
| 133 | + self.x = pos.x |
| 134 | + self.y = pos.y |
| 135 | + # else: |
| 136 | + # vel = self.get_avg_velocity() |
| 137 | + # pos = Vector2(last[0], last[1]) |
| 138 | + # new_pos = pos + vel |
| 139 | + # self.x = new_pos.x |
| 140 | + # self.y = new_pos.y |
| 141 | + # self.extrapolate = True |
| 142 | + |
170 | 143 | self.position_history.append((pos.x, pos.y)) |
171 | 144 | self.added_position = True |
172 | 145 | if len(self.position_history) > Node.max_history: |
173 | 146 | self.position_history.pop(0) |
174 | 147 |
|
175 | | - if d <= Node.max_move_per_cycle: |
176 | | - self.x = pos.x |
177 | | - self.y = pos.y |
178 | | - else: |
179 | | - # avg = self.get_avg_position() |
180 | | - vel = self.get_avg_velocity() |
181 | | - pos = Vector2(last[0], last[1]) |
182 | | - new_pos = pos + vel |
183 | | - self.x = new_pos.x |
184 | | - self.y = new_pos.y |
185 | | - self.extrapolate = True |
186 | | - |
187 | 148 | self.resolved = True |
188 | 149 |
|
| 150 | + def consider_last_location(self): |
| 151 | + last = self.get_last_position() |
| 152 | + if last is not None: |
| 153 | + dt = DirectTriangulation(None, None, None, None, empty=True) |
| 154 | + dt.directly_add_guess(Vector2(last[0], last[1])) |
| 155 | + self.add_triangulation(dt) |
| 156 | + |
189 | 157 | def get_position(self): |
190 | 158 | return self.x, self.y |
191 | 159 |
|
@@ -266,7 +234,7 @@ def show(self): |
266 | 234 | "cmd": "draw_circle", |
267 | 235 | "args": { |
268 | 236 | "fill": "white", |
269 | | - "r": 0.5, |
| 237 | + "r": 200, |
270 | 238 | "tags": ['node'], |
271 | 239 | "outline": "", |
272 | 240 | "x": self.x, |
|
0 commit comments