Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/safety-analysis.py @ 338:f3aceea2afbb
first safety analysis script
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 17 Jun 2013 16:26:11 -0400 |
| parents | dc2e68e936c7 |
| children | 74e437ab5f11 |
comparison
equal
deleted
inserted
replaced
| 337:dc2e68e936c7 | 338:f3aceea2afbb |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 | |
| 3 import utils, storage, prediction, events | |
| 2 | 4 |
| 3 import sys, argparse | 5 import sys, argparse |
| 4 | 6 |
| 5 import matplotlib.pyplot as plt | 7 import matplotlib.pyplot as plt |
| 6 import numpy as np | 8 import numpy as np |
| 7 | 9 |
| 8 from ConfigParser import ConfigParser | 10 from ConfigParser import ConfigParser |
| 9 | 11 |
| 10 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') | 12 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') |
| 13 parser.add_argument('configFilename', help = 'name of the configuration file') | |
| 14 # parser.add_argument('-c', help = 'name of the configuration file') # | |
| 11 args = parser.parse_args() | 15 args = parser.parse_args() |
| 12 print(args) | 16 print(args) |
| 13 # TODO work on the way to indicate an interaction definition | 17 # TODO work on the way to indicate an interaction definition |
| 14 | 18 |
| 15 if False:#len(args)>0: # consider there is a configuration file | 19 # if False: # test if there is a configuration file? |
| 16 params = utils.TrackingParameters() | 20 params = utils.TrackingParameters() |
| 17 params.loadConfigFile(args[0]) | 21 params.loadConfigFile(args.configFilename) |
| 22 | |
| 23 # configuration parameters # TODO from command line | |
| 24 frameRate = 15 # frame per second | |
| 25 maxSpeed = 90/3.6/frameRate # speed limit 50 km/h for urban envt, 90km/hr = 25 m/sec for highways | |
| 26 timeHorizon= frameRate*5 # prediction time Horizon = 1.5 s (reaction time) (5 second) | |
| 27 collisionDistanceThreshold= 1.8 # m | |
| 28 computeCZ = True | |
| 29 | |
| 30 # parameters for prediction methods | |
| 31 constantVelocityPredictionParameters = prediction.ConstantPredictionParameters(maxSpeed) | |
| 32 | |
| 33 normalAdaptationPredictionParameters = prediction.NormalAdaptationPredictionParameters(maxSpeed, 100, 2./frameRate**2, # m/s2 | |
| 34 0.2/frameRate) # rad/s | |
| 35 | |
| 36 featurePredictionParameters = prediction.PointSetPredictionParameters(maxSpeed) | |
| 37 | |
| 38 evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(maxSpeed, 100, -9.1/frameRate**2, # m/s2 | |
| 39 4.3/frameRate**2, # m/s2 | |
| 40 0.5/frameRate, # rad/s | |
| 41 False) | |
| 42 | |
| 43 featureEvasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(maxSpeed, 10, -9.1/frameRate**2, # m/s2 | |
| 44 4.3/frameRate**2, # m/s2 | |
| 45 0.5/frameRate, # rad/s | |
| 46 True) | |
| 18 | 47 |
| 19 | 48 |
| 20 | 49 |
| 50 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'object') | |
| 51 # features = storage.loadTrajectoriesFromSqlite('amherst-10.sqlite','feature') # needed if normal adaptation | |
| 52 | |
| 53 interactions = events.createInteractions(objects) | |
| 54 for inter in interactions[:2]: | |
| 55 inter.computeCrossingsCollisions(constantVelocityPredictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ) | |
| 56 | |
| 57 plt.figure() | |
| 58 plt.axis('equal') | |
| 59 for inter in interactions[:2]: | |
| 60 for collisionPoints in inter.collisionPoints.values(): | |
| 61 for cp in collisionPoints: | |
| 62 plot([cp.x], [cp.y], 'x') | |
| 21 | 63 |
| 22 # for the demo, output automatically a map | 64 # for the demo, output automatically a map |
| 23 | 65 # possibility to process longitudinal coords only |
| 24 | 66 |
