# HG changeset patch # User Nicolas Saunier # Date 1373523432 14400 # Node ID 619ae9a9a7881f528b7a50508e7f90f8072d54f0 # Parent c41ff9f3c263034c343ffb3aa647312a54d082ae implemented prediction method at constant velocity with direct intersection computation diff -r c41ff9f3c263 -r 619ae9a9a788 python/moving.py --- a/python/moving.py Thu Jul 11 00:17:25 2013 -0400 +++ b/python/moving.py Thu Jul 11 02:17:12 2013 -0400 @@ -30,6 +30,9 @@ def empty(self): return self.first > self.last + def center(self): + return (self.first+self.last)/2. + def length(self): '''Returns the length of the interval''' return float(max(0,self.last-self.first)) @@ -306,33 +309,39 @@ def similar(f1, f2, maxDistance2, maxDeltavelocity2): return (f1.position-f2.position).norm2Squared() 0 and moving.Point.dot(dp2, v2) > 0: # if the road users are moving towards the intersection + dist1 = dp1.norm2() + dist2 = dp2.norm2() + s1 = v1.norm2() + s2 = v2.norm2() + halfCollisionDistanceThreshold = collisionDistanceThreshold/2. + timeInterval1 = moving.TimeInterval(max(0,dist1-halfCollisionDistanceThreshold)/s1, (dist1+halfCollisionDistanceThreshold)/s1) + timeInterval2 = moving.TimeInterval(max(0,dist2-halfCollisionDistanceThreshold)/s2, (dist2+halfCollisionDistanceThreshold)/s2) + collisionTimeInterval = moving.TimeInterval.intersection(timeInterval1, timeInterval2) + if not collisionTimeInterval.empty(): + collisionPoints = [SafetyPoint(intersection, 1., collisionTimeInterval.center())] + else: + crossingZones = [SafetyPoint(intersection, 1., timeInterval1.distance(timeInterval2))] + + if debug and intersection!= None: + from matplotlib.pyplot import plot, figure, axis, title + figure() + plot([p1.x, intersection.x], [p1.y, intersection.y], 'r') + plot([p2.x, intersection.x], [p2.y, intersection.y], 'b') + intersection.draw() + obj1.draw('r') + obj2.draw('b') + title('instant {0}'.format(currentInstant)) + axis('equal') - @staticmethod - def save(out, points, predictionInstant, objNum1, objNum2): - for p in points: - out.write('{0} {1} {2} {3}\n'.format(objNum1, objNum2, predictionInstant, p)) + return collisionPoints, crossingZones - @staticmethod - def computeExpectedIndicator(points): - from numpy import sum - return sum([p.indicator*p.probability for p in points])/sum([p.probability for p in points]) + #### diff -r c41ff9f3c263 -r 619ae9a9a788 scripts/safety-analysis.py --- a/scripts/safety-analysis.py Thu Jul 11 00:17:25 2013 -0400 +++ b/scripts/safety-analysis.py Thu Jul 11 02:17:12 2013 -0400 @@ -12,7 +12,7 @@ parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') -parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity, normal adaptation, point set prediction)', choices = ['cv', 'na', 'ps']) +parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (vector computation), constant velocity, normal adaptation, point set prediction)', choices = ['cvd', 'cv', 'na', 'ps']) parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points') args = parser.parse_args() @@ -25,7 +25,9 @@ else: predictionMethod = params.predictionMethod -if predictionMethod == 'cv': +if predictionMethod == 'cvd': + predictionParameters = prediction.CVDirectPredictionParameters(params.maxPredictedSpeed) +elif predictionMethod == 'cv': predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) elif predictionMethod == 'na': predictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed,