新手求助,关于代码里的yield的问题
程序总体结构如下,想请教下关于 def simulate(self):函数里yield i 的意义,注释里说是没个i值程序跑一次,我想问下,每次i取一个值的时候,之前所有的函数都重新调用吗? 我想在每次i取值的时候,改变def sensorSetup(self)函数里 actSensor.attachTo('egoCar4')和 actSensor.attachTo('egoCar6')的命令可以吗? 菜鸟一只,各位高手帮帮忙阿? Ps,这个编译不了的,各位看看结构就行,谢谢import simplesim.configuration
from simplesim.Main.SimSetup import *
#we derive our simulation class from SimSetup.
class Pro_test(SimSetup):
"""
Basic simulation example. Creates a road and a vehicle body moving on it.
"""
def __init__(self):
#This is a must:
SimSetup.__init__(self)
# self.aweterrainmatfile = 'data\\AWE\\TestData\\asphalt_scs.mtl'
self.sensorActive = True #True
self.terrainfile = 'data\\AEM\\autobahn\\concrete_flatland.obj' # Strassenobjekt
self.aweterrainfile = 'data\\AEM\\autobahn\\concrete_flatland.obj'
self.aweterrainmatfile = 'data\\AEM\\autobahn\\concrete_flatland.mtl' # Material fuer die Strasse
self.egomesh = 'data\\AEM\\autobahn\\7070_MercedesBenz_Sprinter_ASCII.obj' # Darstellung von Auto
self.awemesh = 'data\\AEM\\autobahn\\Van_rotated_scaled_20080806.obj' # Autoobjekt fuer Raytracer
self.matagentfile = 'data\\AEM\\autobahn\\body.mtl'
def makeScene(self):
"""
Creates a RoadNetwork object.
See Example_Basic.makeScene(), we add guard rails in this example
"""
#Create a Kruemmungsband object with one clothoid segment.
k = Kruemmungsband()
#set start position orientation and curvature, use helper function deg2rad()
k.setStartValues( (0.0,0.0), 0.0, 0.0, 0.0)
k.addSegmentDerivCurvature(270.0, 0.0)
#Save the Kruemmungsband as object member variable
#so it can be used in other functions.
self.kruemmungsband = k
#Create a road object along the Kruemmungsband
oroad = OrnamentedRoad(k)
#Define the stripes for the road and add them to the OrnamentedRoad object
oroad.addStripe(RoadStripe(50.0), 'road')
oroad.addStripe(MittelStreifen(2.0), 'rechter mittelstreifen')
oroad.addStripe(MiddleDashStripe(-2.0), 'linker mittelstreifen')
oroad.addStripe(BorderStripe(6.0), 'rechter standstreifen')
oroad.addStripe(StandStreifen(-6.0), 'linker standstreifen')
oroad.addStripe(GruenStreifen(50.0), 'gelaende')
#define some helper variables:
postDistance = 8.0 #Abstand zwischen den Pfosten
lateralDistance = 8.0 #Abstand Fahrzeugmitte - Pfostenlinie
startOffset = 3.0 #Wegpunkt des ersten Pfostens
#create guard rail objects for left and right guardrails
leftRail = RailOrnament(-lateralDistance, 'left', postDistance, startOffset)
middelRail = RailOrnament(+lateralDistance, 'middel', postDistance, startOffset)
rightRail = RailOrnament(+24, 'right', postDistance, startOffset)
#configure guard rail objects:
[i.setAweMatfile('data\\AWE\\TestData\\Post_Mcs.mtl') for i in [leftRail,middelRail,rightRail]]
[i.setShowPlanes(True) for i in [leftRail,middelRail,rightRail]] #Leitplanken abschalten!
#place guardrail along road object
oroad.addOrnament(leftRail, 'leftRail')
oroad.addOrnament(middelRail, 'middelRail')
oroad.addOrnament(rightRail, 'rightRail')
return (k,RoadNetwork([oroad]))
def setup_ManyEgos(self):
"""
Setup the ego object.
"""
for i in range(1,6):
#using static agents (un-movable)
a = createAgent('Agents.StaticAgent','egoCar%d' % i)
# a.egoCarSetup = CarSetups.Mercedes_Sprinter(a)
a.setMesh(self.egomesh)
a.addWorld('AWEInterface',self.awemesh)
a.setAweMaterial(self.matagentfile)
a.addWorld('LogWorld','')
a.setTrajectoryObject(NewPosition(random.randint(1, 30)+i*50,0,0,180,0,0))
def setup_Radar(self):
#create a new radar simulation (using datetime as identifier)
self.aweComponent().setParam_useSimulation('date')
#wait for simulation results
self.aweComponent().setParam_openLoopSimulation(False)
#show interaction points of radar paths and environment
self.aweComponent().setParam_showInteractionPoints(False)
#set raytracer options (trace depth etc.)
self.aweComponent().setParam_options(AweDefaultOptions())
def sensorSetup(self):
if self.sensorActive:
actSensor = self.createSensor('Agents.Sensors.AweSensor','awesens_tx')
actSensor.setTrajectoryObject(NewPosition(-2.0,0.0,2.8))
#actSensor.setXYZ(-2.0,0.0,2.8)
actSensor.attachTo('egoCar4')
actSensor.SetSampleTime(1)
actSensor.deactivateReceiver()
actSensor = self.createSensor('Agents.Sensors.AweSensor','awesens_rx')
actSensor.setTrajectoryObject(NewPosition(-2.0,0.0,2.8))
##actSensor.setXYZ(-2.0,0.0,2.8)
actSensor.attachTo('egoCar6')
#actSensor.setTrajectoryObject(NewPosition(-489 , 43 , 1.5, 90,0.0,0.0))
actSensor.SetSampleTime(1)
actSensor.deactivateTransmitter()
self.getApplication().setScreenShotMode(False)
self.setup_Radar()
def setup(self):
"""
Setup the simulation. Add and configure agents, set simulation parameters, ...
"""
# self.setup_Ego()
self.setup_ManyEgos()
self.setup_Terrain()
self.setup_Camera()
# self.sensorSetup()
def simulate(self):
"""
Simulation loop, defines simulation times in milliseconds.
"""
#simulate 0 to 12 seconds in 100 ms steps
for i in range(0,12000,20):
yield i #calculate time step i
print i #print something to stdout
#import all simplesim packages
from importAll import *
#the "main" entry point:
if __name__ == "__main__":
doSim(Pro_test())