Пример #1
0
    # with simulation_only:
    #     V_c = vc_rlc(pwm_v, R, L, C)

    err = bd.SUM('+-', reference, adc)
    register_err(err)

    return adc, err, duty, pwm_v


if __name__ == "__main__":

    bd = BDSim().blockdiagram()

    with bdsim_realtime.tuning.TcpClientTuner() as tuner:

        target = bd.TUNABLE_WAVEFORM("sine", offset=1, tinker=True)

        adc, err, duty, _pwm_v = control_rlc(bd, target, DEFAULT_KP,
                                             DEFAULT_KI)

    bd.TUNERSCOPE(target,
                  adc,
                  err,
                  duty,
                  nin=4,
                  labels=['Target', 'ADC', 'Error', 'Duty %'],
                  name='PID Tuning live feedback',
                  tuner=tuner)

    bdsim_realtime.run(bd, tuner=tuner)
Пример #2
0
sine = bd.WAVEFORM('sine')
sine_neg_2 = bd.GAIN(-2, sine)
sine3 = bd.GAIN(3, sine)

# create a socket transport pair
send_socket, recv_socket = socket.socketpair()

# initialize the DATASENDER in another thread because it blocks until the handshake
thread = threading.Thread(target=bd.DATASENDER,
                          args=(send_socket.makefile('rwb'), sine, sine_neg_2,
                                sine3),
                          kwargs=dict(nin=3, clock=bd.clock(50, 'Hz')))
thread.start()

# this should wait for the handshake triggered by the previous thread
receiver = bd.DATARECEIVER(
    recv_socket.makefile('rwb'),
    nout=3,
    # offset it by 30ms from sender's clock; so the sender executes at least once and this executes 10ms afterwards
    clock=bd.clock(50, 'Hz', offset=0.03))

# the thread must be finished at this point
thread.join(0)

# finally write the results to a CSV
csv_writer = bd.CSV(open('bdsim-dataout.csv', 'w'), receiver[0:3], nin=3)

# lets jam!
bdsim_realtime.run(bd)