diff trafficintelligence/prediction.py @ 1269:ca70a79688ae

adding a speed threshold to avoid computing TTC at very low speeds
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 05 Jun 2024 10:12:43 -0400
parents 1b472cddf9b1
children
line wrap: on
line diff
--- a/trafficintelligence/prediction.py	Fri May 31 16:52:51 2024 -0400
+++ b/trafficintelligence/prediction.py	Wed Jun 05 10:12:43 2024 -0400
@@ -355,8 +355,9 @@
 
         return collisionPoints, crossingZones
 
-    def computeCrossingsCollisions(self, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None):#, nProcesses = 1):
-        '''Computes all crossing and collision points at each common instant for two road users. '''
+    def computeCrossingsCollisions(self, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None, speedThreshold = 0.):
+        '''Computes all crossing and collision points at each common instant for two road users. 
+        No movement prediction below a certain speedThreshold for both objects'''
         collisionPoints = {}
         if computeCZ:
             crossingZones = {}
@@ -366,13 +367,14 @@
             commonTimeInterval = timeInterval
         else:
             commonTimeInterval = obj1.commonTimeInterval(obj2)
-        #if nProcesses == 1:
-        for i in list(commonTimeInterval)[:-1]: # do not look at the 1 last position/velocities, often with errors
-            cp, cz = self.computeCrossingsCollisionsAtInstant(i, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ, debug)
-            if len(cp) != 0:
-                collisionPoints[i] = cp
-            if computeCZ and len(cz) != 0:
-                crossingZones[i] = cz
+        speedThreshold2 = max(0,speedThreshold)**2
+        for t in list(commonTimeInterval)[:-1]: # do not look at the 1 last position/velocities, often with errors
+            if obj1.getVelocityAtInstant(t).norm2Squared() > speedThreshold2 and obj2.getVelocityAtInstant(t).norm2Squared() > speedThreshold2:
+                cp, cz = self.computeCrossingsCollisionsAtInstant(t, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ, debug)
+                if len(cp) != 0:
+                    collisionPoints[t] = cp
+                if computeCZ and len(cz) != 0:
+                    crossingZones[t] = cz
         return collisionPoints, crossingZones
 
     def computeCollisionProbability(self, obj1, obj2, collisionDistanceThreshold, timeHorizon, debug = False, timeInterval = None):