示例#1
0
    def __init__(self,
                 source_streams,
                 noise_streams,
                 rir_streams,
                 config,
                 DEBUG=False):
        """
        :param source_streams: a list of SpeechDataStream objects, containing the clean speech source files names and
        meta-data such as label, utterance ID, and speaker ID.
        :param noise_streams: a list of DataStream objects, containing noise file names.
        :param rir_streams: a list of RIRDataStream objects, containing RIR file names and meta data information.
        :param config: an object of type DataGeneratorSequenceConfig
        :param DEBUG: if set to DEBUG mode, will plot the filterbanks and label.
        """
        self._source_streams = source_streams
        self._source_streams_prior = self._get_streams_prior(source_streams)
        self._rir_streams = rir_streams
        self._rir_streams_prior = self._get_streams_prior(rir_streams)
        self._noise_streams = noise_streams
        self._noise_streams_prior = self._get_streams_prior(noise_streams)

        self._data_len = config.n_segment_per_epoch
        self._single_source_simulator = SimpleSimulator(
            use_rir=config.use_reverb,
            use_noise=config.use_noise,
            snr_range=config.snr_range)
        self._config = config
        self._DEBUG = DEBUG
        self._gen_window()
示例#2
0
    def __init__(self,world,name="My GL simulation program"):
        """Arguments:
        - world: a RobotWorld instance.
        """
        GLRealtimeProgram.__init__(self,name)
        self.world = world
        #Put your initialization code here
        #the current example creates a collision class, simulator, 
        #simulation flag, and screenshot flags
        self.collider = robotcollide.WorldCollider(world)
        self.sim = SimpleSimulator(world)
        self.simulate = False
        self.commanded_config_color = [0,1,0,0.5]

        #turn this on to draw contact points
        self.drawContacts = False

        #turn this on to save screenshots
        self.saveScreenshots = False
        self.nextScreenshotTime = 0
        self.screenshotCount = 0
        self.verbose = 0

        #turn this on to save log to disk
        self.logging = False
        self.logger = None
示例#3
0
def doSim(world,
          duration,
          initialCondition,
          returnItems=None,
          trace=False,
          simDt=0.01,
          simInit=None,
          simStep=None,
          simTerm=None):
    """Runs a simulation for a given initial condition of a world.

    Arguments:
    - world: the world
    - duration: the maximum duration of simulation, in seconds
    - initialCondition: a dictionary mapping named items to values.
      Each named item is specified by a path as used by the map module, e.g.
      'robot[0].config[4]'.  See the documentation for map.get_item()/
      map.set_item() for details.

      Special items include 'args' which is a tuple provided to each simInit,
      simStep, and simTerm call.
    - returnItems (optional): a list of named items to return in the final
      state of the simulation.  By default returns everything that is
      variable in the simulator (simulation time, robot and rigid object
      configuration / velocity, robot commands, robot sensors).
    - trace (optional, default False): if True, returns the entire trace of
      the items specified in returnItems rather than just the final state.
    - simDt (optional, default 0.01): the outer simulation loop (usually
      corresponds to the control rate).
    - simInit (optional): a function f(sim) called on the simulator after its
      initial conditions are set but before simulating. You may configure the
      simulator with this function.
    - simStep (optional): a function f(sim) that is called on every outer
      simulation loop (usually a controller function).
    - simTerm (optional): a function f(sim) that returns True if the simulation
      should terminate early.  Called on every outer simulation loop.

    Return value is the final state of each returned item upon termination. 
    This takes the form of a dictionary mapping named items (specified by
    the returnItems argument) to their values. 
    Additional returned items are:
    - 'status', which gives the status string of the simulation
    - 'time', which gives the time of the simulation, in s
    - 'wall_clock_time', which gives the time elapsed while computing the simulation, in s
    """
    if returnItems == None:
        #set up default return items
        returnItems = []
        for i in range(world.numRigidObjects()):
            returnItems.append('rigidObjects[' + str(i) + '].transform')
            returnItems.append('rigidObjects[' + str(i) + '].velocity')
        for i in range(world.numRobots()):
            returnItems.append('time')
            returnItems.append('controllers[' + str(i) + '].commandedConfig')
            returnItems.append('controllers[' + str(i) + '].commandedVelocity')
            returnItems.append('controllers[' + str(i) + '].sensedConfig')
            returnItems.append('controllers[' + str(i) + '].sensedVelocity')
            returnItems.append('controllers[' + str(i) + '].sensors')
            returnItems.append('robots[' + str(i) + '].actualConfig')
            returnItems.append('robots[' + str(i) + '].actualVelocity')
            returnItems.append('robots[' + str(i) + '].actualTorques')
    initCond = getWorldSimState(world)
    args = ()
    for k, v in initialCondition.iteritems():
        if k is not 'args':
            map.set_item(world, k, v)
        else:
            args = v
    sim = SimpleSimulator(world)
    if simInit: simInit(sim, *args)
    assert simDt > 0, "Time step must be positive"
    res = dict()
    if trace:
        for k in returnItems:
            res[k] = [map.get_item(sim, k)]
        res['status'] = [sim.getStatusString()]
    print "klampt.batch.doSim(): Running simulation for", duration, "s"
    t0 = time.time()
    t = 0
    worst_status = 0
    while t < duration:
        if simTerm and simTerm(sim, *args) == True:
            if not trace:
                for k in returnItems:
                    res[k] = map.get_item(sim, k)
                res['status'] = sim.getStatusString(worst_status)
                res['time'] = t
                res['wall_clock_time'] = time.time() - t0
            #restore initial world state
            setWorldSimState(world, initCond)
            print "  Termination condition reached at", t, "s"
            print "  Computation time:", time.time() - t0
            return res
        if simStep: simStep(sim, *args)
        sim.simulate(simDt)
        worst_status = max(worst_status, sim.getStatus())
        if trace:
            for k in returnItems:
                res[k].append(map.get_item(sim, k))
            res['status'].append(sim.getStatusString())
            res['time'] = t
            res['wall_clock_time'] = time.time() - t0
        t += simDt
    if not trace:
        #just get the terminal stats
        for k in returnItems:
            res[k] = map.get_item(sim, k)
        res['status'] = sim.getStatusString(worst_status)
        res['time'] = t
        res['wall_clock_time'] = time.time() - t0

    print "  Done."
    print "  Computation time:", time.time() - t0
    #restore initial world state
    setWorldSimState(world, initCond)
    return res