Hi Taylor,
We would like to switch between channels in some of the protocols and would like to give the mode names (i.e. “mode_1”, “mode_2”, etc. ) a variable name so we can call the variable name directly in a state rather than hard-coding “mode_1” or “mode_2” in the protocol.
Apologies for not responding sooner.
I’m not 100% sure that I understand what you want to do, but I’m pretty sure you’re confused about the difference between component parameters and variables.
Taking a look at the start of the definition of a QCUALOR device:
iodevice/qcualor laser (
mode_1 = mode_1
...
The “mode_1” on the left is a parameter name and refers to the mode_1 parameter of the QCUALOR device. The “mode_1” on the right is a variable name. The variable is declared elsewhere in your experiment, with a statement like
var mode_1 = 'continuous'
In the device definition, “mode_1 = mode_1” means “take the value for the parameter named mode_1 from the variable named mode_1”. This might be clearer if the variable had a different name. For example:
var channel_1_mode = 'continuous'
var channel_2_mode = 'off'
iodevice/qcualor laser (
mode_1 = channel_1_mode
mode_2 = channel_2_mode
...
To change the mode of a laser channel, you have to change the value of the variable that is assigned to the parameter for that mode, e.g.
channel_1_mode = 'sinusoidal'
If you want to change the active channel, you have to do two such assignments: one to turn off the current channel, and another to turn on the new channel, e.g.
channel_1_mode = 'off'
channel_2_mode = 'continuous'
If your goal is to avoid writing the “if” statements mapping laser_type
to channel modes multiple times, maybe try using a macro like this:
%define set_laser_channel (mode_var, mode_type)
assignment(
variable = mode_var
value = {
0: 'off',
1: 'continuous',
2: 'sinusoidal',
3: 'inverse_sinusoidal',
4: 'square'
}[mode_type]
)
%end
Then, to turn channel 1 off and set channel 2 to the mode specified by laser_type
:
set_laser_channel (
mode_var = mode_1
mode_type = 0
)
set_laser_channel (
mode_var = mode_2
mode_type = laser_type
)
Does that get you closer to your goal?
Cheers,
Chris