Exemplo n.º 1
0
    def __init__(self):
        '''
        A basic simulation that sums two (default) Ramp sources 
        together and plots the combined output.
        '''
        connection1, connection2, connection3 = MakeChans(3)

        src1 = Ramp(connection1)
        src2 = Ramp(connection2)

        summer = Summer([connection1, connection2], connection3)
        dst = Plotter(connection3, title="Double Ramp Sum")

        self.components = [src1, src2, summer, dst]
    def __init__(self, res=10, simulation_length=40):
        super(DelayedRampSum, self).__init__()

        conns = MakeChans(5)

        src1 = Ramp(conns[0], resolution=res, simulation_time=simulation_length)
        src2 = Ramp(conns[1], resolution=res, simulation_time=simulation_length)
        src3 = RandomSource(conns[2], resolution=res, simulation_time=simulation_length)

        # The following "magic number" is one time step, (1/res)
        # the delay must be an integer factor of this so the events line up 
        # for the summer block to work...
        time_step = 1.0 / res
        delay1 = Delay(conns[1], conns[4], 3 * time_step)

        summer = Summer([conns[0], conns[4], conns[2]], conns[3])
        dst = Plotter(conns[3])

        self.components = [src1, src2, src3, summer, dst, delay1]
Exemplo n.º 3
0
    def __init__(self):
        chan1, chan2, chan3 = MakeChans(3)

        src1 = Ramp(chan1)
        src2 = CTSinGenerator(chan2, amplitude=1.0, freq=1.0)

        summer = Summer([chan1, chan2], chan3)
        dst = Plotter(chan3, title="Sin+Ramp")

        self.components = [src1, src2, summer, dst]
Exemplo n.º 4
0
    def __init__(self):
        '''Create the components'''
        super(RampPlot, self).__init__()
        connection = Channel()
        src = Ramp(connection)
        dst = Plotter(connection,
                      xlabel='Time (s)',
                      ylabel='Amplitude',
                      title='Ramp Plot')

        self.components = [src, dst]
Exemplo n.º 5
0
    def __init__(self):
        '''Setup the sim'''
        super(RampGainPlot, self).__init__()
        ramp2gain = Channel()
        gain2plot = Channel()

        src = Ramp(ramp2gain)
        filt = Proportional(ramp2gain, gain2plot)
        dst = Plotter(gain2plot)

        self.components = [src, filt, dst]
Exemplo n.º 6
0
 def __init__(self,
              out,
              amplitude=1.0,
              freq=1.0,
              phi=0.0,
              timestep=0.001,
              simulation_time=10):
     super(CTSinGenerator, self).__init__(output_channel=out)
     self.chan = Channel()
     self.ramp = Ramp(self.chan,
                      resolution=1.0 / timestep,
                      simulation_time=simulation_time)
     self.sin = Sin(self.chan,
                    self.output_channel,
                    amplitude=amplitude,
                    freq=freq,
                    phi=phi)
Exemplo n.º 7
0
    def __init__(self):
        '''Setup the simulation'''
        connection1 = Channel()
        connection2 = Channel()
        connection3 = Channel()
        connection4 = Channel()

        src1 = Ramp(connection1)
        src2 = RandomSource(connection2)
        summer = Summer([connection1, connection2], connection3)

        bundler = Bundle(connection3, connection4)
        dst = BundlePlotter(connection4,
                            title="Scipy-Simulation: Noise + Ramp Sum",
                            show=True)
        #dst = Plotter(connection3)

        self.components = [src1, src2, summer, bundler, dst]
Exemplo n.º 8
0
    def __init__(self,
                 out,
                 amplitude=1.0,
                 freq=0.01,
                 phi=0.0,
                 simulation_length=100):
        '''
        Construct a discrete sin generator model.
        
        @param out: output channel
        '''
        super(DTSinGenerator, self).__init__(output_channel=out)

        logging.debug("Setting model paramaters.")
        self.amplitude = amplitude
        self.frequency = freq
        self.phase = phi
        self.simulation_length = simulation_length

        assert out.domain is "DT"

        logging.info('Constructing the inner actors that make up this "model"')
        self.chan1 = Channel()

        # The values of the ramp will be ignored, it just provides the "clock"
        self.ramp = Ramp(self.chan1,
                         resolution=1,
                         simulation_time=self.simulation_length)
        # Note in this case we have connected the output of the last inner component directly to
        # the output of the model - this isn't always going to be the case.
        self.sin = Sin(self.chan1,
                       self.output_channel,
                       amplitude=self.amplitude,
                       freq=self.frequency,
                       phi=self.phase)
        logging.info("Inner actors have been constructed")
Exemplo n.º 9
0
    def __init__(self, simulation_length=0.02, simulation_resolution=10000):
        self.sim_time = simulation_length
        self.sim_res = simulation_resolution

        wire_names = ('ramp', 'sin', 'const_offset', 'offset_sin',
                      'ramp_probe', 'ramp_plot', 'offset_sin_probe',
                      'sin_plot', 'diff', 'pwm_bool', 'on_value', 'off_value',
                      'pwm_value')
        raw_wires = MakeChans(len(wire_names))

        wires = dict(zip(wire_names, raw_wires))

        ramp_src = Ramp(wires['ramp_probe'],
                        freq=500,
                        simulation_time=self.sim_time,
                        resolution=self.sim_res)
        sin_src = CTSinGenerator(wires['sin'],
                                 amplitude=0.5,
                                 freq=50.0,
                                 phi=0.0,
                                 timestep=1.0 / self.sim_res,
                                 simulation_time=self.sim_time)
        const_src = Constant(wires['const_offset'],
                             0.5,
                             resolution=self.sim_res,
                             simulation_time=self.sim_time)

        offset_sin_sum = Summer([wires['sin'], wires['const_offset']],
                                wires['offset_sin_probe'])
        ramp_cloning_probe = Split(wires['ramp_probe'],
                                   [wires['ramp'], wires['ramp_plot']])
        sin_cloning_probe = Split(wires['offset_sin_probe'],
                                  [wires['offset_sin'], wires['sin_plot']])

        # Output = sin - ramp
        subtractor = Summer([wires['offset_sin'], (wires['ramp'], '-')],
                            wires['diff'])

        # Want to see when that is > 0
        comparison = GreaterThan(wires['diff'],
                                 wires['pwm_bool'],
                                 threshold=0.0,
                                 boolean_output=True)
        if_device = PassThrough(wires['pwm_bool'],
                                wires['on_value'],
                                wires['pwm_value'],
                                else_data_input=wires['off_value'])
        output_value_on = Constant(wires['on_value'],
                                   1.0,
                                   resolution=self.sim_res,
                                   simulation_time=self.sim_time)
        output_value_off = Constant(wires['off_value'],
                                    0.0,
                                    resolution=self.sim_res,
                                    simulation_time=self.sim_time)

        self.components = [
            ramp_src, sin_src, const_src, offset_sin_sum, ramp_cloning_probe,
            sin_cloning_probe, subtractor, comparison, if_device,
            output_value_on, output_value_off
        ]

        ramp_out = TextWriter(wires['ramp_plot'], 'ramp_values')
        sin_out = TextWriter(wires['sin_plot'], 'sine_values')
        pwm_out = TextWriter(wires['pwm_value'], 'pwm_values')
        self.components.append(ramp_out)
        self.components.append(sin_out)
        self.components.append(pwm_out)