view scripts/safety-analysis.py @ 343:74e437ab5f11

first version of indicator loading code
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 21 Jun 2013 15:28:59 -0400
parents f3aceea2afbb
children 14a2405f54f8
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

display = False

# 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.computeIndicators()
    # inter.computeCrossingsCollisions(constantVelocityPredictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ)

storage.saveIndicators(params.databaseFilename, interactions)

if display:
    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