Permalink
Browse files

graphs and removing reflections adapted for ra

  • Loading branch information...
1 parent 9580da6 commit d17fcb31ef933f06a9783fd31531ac1eca5fe954 @bahniks committed Apr 25, 2014
Showing with 73 additions and 16 deletions.
  1. +6 −5 Stuff/Modules/cm.py
  2. +4 −4 Stuff/Modules/explorer.py
  3. +33 −5 Stuff/Modules/graphs.py
  4. +30 −2 Stuff/Modules/ra.py
View
@@ -847,11 +847,12 @@ def _removalCondition(self, row, i, before, reflection):
reflection row - determined by speed
wrong points in the row
"""
- return any((self._computeSpeed(self.data[row + i], before) > 250,
- self.data[row + i][2:4] == self.data[row][2:4],
- self.data[row + i][7:9] == self.data[row][7:9],
- self._computeSpeed(reflection, self.data[row + i]) * 30 <
- self._computeSpeed(before, self.data[row + i]),
+ old = self.data[row]
+ new = self.data[row + i]
+ return any((self._computeSpeed(new, before) > 250,
+ new[2:4] == old[2:4],
+ new[7:9] == old[7:9],
+ self._computeSpeed(reflection, new) * 30 < self._computeSpeed(before, new),
row + i in self.interpolated))
def _cacheRemoval(self):
@@ -33,7 +33,7 @@
from processor import ProgressWindow
from optionget import optionGet
from graphs import getGraphTypes, Graphs, SvgGraph, SpeedGraph, DistanceFromCenterGraph
-from graphs import AngleGraph, DistanceFromPlatformGraph
+from graphs import AngleGraph, DistanceFromPlatformGraph, DistanceFromRobotGraph
from comment import Comment, commentColor
import mode as m
@@ -227,11 +227,10 @@ def __init__(self, root):
self.saveBut.grid(column = 1, row = 2, sticky = E)
self.removeReflections.grid(column = 1, row = 0, padx = 3, pady = 2, sticky = (N, W))
- if m.mode == "CM":
- self.showShocks.grid(column = 1, row = 1, padx = 3, pady = 2, sticky = (N, W))
self.showTail.grid(column = 1, row = 2, padx = 3, pady = 2, sticky = (N, W))
if m.files == "pair":
+ self.showShocks.grid(column = 1, row = 1, padx = 3, pady = 2, sticky = (N, W))
self.showAnimation.grid(column = 0, row = 0, padx = 2, pady = 1, sticky = (N, W))
self.showTrack.grid(column = 0, row = 1, padx = 2, pady = 1, sticky = (N, W))
@@ -883,7 +882,8 @@ def _initializeAnimation(self):
self.roomCanv.create_oval(Rx + 16, Ry + 16, Rx + 24, Ry + 24,
fill = "black", tags = "ratR")
elif m.mode == "RA":
- self.roomCanv.create_oval(Ax - Rx + 146, Ay - Ry + 146, Ax - Rx + 154, Ay - Ry + 154,
+ self.roomCanv.create_oval((Ax - Rx)/2 + 146, (Ay - Ry)/2 + 146,
+ (Ax - Rx)/2 + 154, (Ay - Ry)/2 + 154,
fill = "black", tags = "ratR")
self.arenaCanv.create_oval(Rx + 12, Ry + 12, Rx + 28, Ry + 28, outline = "green3",
fill = "green3", tags = "robotA")
View
@@ -35,6 +35,8 @@ def getGraphTypes():
types[1] = ["Proximity to side", "DistanceFromCenterGraph(self)"]
elif m.mode == "MWM":
types.insert(2, ["Distance from platform", "DistanceFromPlatformGraph(self)"])
+ elif m.mode == "RA":
+ types.insert(2, ["Distance from robot", "DistanceFromRobotGraph(self)"])
return types
@@ -309,7 +311,7 @@ def compute(self, cm, skip = 12, smooth = 2):
e.g. when skip = 12 and smooth = 2, speed is computed as an average of two speeds
computed from lines separated by 11 lines
"""
- indices = slice(7, 9) if m.mode == "CM" else slice(2, 4)
+ indices = cm.indices
resolution = cm.trackerResolution
# saving speed between every 'skip' data point ... in centimeters per second
@@ -386,7 +388,10 @@ def compute(self, cm, smooth = 10):
self.radius = cm.radius
Cx, Cy = cm.centerX, cm.centerY
- if m.mode != "OF":
+ if m.mode == "RA":
+ dists = [((line[7] - Cx)**2 + (line[8] - Cy)**2)**0.5 for line in cm.data[start:] if
+ line[1] <= self.maxTime]
+ elif m.mode != "OF":
dists = [((line[2] - Cx)**2 + (line[3] - Cy)**2)**0.5 for line in cm.data[start:] if
line[1] <= self.maxTime]
else:
@@ -411,6 +416,7 @@ def CM_loaded(self, cm, initTime = 0, minTime = 0, maxTime = "max"):
self.drawGraph(maxY = self.maxY, valueList = self.points)
+
class DistanceFromPlatformGraph(Graphs, SvgGraph):
"graph depicting distance from platform during the MWM session"
def __init__(self, parent, cm = None, purpose = "graph"):
@@ -434,7 +440,7 @@ def compute(self, cm, smooth = 10):
Cx, Cy = cm.centerX, cm.centerY
Px, Py = cm.platformX, cm.platformY
- self.platformRadius = cm.platformRadius
+ self.radius = cm.platformRadius
self.points = [((line[2] - Px)**2 + (line[3] - Py)**2)**0.5 for line in cm.data[start:] if
line[1] <= self.maxTime]
@@ -449,13 +455,31 @@ def CM_loaded(self, cm, initTime = 0, minTime = 0, maxTime = "max"):
super().CM_loaded(cm, minTime, maxTime, initTime)
self.compute(cm)
- y = self.height * (1 - self.platformRadius/self.maxY)
+ y = self.height * (1 - self.radius/self.maxY)
self.create_line((0, y, self.width, y), fill = "grey")
self.drawGraph(maxY = self.maxY, valueList = self.points)
+class DistanceFromRobotGraph(DistanceFromPlatformGraph):
+ "graph depicting distance from the robot during the RA session"
+ def __init__(self, parent, cm = None, purpose = "graph"):
+ super().__init__(parent = parent, cm = cm, purpose = purpose)
+
+
+ def compute(self, cm, smooth = 10):
+ start = cm.findStart(self.minTime / 60000)
+
+ self.radius = cm.sectorRadius
+
+ self.points = [((line[7] - line[2])**2 + (line[8] - line[3])**2)**0.5
+ for line in cm.data[start:] if line[1] <= self.maxTime]
+
+ self.maxY = cm.radius * 2
+
+
+
class AngleGraph(Graphs, SvgGraph):
"graph depicting angle relative to the center of shock zone during the session"
def __init__(self, parent, cm = None, purpose = "graph"):
@@ -482,7 +506,11 @@ def compute(self, cm):
if line[1] > self.maxTime:
break
else:
- angle = (degrees(atan2(Cy - line[3], line[2] - Cx + 0.000001)) + 720 - CA) % 360
+ if m.mode == "RA":
+ angle = (degrees(atan2(line[8] - line[3],
+ line[2] - line[7] + 0.000001)) + 540) % 360
+ else:
+ angle = (degrees(atan2(Cy - line[3], line[2] - Cx + 0.000001)) + 720 - CA) % 360
if prev > 270 and angle < 90:
self.angles.append(360)
self.angles.append(0)
View
@@ -18,6 +18,7 @@
"""
from collections import OrderedDict
+from math import sqrt
import os
@@ -53,6 +54,8 @@ def __init__(self, nameA, nameR = "auto"):
with open(self.nameA, "r") as infile:
self._processArenaFile(infile) # rat file generally internally corresponds to arenafile
+ self.centerX = self.centerY = self.radius
+
# discards missing points from beginning of self.data
self._correctMissingFromBeginning()
@@ -99,6 +102,31 @@ def _cacheRemoval(self):
RA.cache.pop((self.nameA, self.nameR))
- def removeReflections(self, *args, bothframes = False, **kwargs):
- super().removeReflections(*args, bothframes = bothframes, **kwargs)
+ def removeReflections(self, points = None, deleteSame = True, bothframes = True):
+ if points == None:
+ ps = self.findReflections(time = "max", startTime = 0, results = "indices")
+ ps = ps[0] + ps[1]
+ ps += [line[0] for line in self.data if
+ sqrt((line[2] - line[7])**2 + (line[3] - line[8])**2) < 8]
+ else:
+ ps = points
+ super().removeReflections(points = ps, deleteSame = deleteSame, bothframes = True)
+
+
+
+ def _removalCondition(self, row, i, before, reflection):
+ """conditions in order of appearance:
+ large speed between the row and before row
+ same position as in the reflection row
+ we should expect the position to be closer to before row than to the
+ reflection row - determined by speed
+ wrong points in the row
+ """
+ old = self.data[row]
+ new = self.data[row + i]
+ return any((self._computeSpeed(new, before) > 250,
+ new[7:9] == old[7:9],
+ self._computeSpeed(reflection, new) * 30 < self._computeSpeed(before, new),
+ row + i in self.interpolated))
+

0 comments on commit d17fcb3

Please sign in to comment.