PID module and customfunction

Hello,

i have another problem with the PID module.
In the PID module, a value of a CustomFunction can be selected for the tolerance, but this is not accepted. The error message "PID: Parameter ‘TolleranceValue’ with value ‘CustomFunction value’ which is no number. If the value is specified via a form value, this is accepted. Why does this not work with a CustomFunction value?

Best regards,
Steffen

Hello Steffen,

Do I understand this correctly: You want to use a parameter named “TolleranceValue”, which is generated by your Custom Function Module, as input for the tolerance parameter of the PID module?

The error message suggests that the value of your “TolleranceValue” parameter is “CustomFunctionValue”, which is a string and not a number. What value do you expect the parameter to be?
Can you check the parameter widget (via pressing F3) to see the type and value of your “TolleranceValue” parameter?

Can you provide a minimum working example or screenshot of a setting were it is working via the Form module and one were it is not working?

Best,
Franz

Hello Franz,

exactly, I would like to use the value from the CustomFunction for the tolerance. The type of the value is int.
Here is an example of a setting (form and CustomFunction)
and the CustomFunction script and a screenshot of the error message.

Rate_Tollerance_from_CustomFunction.set (15.0 KB)
Rate_Tollerance_from_Fomular.set (15.0 KB)

Best,
Steffen

The error arises due to the sequencing order of your setting.

The Form module provides its values to the parameter system at the very start of the measurement. This is possible because the Form Input values cannot be changed during the measuremt.

The Custom Function module, however, provides its values at every step of the measurement sweep. Each step consists of multiple function calls such as “configure”, “measure”, “call” (More info on this can be found here: Sequencer procedure - SweepMe! Wiki)
The PID module retrieves its input values in the “process” step.
The Custom Function module provides its values in the “process” step as well. However, as the PID module is on a lower level than the Custom Function module in your setting, the PID module tries to handle its inputs before the Custom Function provides them.

There are two possible solutions here:

  1. Swap your PID and Custom Function module in the sequencer branch.
  2. Change the execution phase of your custom function by adding the “execution = start” parameter (see CustomFunction - SweepMe! Wiki). With this, the custom function is called before the measurement point in the start phase. However, this does not work If your custom function depends on the results of other measurement modules.

Let me know if any of these solutions resolved your issue.

Unfortunately, the first suggestion does not work, the same error message appears and the second suggestion only partially works. In the first sweep the customfunction still gets the sweep value (sweep_rate), but in the second sweep it only gets nan. You had written that this would be the case. Unfortunately, the customfunction needs the sweep value (sweep_rate). Do you have an idea how I can work around this?

I was able to reproduce the issue with the setting and custom function script you have provided.

It seems that your Custom Function does not correctly parse the sweep value of your Sweep_Rate element. After some testing with your custom function script, I got it to work by using the newer way of defining input parameters. You can update your code to the following (I have simplified the logic for explanatory purposes):

class Main():

# please define variables and units as returned by the function 'main'
variables = ["tolerance"]
units = ["%"]

# The recommended way of defining input variables for your script
arguments = {
    "sweep_rate":"1",  # Important to define a string value to allow use of the Parameter Syntax
}
# Use the "start" phase before each measurement point
execution = "start"

[...]

# Change the parameters to retrieve the "arguments" we just defined
def main(self, **kwargs):

    # Retrieve the GUI input
    sweep_rate = float(kwargs["sweep_rate"])

    [...]

In your setting, you need to update the input of the Custom Function by using the Parameter Syntax, which means writing the source of the parameter in curly brackets:

I could not test the complete setting, as I am missing the devices, but with these changes the tolerance could be transferred to the PID module

Happy measuring!

I have tested the changes to the CustomFunction and it works, thanks for the help.

1 Like