view 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
line wrap: on
line source

#! /usr/bin/env python

import utils, storage, prediction, events

import sys, argparse

import matplotlib.pyplot as plt
import numpy as np

from ConfigParser import ConfigParser

parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene')
parser.add_argument('configFilename', help = 'name of the configuration file')
# parser.add_argument('-c', help = 'name of the configuration file') # 
args = parser.parse_args()
print(args)
# TODO work on the way to indicate an interaction definition

# if False: # test if there is a configuration file?
params = utils.TrackingParameters()
params.loadConfigFile(args.configFilename)

# configuration parameters # TODO from command line
frameRate = 15  # frame per second
maxSpeed = 90/3.6/frameRate # speed limit 50 km/h for urban envt, 90km/hr = 25 m/sec for highways
timeHorizon= frameRate*5 # prediction time Horizon = 1.5 s (reaction time) (5 second)
collisionDistanceThreshold= 1.8 # m
computeCZ = True

# parameters for prediction methods
constantVelocityPredictionParameters = prediction.ConstantPredictionParameters(maxSpeed)

normalAdaptationPredictionParameters = prediction.NormalAdaptationPredictionParameters(maxSpeed, 100, 2./frameRate**2, # m/s2
                                                                                       0.2/frameRate) # rad/s

featurePredictionParameters = prediction.PointSetPredictionParameters(maxSpeed)

evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(maxSpeed, 100, -9.1/frameRate**2, # m/s2
                                                                                 4.3/frameRate**2, # m/s2
                                                                                 0.5/frameRate, # rad/s
                                                                                 False)

featureEvasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(maxSpeed, 10, -9.1/frameRate**2, # m/s2
                                                                                        4.3/frameRate**2, # m/s2
                                                                                        0.5/frameRate, # rad/s
                                                                                        True)



objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'object')
# features = storage.loadTrajectoriesFromSqlite('amherst-10.sqlite','feature') # needed if normal adaptation

interactions = events.createInteractions(objects)
for inter in interactions[:2]:
    inter.computeCrossingsCollisions(constantVelocityPredictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ)

plt.figure()
plt.axis('equal')
for inter in interactions[:2]:
    for collisionPoints in inter.collisionPoints.values():
        for cp in collisionPoints:
            plot([cp.x], [cp.y], 'x')

# for the demo, output automatically a map
# possibility to process longitudinal coords only