librts: excitation channels need unique AWG ids
When calling getIndexAWG
, there needs to be a one-to-one mapping between the id number (second argument) and the excitation point channel names. AWG uses this id number to decide whether to allocate a new slot, or return an already existing slot.
Currently librts always uses 1
as the id number. Therefore, only one AWG slot can ever be allocated. If you try to drive multiple channels with distinct waveforms, each channel ends up being driven with the same waveform (which is a superposition of all waveforms that were requested).
Here's a short example demonstrating the issue:
import numpy as np
import matplotlib.pyplot as plt
import x1bmp_pybind
mdl = x1bmp_pybind.create_instance(1)
# setting up two simultaneous excitations
slot1 = mdl.get_awg_slot('CTRL_A_EXC')
slot2 = mdl.get_awg_slot('CTRL_B_EXC')
print(f'got slots {slot1} {slot2}') # expect two distinct slot numbers
# waveform 1 (1.1 Hz 1 ct sine wave)
c1 = x1bmp_pybind.AWG_Component()
c1.wtype = c1.wtype.awgSine
c1.start = (mdl.get_gps_time()+1)*int(1e9)
c1.duration = -1
c1.restart = -1
c1.par[0] = 1
c1.par[1] = 1.1
x1bmp_pybind.addWaveformAWG(slot1, [c1,])
# waveform 2 (2.1 Hz 2 ct sine wave)
c2 = x1bmp_pybind.AWG_Component()
c2.wtype = c2.wtype.awgSine
c2.start = (mdl.get_gps_time()+1)*int(1e9)
c2.duration = -1
c2.restart = -1
c2.par[0] = 2
c2.par[1] = 2.1
x1bmp_pybind.addWaveformAWG(slot2, [c2,])
# record results
mdl.record_model_var('CTRL_A_IN2', mdl.get_model_rate_Hz())
mdl.record_model_var('CTRL_B_IN2', mdl.get_model_rate_Hz())
mdl.run_model(mdl.get_model_rate_Hz()*10)
data1 = np.array(mdl.get_recorded_var('CTRL_A_IN2'))
data2 = np.array(mdl.get_recorded_var('CTRL_B_IN2'))
# plot results
plt.plot(np.linspace(0, 10, mdl.get_model_rate_Hz()*10), data1)
plt.plot(np.linspace(0, 10, mdl.get_model_rate_Hz()*10), data2)
plt.savefig('awgissue.png') # expect two distinct sine waveforms
The code in the original MR incremented the id number while iterating over the excitation points, to provide a unique id for each one.