Mercurial Hosting > traffic-intelligence
changeset 881:8ba82b371eea
work on storing PET
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 14 Mar 2017 17:48:40 -0400 |
parents | 000555430b28 |
children | 4749b71aa7fb |
files | python/events.py python/moving.py python/prediction.py scripts/safety-analysis.py |
diffstat | 4 files changed, 32 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/python/events.py Tue Mar 14 17:10:35 2017 -0400 +++ b/python/events.py Tue Mar 14 17:48:40 2017 -0400 @@ -63,7 +63,8 @@ 'Collision Probability', 'Time to Collision', # 7 'Probability of Successful Evasive Action', - 'predicted Post Encroachment Time'] + 'predicted Post Encroachment Time', + 'Post Encroachment Time'] indicatorNameToIndices = utils.inverseEnumeration(indicatorNames) @@ -76,7 +77,8 @@ 'PoC', 'TTC', 'P(SEA)', - 'pPET'] + 'pPET', + 'PET'] indicatorUnits = ['', 'rad', @@ -87,7 +89,8 @@ '', 's', '', - ''] + 's', + 's'] timeIndicators = ['Time to Collision', 'predicted Post Encroachment Time'] @@ -235,7 +238,9 @@ def computePET(self, collisionDistanceThreshold): # TODO add crossing zone - self.pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) + pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) + if pet is not None: # TODO get crossing zone and time + self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[10], {0: pet}, mostSevereIsMax = False def setCollision(self, collision): '''indicates if it is a collision: argument should be boolean'''
--- a/python/moving.py Tue Mar 14 17:10:35 2017 -0400 +++ b/python/moving.py Tue Mar 14 17:48:40 2017 -0400 @@ -340,16 +340,15 @@ ttc1 = (-b + deltaRoot)/(2*a) ttc2 = (-b - deltaRoot)/(2*a) if ttc1 >= 0 and ttc2 >= 0: - ttc = min(ttc1,ttc2) + return min(ttc1,ttc2) elif ttc1 >= 0: - ttc = ttc1 + return ttc1 elif ttc2 >= 0: - ttc = ttc2 + return ttc2 else: # ttc1 < 0 and ttc2 < 0: - ttc = None + return None else: - ttc = None - return ttc + return None @staticmethod def midPoint(p1, p2): @@ -1428,9 +1427,6 @@ '''Post-encroachment time based on distance threshold Returns the smallest time difference when the object positions are within collisionDistanceThreshold''' - #for i in xrange(int(obj1.length())-1): - # for j in xrange(int(obj2.length())-1): - # inter = segmentIntersection(obj1.getPositionAt(i), obj1.getPositionAt(i+1), obj2.getPositionAt(i), obj2.getPositionAt(i+1)) positions1 = [p.astuple() for p in obj1.getPositions()] positions2 = [p.astuple() for p in obj2.getPositions()] pets = zeros((int(obj1.length()), int(obj2.length()))) @@ -1439,6 +1435,7 @@ pets[i,j] = abs(t1-t2) distances = cdist(positions1, positions2, metric = 'euclidean') if distances.min() <= collisionDistanceThreshold: + #idx = distances.argmin() return pets[distances <= collisionDistanceThreshold].min() else: return None
--- a/python/prediction.py Tue Mar 14 17:10:35 2017 -0400 +++ b/python/prediction.py Tue Mar 14 17:48:40 2017 -0400 @@ -558,9 +558,9 @@ PredictionParameters.__init__(self, 'constant velocity (direct exact computation)', None) def computeCrossingsCollisionsAtInstant(self, currentInstant, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, *kwargs): - 'TODO add collision point coordinates, compute pPET' - #collisionPoints = [] - #crossingZones = [] + 'TODO compute pPET' + collisionPoints = [] + crossingZones = [] p1 = obj1.getPositionAtInstant(currentInstant) p2 = obj2.getPositionAtInstant(currentInstant) @@ -570,10 +570,12 @@ if intersection is not None: ttc = moving.Point.timeToCollision(p1, p2, v1, v2, collisionDistanceThreshold) - if ttc: - return currentInstant, [SafetyPoint(intersection, 1., ttc)], [] # (p1+v1.multiply(ttc)+p2+v2.multiply(ttc)).multiply(0.5) + if ttc is not None: + collisionPoints = SafetyPoint(intersection, 1., ttc) else: - return currentInstant, [],[] + pass # compute pPET + + return currentInstant, collisionPoints, crossingZones #### # Other Methods
--- a/scripts/safety-analysis.py Tue Mar 14 17:10:35 2017 -0400 +++ b/scripts/safety-analysis.py Tue Mar 14 17:48:40 2017 -0400 @@ -14,7 +14,8 @@ parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to analyse', type = int) # TODO analyze only -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('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps']) +parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) args = parser.parse_args() @@ -32,8 +33,10 @@ def steeringDistribution(): return random.triangular(-params.maxNormalSteering, params.maxNormalSteering, 0.) -if predictionMethod == 'cvd': # TODO add cve: constant velocity exact (Sohail's) +if predictionMethod == 'cvd': predictionParameters = prediction.CVDirectPredictionParameters() +if predictionMethod == 'cve': + predictionParameters = prediction.CVExactPredictionParameters() elif predictionMethod == 'cv': predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) elif predictionMethod == 'na': @@ -64,6 +67,10 @@ inter.computeIndicators() inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, nProcesses = args.nProcesses) +if args.computePET: + for inter in Interactions: + inter.computePET() + storage.saveIndicators(params.databaseFilename, interactions) if args.displayCollisionPoints: