Mercurial Hosting > traffic-intelligence
comparison scripts/safety-analysis.py @ 352:72aa44072093
safety analysis script with option for prediction method
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 27 Jun 2013 01:35:47 -0400 |
parents | 891858351bcb |
children | e5fe0e6d48a1 |
comparison
equal
deleted
inserted
replaced
351:891858351bcb | 352:72aa44072093 |
---|---|
7 import matplotlib.pyplot as plt | 7 import matplotlib.pyplot as plt |
8 import numpy as np | 8 import numpy as np |
9 | 9 |
10 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') | 10 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') |
11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') | 11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') |
12 #parser.add_argument('--maxspeed', dest = 'maxSpeed', help = 'maximum speed when predicting future motion (km/h)', default = 50, type = int) | 12 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity, normal adaptation, point set prediction)', choices = ['cv', 'na', 'ps']) |
13 #parser.add_argument('--time-horizon', dest = 'maxSpeed', help = 'maximum speed when predicting future motion (km/h)', default = 50, type = int) | |
14 args = parser.parse_args() | 13 args = parser.parse_args() |
15 | 14 |
16 # TODO work on the way to indicate an interaction definition | |
17 | |
18 # if False: # test if there is a configuration file? | |
19 params = utils.TrackingParameters() | 15 params = utils.TrackingParameters() |
20 params.loadConfigFile(args.configFilename) | 16 params.loadConfigFile(args.configFilename) |
21 | 17 |
22 # parameters for prediction methods | 18 # parameters for prediction methods |
23 constantVelocityPredictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) | 19 if args.predictionMethod: |
20 predictionMethod = args.predictionMethod | |
21 else: | |
22 predictionMethod = params.predictionMethod | |
24 | 23 |
25 normalAdaptationPredictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed, | 24 if predictionMethod == 'cv': |
26 params.nPredictedTrajectories, | 25 predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) |
27 params.maxAcceleration, | 26 elif predictionMethod == 'na': |
28 params.maxSteering, | 27 predictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed, |
29 params.useFeaturesForPrediction) | 28 params.nPredictedTrajectories, |
30 | 29 params.maxAcceleration, |
31 featurePredictionParameters = prediction.PointSetPredictionParameters(params.maxPredictedSpeed, | 30 params.maxSteering, |
32 params.nPredictedTrajectories) | 31 params.useFeaturesForPrediction) |
32 elif predictionMethod == 'ps': | |
33 predictionParameters = prediction.PointSetPredictionParameters(params.nPredictedTrajectories, | |
34 params.maxPredictedSpeed) | |
35 else: | |
36 print('Prediction method {} is not valid. See help.'.format(predictionMethod)) | |
37 sys.exit() | |
33 | 38 |
34 evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, | 39 evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, |
35 params.nPredictedTrajectories, | 40 params.nPredictedTrajectories, |
36 params.minAcceleration, | 41 params.minAcceleration, |
37 params.maxAcceleration, | 42 params.maxAcceleration, |
38 params.maxSteering, | 43 params.maxSteering, |
39 params.useFeaturesForPrediction) | 44 params.useFeaturesForPrediction) |
40 | 45 |
41 featureEvasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, | |
42 params.nPredictedTrajectories, | |
43 params.minAcceleration, | |
44 params.maxAcceleration, | |
45 params.maxSteering, | |
46 params.useFeaturesForPrediction) | |
47 | |
48 | |
49 | |
50 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'object') | 46 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'object') |
51 # features = storage.loadTrajectoriesFromSqlite('amherst-10.sqlite','feature') # needed if normal adaptation | 47 if params.useFeaturesForPrediction: |
48 features = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'feature') # needed if normal adaptation | |
49 for obj in objects: | |
50 obj.setFeatures(features) | |
52 | 51 |
53 interactions = events.createInteractions(objects) | 52 interactions = events.createInteractions(objects) |
54 for inter in interactions: | 53 for inter in interactions[:1]: |
55 inter.computeIndicators() | 54 inter.computeIndicators() |
56 inter.computeCrossingsCollisions(constantVelocityPredictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones) | 55 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones) |
57 | 56 |
58 storage.saveIndicators(params.databaseFilename, interactions) | 57 storage.saveIndicators(params.databaseFilename, interactions) |
59 | 58 |
60 # if display: | 59 if False: |
61 # plt.figure() | 60 plt.figure() |
62 # plt.axis('equal') | 61 plt.axis('equal') |
63 # for inter in interactions[:2]: | 62 for inter in interactions: |
64 # for collisionPoints in inter.collisionPoints.values(): | 63 for collisionPoints in inter.collisionPoints.values(): |
65 # for cp in collisionPoints: | 64 for cp in collisionPoints: |
66 # plot([cp.x], [cp.y], 'x') | 65 plt.plot([cp.x], [cp.y], 'x') |
67 | |
68 # for the demo, output automatically a map | |
69 # possibility to process longitudinal coords only | |
70 | 66 |