| optoMDC

Loading...
Searching...
No Matches
MR-E-2 Advanced Examples

Download a saved vector from the board.

    import optoMDC
    mre2 = optoMDC.connect()

    start_address, num_elements = 0, 1024
    vector = mre2.VectorPatternMemory.GetPatternSegment(start_address, num_elements)

Set a DC output.

    import optoMDC
    mre2 = optoMDC.connect()

    # pick some value for current
    amplitude_A = 0.250

    static = mre2.Mirror.Channel_0.StaticInput
    static.SetAsInput()
    static.SetCurrent(amplitude_A)

Output an impulse on one axis/channel.

    import optoMDC
    mre2 = optoMDC.connect()

    # pick a channel, amplitude, and impulse duration
    channel = 1
    amplitude_A = 0.07
    duration_ms = 1.0

    sig_gen = mre2.channel[channel].SignalGenerator
    sig_gen.SetAsInput()
    sig_gen.SetShape(optoMDC.WaveformShape.PULSE)
    sig_gen.SetFrequency(1 / (2 * duration_ms / 1000))  # /1000 to convert to seconds
    sig_gen.SetAmplitude(amplitude_A)
    sig_gen.SetDutyCycle(0.5)
    sig_gen.SetCycles(1)
    sig_gen.SetUnit(optoMDC.UnitType.CURRENT)
    sig_gen.Run()

Upload a trapezoidal vector to the board.

    import numpy as np
    import optoMDC
    mre2 = optoMDC.connect()

    # The hard part... building a vector.
    # ----------------------------------
    # pick a frequency, trans time, amplitude, and phase
    frequency_Hz = 50
    time_transition_ms = 2
    amplitude_A = 0.1
    phase_deg = 0.0
    # calculate number of samples
    period = 1 / frequency_Hz
    num_samples = period * optoMDC.SAMPLING_FREQ
    # we want an even number of samples per period, so it can be divided in two halves
    num_samples = round(num_samples / 2.0) * 2
    half_num_samples = num_samples // 2
    # samples in transition and holding time
    nsamples_tr = round(time_transition_ms / 1000 * optoMDC.SAMPLING_FREQ)
    nsamples_hold = half_num_samples - nsamples_tr
    # linspace takes both start and stop points, we need to discard the stop point and add one more sample point,
    # so we use nsamples+1 and discard the last element of the vector [:-1]
    vector = list(np.linspace(start=-amplitude_A, stop=amplitude_A, num=nsamples_tr + 1)[:-1]) \
             + [amplitude_A] * nsamples_hold \
             + list(np.linspace(start=amplitude_A, stop=-amplitude_A, num=nsamples_tr + 1)[:-1]) \
             + [-amplitude_A] * nsamples_hold
    break_idx = round(phase_deg / 360.0 * len(vector))
    vector = vector[break_idx:] + vector[:break_idx]

    # now the easy part, send vector to the board!
    # ----------------------------------
    mre2.VectorPatternMemory.SetPattern(index=0, vector=vector)

Run a saved vector on one axis/channel.

    import optoMDC
    mre2 = optoMDC.connect()

    vpu = mre2.Mirror.Channel_0.VectorPatternUnit
    vpu.SetAsInput()
    vpu.SetStart(0)
    vpu.SetEnd(len(vector) - 1)
    vpu.SetFreqSampleSpeed(optoMDC.SAMPLING_FREQ)
    vpu.SetUnit(optoMDC.UnitType.CURRENT)
    vpu.Run()