RT-Lab Error with Python script to change parameter
We are seeing some weird results when we attempt to manually modify block parameters that are within enabled subsystems from a python script. Have you seen anything like this before?
Question
So I found my problem. The parameter I was attempting to change was a 3x3 matrix in a constant block. Doesn’t RT-Lab support matrices?
Answer
I ran a test python script which modifies the gain parameter within an enabled subsystem. It works fine as long as I closed out the Parameter Control from RT-Lab. This is because the Parameter Control from RT-Lab was taking control of the model parameters and would not allow the python script to modify the gain parameter.
I tested having a 3x3 matrix for a gain block and was able to get the parameter control to work for all of the matrix values. I modified rtdemo1.mdl to have an enabled subsystem with a gain block inside that has the 3x3 matrix.
I then modified the python script to modify each of gains 1 – 9.
Results of python script:
The connection with 'rtdemo1' is completed.
- Here is the list of all parameter values:
rtdemo1/sm_computation/Integrator3/InitialCondition = 0.0
rtdemo1/sm_computation/Integrator3/UpperSaturationLimit = 200.0
rtdemo1/sm_computation/Integrator3/LowerSaturationLimit = 0.0
rtdemo1/sm_computation/Sensor response time/DelayTime = 0.005
rtdemo1/sm_computation/Sensor response time/InitialOutput = 0.0
rtdemo1/sm_computation/Gain Kp/Gain = 20.0
rtdemo1/sm_computation/Integrator1/InitialCondition = 0.0
rtdemo1/sm_computation/Gain Ki/Gain = 5.0
rtdemo1/sm_computation/Gain1/Gain = -1.0
rtdemo1/sm_computation/Gain Kd/Gain = 5.0
rtdemo1/sm_computation/Actuator response time/DelayTime = 0.005
rtdemo1/sm_computation/Actuator response time/InitialOutput = 0.0
rtdemo1/sm_computation/Gain/Gain = 1.0
rtdemo1/sm_computation/Integrator2/InitialCondition = 0.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(1) = 120.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(2) = 50.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(3) = 10.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(4) = 60.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(5) = 95.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(6) = 80.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(7) = 70.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(8) = 65.0
rtdemo1/sm_computation/Enabled Subsystem/Gain/Gain(9) = 55.0
rtdemo1/sm_computation/Enabled Subsystem/Integrator2/InitialCondition = 0.0
- The parameter control is acquired.
- The parameter values were set to : (120, 50, 10, 60, 95, 80, 70, 65, 55).
- The parameter values are : (120.0, 50.0, 10.0, 60.0, 95.0, 80.0, 70.0, 65.0, 55.0).
- The parameter control is released.
The connection is closed.
- Matlab plot before python script run:
- Matlab plot after running parameter control python scripts:
- enabled subsystem:
- Gain block 3x3 matrix:
rtdemo1.mdl - PID controller example
rtdemo1_parameter1.py_.txt - python script for parameter change




