comparison python/traffic_engineering.py @ 300:f65b828e5521

working on trajectory simulation
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 13 Feb 2013 18:26:49 -0500
parents 82b4101d9a2f
children 9d88a4d97473
comparison
equal deleted inserted replaced
299:7e5fb4abd070 300:f65b828e5521
9 ######################### 9 #########################
10 # Simulation 10 # Simulation
11 ######################### 11 #########################
12 12
13 class Vehicle: 13 class Vehicle:
14 'Generic vehicle class' 14 'Generic vehicle class
15 def __init__(self, position = 0, speed = 0, acceleration = 0, prt = 2.5, leader = None, log=True): 15 1D coordinates for now'
16 self.position = position 16 class PredictedTrajectory1D(prediction.PredictedTrajectory):
17 self.speed = speed 17 def __init__(self, initialPosition, initialSpeed, control, maxSpeed = None):
18 self.acceleration = acceleration 18 self.control = control
19 self.maxSpeed = maxSpeed
20 self.probability = None
21 self.predictedPositions = {0: moving.Point(initialPosition)}
22 self.predictedSpeedOrientations = {0: moving.NormAngle(initialSpeed, 0)}
23
24 def setAcceleration(self, acceleration):
25 self.control = moving.NormAngle(acceleration, 0)
26
27 def getControl(self):
28 return self.control
29
30
31 def __init__(self, initialPosition = 0, initialSpeed = 0, acceleration = 0, prt = 2.5, leader = None):
32 self.positions = PredictedTrajectory1D(initialPosition, initialSpeed)
33
19 self.prt = prt 34 self.prt = prt
20 self.leader = leader 35 self.leader = leader
21 self.log = log 36 # todo add microModel (Treiber)
22 if log: 37
23 self.positions = [position] 38 def setAcceleration(self, acceleration):
24 self.speeds = [speed] 39 self.positions.setAcceleration(acceleration)
25 self.accelerations = [acceleration] 40
26 # todo add microModel 41 def updatePosition(self, dt): # knowledge of time outside of vehicle ??
27
28 def updatePosition(self, dt):
29 speed = self.speed 42 speed = self.speed
30 self.speed += self.acceleration*dt 43 self.speed += self.acceleration*dt
31 self.position += speed*dt 44 self.position += speed*dt
32 if self.log: 45 if self.log:
33 self.positions.append(self.position) 46 self.positions.append(self.position)