还是关于那个yield的问题,删去了部分不必要的程序,加了些注释,还望高手赐教
import simplesim.configuration
from simplesim.Main.SimSetup import *
#we derive our simulation class from SimSetup.
class Pro_test(SimSetup): #类定义
"""
def setup_ManyEgos(self): #这个函数产生5辆车,egoCar1.......egoCar5,并设置了相应的属性
"""
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.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 20 ms steps
for i in range(0,12000,20): # 这里是我想问的地方,每过20ms后,我想改变sensorSetup里面设置
yield i #calculate time step i #这个yield到底该怎么用呢?
print i #print something to stdout
#import all simplesim packages
from importAll import *
#the "main" entry point:
if __name__ == "__main__":
doSim(Pro_test())
是不是可以在def simulate(self):函数里,每次执行的时候调用sensorSetup(self): "egoCar"的ID值传过去呢?