Permalink
Browse files

drawing tracks for robot avoidance added

  • Loading branch information...
1 parent 70fcdce commit 9580da6a18c0d3c8e2f4d3ed60bb40866b9f2f1c @bahniks committed Apr 24, 2014
Showing with 75 additions and 33 deletions.
  1. +6 −2 Stuff/Modules/cm.py
  2. +58 −29 Stuff/Modules/explorer.py
  3. +11 −2 Stuff/Modules/ra.py
View
@@ -147,7 +147,7 @@ def _processRoomFile(self, infile, endsplit = 7):
count = -1
for line in infile:
try:
- line = list(map(float, line.split()[:endsplit])) # zmenit na int??? float je pro RA
+ line = self._evaluateLine(line, endsplit)
self.data.append(line)
except Exception:
continue
@@ -206,6 +206,10 @@ def _processRoomFile(self, infile, endsplit = 7):
self.data[missLines][2:4] = before
+ def _evaluateLine(self, line, endsplit):
+ return list(map(int, line.split()[:endsplit]))
+
+
def _processArenaFile(self, infile):
for line in infile:
if line.count("END_HEADER") > 0:
@@ -216,7 +220,7 @@ def _processArenaFile(self, infile):
count = -1
for line in infile:
try:
- line = list(map(float, line.split()[:7])) # zmenit na int??? float je pro RA
+ line = self._evaluateLine(line, 7)
except Exception:
continue
View
@@ -508,7 +508,7 @@ def changedTime(self, value, unit = "0-100"):
Rx, Ry = curLine[2:4]
Rx *= self.scale
Ry *= self.scale
- self.arenaCanv.coords("robotA", (Rx + 16, Ry + 16, Rx + 24, Ry + 24))
+ self.arenaCanv.coords("robotA", (Rx + 12, Ry + 12, Rx + 28, Ry + 28))
self.roomCanv.coords("ratR", ((Ax - Rx)/2 + 146, (Ay - Ry)/2 + 146,
(Ax - Rx)/2 + 154, (Ay - Ry)/2 + 154))
r = self.cm.sectorRadius * self.scale
@@ -588,7 +588,7 @@ def _createTail(self, curLine):
self.roomCanv.delete("trailR")
if curLine[0] >= 10:
end = curLine[0]
- r = self.cm.radius
+ adjust = 150 - self.cm.radius * self.scale
start = end - 500 if end > 500 else 0
start = round(start*2, -1) // 2
if m.mode == "CM":
@@ -597,18 +597,37 @@ def _createTail(self, curLine):
arena = []
room = []
for rx, ry, ax, ay in trail:
- arena.append((ax + 150 - r, ay + 150 - r))
- room.append((rx + 150 - r, ry + 150 - r))
- arena.append((curLine[7] + 150 - r, curLine[8] + 150 - r))
- room.append((curLine[2] + 150 - r, curLine[3] + 150 - r))
+ arena.append((ax*self.scale + adjust, ay*self.scale + adjust))
+ room.append((rx*self.scale + adjust, ry*self.scale + adjust))
+ arena.append((curLine[7] + adjust, curLine[8] + adjust))
+ room.append((curLine[2] + adjust, curLine[3] + adjust))
self.arenaCanv.create_line((arena), fill = "blue", width = 2, tag = "trailA")
self.roomCanv.create_line((room), fill = "blue", width = 2, tag = "trailR")
+ elif m.mode == "RA":
+ self.arenaCanv.delete("trailRobot")
+ trail = [tuple(content[2:4] + content[7:9]) for content in
+ self.cm.data[start:end:5]]
+ ratA = []
+ ratR = []
+ robotA = []
+ for rx, ry, ax, ay in trail:
+ ratA.append((ax*self.scale + adjust, ay*self.scale + adjust))
+ robotA.append((rx*self.scale + adjust, ry*self.scale + adjust))
+ ratR.append(((ax - rx)*self.scale / 2 + 150,
+ (ay - ry)*self.scale / 2 + 150))
+ ratA.append((curLine[7]*self.scale + adjust, curLine[8]*self.scale + adjust))
+ robotA.append((curLine[2]*self.scale + adjust, curLine[3]*self.scale + adjust))
+ ratR.append(((curLine[7] - curLine[2])*self.scale / 2 + 150,
+ (curLine[8] - curLine[3])*self.scale / 2 + 150))
+ self.arenaCanv.create_line((ratA), fill = "blue", width = 2, tag = "trailA")
+ self.roomCanv.create_line((ratR), fill = "blue", width = 2, tag = "trailR")
+ self.arenaCanv.create_line((robotA), fill = "green", width = 2, tag = "trailRobot")
else:
trail = [tuple(content[2:4]) for content in self.cm.data[start:end:5]]
arena = []
for ax, ay in trail:
- arena.append((ax + 150 - r, ay + 150 - r))
- arena.append((curLine[2] + 150 - r, curLine[3] + 150 - r))
+ arena.append((ax*self.scale + adjust, ay*self.scale + adjust))
+ arena.append((curLine[2] + adjust, curLine[3] + adjust))
self.arenaCanv.create_line((arena), fill = "blue", width = 2, tag = "trailA")
@@ -761,9 +780,9 @@ def _createShockSector(self):
self.roomCanv.create_line((Sx1, Sy1, 150, 150, Sx2, Sy2), fill = "red", width = 2,\
tags = "shockZone")
elif m.mode == "MWM":
- x = self.cm.platformX + 20
- y = self.cm.platformY + 20
- r = self.cm.platformRadius
+ x = self.cm.platformX * self.scale + 20
+ y = self.cm.platformY * self.scale + 20
+ r = self.cm.platformRadius * self.scale
self.arenaCanv.create_oval(x - r, y - r, x + r, y + r, outline = "red",
width = 2, tags = "platformAF")
self.roomCanv.create_oval(x - r, y - r, x + r, y + r, outline = "red",
@@ -772,41 +791,51 @@ def _createShockSector(self):
r = self.cm.sectorRadius * self.scale / 2
self.roomCanv.create_oval(150 - r, 150 - r, 150 + r, 150 + r, outline = "red",
width = 2, tags = "shockZoneR")
- self.roomCanv.create_oval(146, 146, 154, 154, outline = "green", fill = "green",
+ self.roomCanv.create_oval(142, 142, 158, 158, outline = "green3", fill = "green3",
width = 2, tags = "robotR")
def _drawTrack(self):
- if m.mode == "CM":
+ if m.mode == "CM" or m.mode == "RA":
data = [line[2:4] + line[6:9] for line in self.cm.data if
self.minTime <= line[1] <= self.maxTime]
arena = []
room = []
prev = [-100, -100, 0, -100, -100]
- last = [0, 0]
+ last = 0
for count, line in enumerate(data):
- if abs(line[0] - prev[0]) + abs(line[1] - prev[1]) > 2 or count - last[0] == 25 or\
+ if abs(line[0] - prev[0]) + abs(line[1] - prev[1]) > 2 or count - last == 25 or\
line[2] > 0:
room.append(line[0:2])
- last[0] = count
- if abs(line[3] - prev[3]) + abs(line[4] - prev[4]) > 2 or count - last[1] == 25:
arena.append(line[3:5])
- last[1] = count
+ last = count
prev = line
- self.arenaCanv.create_line(([item + 20 for line in arena for item in line]),
- fill = "black", width = 2)
- self.roomCanv.create_line(([item + 20 for line in room for item in line]),
- fill = "black", width = 2)
+ if m.mode == "CM":
+ self.roomCanv.create_line(([i * self.scale + 20 for line in room for i in line]),
+ fill = "black", width = 2)
+ else:
+ self.arenaCanv.create_line(([i * self.scale + 20 for line in room for i in line]),
+ fill = "green", width = 2)
+ self.roomCanv.create_line(([(i[0] - i[1]) * self.scale / 2 + 150 for line in
+ zip(arena, room) for i in zip(line[0], line[1])]),
+ fill = "black", width = 2)
+
+ self.arenaCanv.create_line(([i * self.scale + 20 for line in arena for i in line]),
+ fill = "black", width = 2)
+
if self.showShocksVar.get():
- shocks = [line[2:4] for count, line in enumerate(self.cm.data) if
+ indices = slice(2,4) if m.mode == "CA" else slice(7,9)
+ fun = self.roomCanv.create_oval if m.mode == "CA" else self.arenaCanv.create_oval
+
+ shocks = [line[indices] for count, line in enumerate(self.cm.data) if
self.minTime <= line[1] <= self.maxTime and line[6] > 0 and
self.cm.data[count - 1][6] <= 0]
for shock in shocks:
- self.roomCanv.create_oval(shock[0] + 16, shock[1] + 16,
- shock[0] + 24, shock[1] + 24,
- outline = "red", width = 3)
+ fun(shock[0]*self.scale + 16, shock[1]*self.scale + 16,
+ shock[0]*self.scale + 24, shock[1]*self.scale + 24,
+ outline = "red", width = 3)
else:
data = [line[2:4] for line in self.cm.data if self.minTime <= line[1] <= self.maxTime]
points = []
@@ -817,7 +846,7 @@ def _drawTrack(self):
points.append(line)
last = count
prev = line
- self.roomCanv.create_line(([item + 20 for line in points for item in line]),
+ self.roomCanv.create_line(([item*self.scale + 20 for line in points for item in line]),
fill = "black", width = 2)
@@ -856,8 +885,8 @@ def _initializeAnimation(self):
elif m.mode == "RA":
self.roomCanv.create_oval(Ax - Rx + 146, Ay - Ry + 146, Ax - Rx + 154, Ay - Ry + 154,
fill = "black", tags = "ratR")
- self.arenaCanv.create_oval(Rx + 16, Ry + 16, Rx + 24, Ry + 24, outline = "green",
- fill = "green", tags = "robotA")
+ self.arenaCanv.create_oval(Rx + 12, Ry + 12, Rx + 28, Ry + 28, outline = "green3",
+ fill = "green3", tags = "robotA")
r = self.cm.sectorRadius * self.scale
self.arenaCanv.create_oval(Rx + 20 - r, Ry + 20 - r, Rx + 20 + r, Ry + 20 + r,
outline = "red", tags = "shockZoneA", width = 2)
View
@@ -46,7 +46,7 @@ def __init__(self, nameA, nameR = "auto"):
# processing data from robot frame
with open(self.nameR, "r") as infile:
self._processHeader(infile)
- self.radius = self.trackerResolution * self.arenaDiameter * 100
+ self.radius = self.trackerResolution * self.arenaDiameter * 100 / 2
self._processRoomFile(infile) # robot file generally internally corresponds to roomfile
# processing data from rat file
@@ -66,7 +66,6 @@ def __init__(self, nameA, nameR = "auto"):
CM.cache.popitem(last = False)
-
def _setRoomName(self, name): # ZMENIT rob na robot???
if name == "auto":
splitname = os.path.split(self.nameA)
@@ -80,6 +79,16 @@ def _setRoomName(self, name): # ZMENIT rob na robot???
self.nameR = name
+ def _evaluateLine(self, line, endsplit):
+ temp = line.split()[:endsplit]
+ if temp[2] != "0" or temp[3] != "0":
+ temp[2] = float(temp[2]) - self.centerX + self.radius
+ temp[3] = float(temp[3]) - self.centerY + self.radius
+ else:
+ temp[2:4] = [0, 0]
+ return list(map(int, temp))
+
+
def _addReinforcedSector(self, string, position):
self.sectorRadius = eval(string[position+1])

0 comments on commit 9580da6

Please sign in to comment.