comparison python/prediction.py @ 387:91679eb2ff2c

cleaning up safety analysis and the new traditional constant velocity method
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 24 Jul 2013 12:48:12 -0400
parents 619ae9a9a788
children 55b424d98b68
comparison
equal deleted inserted replaced
386:8bc632cb8344 387:91679eb2ff2c
311 311
312 class CVDirectPredictionParameters(PredictionParameters): 312 class CVDirectPredictionParameters(PredictionParameters):
313 '''Prediction parameters of prediction at constant velocity 313 '''Prediction parameters of prediction at constant velocity
314 using direct computation of the intersecting point''' 314 using direct computation of the intersecting point'''
315 315
316 def __init__(self, maxSpeed): 316 def __init__(self):
317 PredictionParameters.__init__(self, 'constant velocity (direct computation)', maxSpeed) 317 PredictionParameters.__init__(self, 'constant velocity (direct computation)', None)
318 318
319 def computeCrossingsCollisionsAtInstant(self, currentInstant, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False): 319 def computeCrossingsCollisionsAtInstant(self, currentInstant, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False):
320 collisionPoints = [] 320 collisionPoints = []
321 crossingZones = [] 321 crossingZones = []
322 322
339 s2 = v2.norm2() 339 s2 = v2.norm2()
340 halfCollisionDistanceThreshold = collisionDistanceThreshold/2. 340 halfCollisionDistanceThreshold = collisionDistanceThreshold/2.
341 timeInterval1 = moving.TimeInterval(max(0,dist1-halfCollisionDistanceThreshold)/s1, (dist1+halfCollisionDistanceThreshold)/s1) 341 timeInterval1 = moving.TimeInterval(max(0,dist1-halfCollisionDistanceThreshold)/s1, (dist1+halfCollisionDistanceThreshold)/s1)
342 timeInterval2 = moving.TimeInterval(max(0,dist2-halfCollisionDistanceThreshold)/s2, (dist2+halfCollisionDistanceThreshold)/s2) 342 timeInterval2 = moving.TimeInterval(max(0,dist2-halfCollisionDistanceThreshold)/s2, (dist2+halfCollisionDistanceThreshold)/s2)
343 collisionTimeInterval = moving.TimeInterval.intersection(timeInterval1, timeInterval2) 343 collisionTimeInterval = moving.TimeInterval.intersection(timeInterval1, timeInterval2)
344 if not collisionTimeInterval.empty(): 344 if computeCZ and collisionTimeInterval.empty():
345 crossingZones = [SafetyPoint(intersection, 1., timeInterval1.distance(timeInterval2))]
346 else:
345 collisionPoints = [SafetyPoint(intersection, 1., collisionTimeInterval.center())] 347 collisionPoints = [SafetyPoint(intersection, 1., collisionTimeInterval.center())]
346 else:
347 crossingZones = [SafetyPoint(intersection, 1., timeInterval1.distance(timeInterval2))]
348 348
349 if debug and intersection!= None: 349 if debug and intersection!= None:
350 from matplotlib.pyplot import plot, figure, axis, title 350 from matplotlib.pyplot import plot, figure, axis, title
351 figure() 351 figure()
352 plot([p1.x, intersection.x], [p1.y, intersection.y], 'r') 352 plot([p1.x, intersection.x], [p1.y, intersection.y], 'r')