Skip to content
Prev Previous commit
Next Next commit
more comprehensive system construction tests
  • Loading branch information
sawyerbfuller committed Nov 5, 2021
commit 2af117130d388b91a3b0b742879e3c6250e232a7
7 changes: 4 additions & 3 deletions control/sisotool.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _SisotoolUpdate(sys, fig, K, bode_plot_params, tvect=None):
def rootlocus_pid_designer(plant, gain='P', sign=+1, input_signal='r',
Kp0=0, Ki0=0, Kd0=0, tau=0.01,
C_ff=0, derivative_in_feedback_path=False,
noplot=False):
plot=True):
"""Manual PID controller design based on root locus using Sisotool

Uses `Sisotool` to investigate the effect of adding or subtracting an
Expand Down Expand Up @@ -262,7 +262,8 @@ def rootlocus_pid_designer(plant, gain='P', sign=+1, input_signal='r',
derivative_in_feedback_path : bool (optional)
Whether to place the derivative term in feedback transfer function
`C_b` instead of the forward transfer function `C_f`.
noplot : bool (optional)
plot : bool (optional)
Whether to create Sisotool interactive plot.

Returns
----------
Expand Down Expand Up @@ -328,6 +329,6 @@ def rootlocus_pid_designer(plant, gain='P', sign=+1, input_signal='r',
C_ff, e_summer, u_summer),
inplist=['input', input_signal],
outlist=['output', 'y'])
if ~noplot:
if plot:
sisotool(loop, kvect=(0.,))
return _convert_to_statespace(loop[1, 1])
26 changes: 17 additions & 9 deletions control/tests/sisotool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,26 @@ def plant(self, request):
'syscont221':StateSpace([[-.3, 0],[1,0]],[[-1,],[.1,]], [0, -.3], 0)}
return plants[request.param]

# check
# cont or discrete, vary P I or D
# @pytest.mark.parametrize('plant', (syscont, sysdisc1))
@pytest.mark.parametrize('plant', ('syscont', 'sysdisc1'), indirect=True)
# test permutations of system construction without plotting
@pytest.mark.parametrize('plant', ('syscont', 'sysdisc1', 'syscont221'), indirect=True)
@pytest.mark.parametrize('gain', ('P', 'I', 'D'))
@pytest.mark.parametrize("kwargs", [{'Kp0':0.1, 'noplot':True},])
def test_pid_designer_1(self, plant, gain, kwargs):
rootlocus_pid_designer(plant, gain, **kwargs)

@pytest.mark.parametrize('sign', (1,))
@pytest.mark.parametrize('input_signal', ('r', 'd'))
@pytest.mark.parametrize('Kp0', (0,))
@pytest.mark.parametrize('Ki0', (1.,))
@pytest.mark.parametrize('Kd0', (0.1,))
@pytest.mark.parametrize('tau', (0.01,))
@pytest.mark.parametrize('C_ff', (0, 1,))
@pytest.mark.parametrize('derivative_in_feedback_path', (True, False,))
@pytest.mark.parametrize("kwargs", [{'plot':False},])
def test_pid_designer_1(self, plant, gain, sign, input_signal, Kp0, Ki0, Kd0, tau, C_ff,
derivative_in_feedback_path, kwargs):
rootlocus_pid_designer(plant, gain, sign, input_signal, Kp0, Ki0, Kd0, tau, C_ff,
derivative_in_feedback_path, **kwargs)

# test creation of sisotool plot
# input from reference or disturbance
@pytest.mark.parametrize('plant', ('syscont', 'syscont221'), indirect=True)
# @pytest.mark.parametrize('plant', (syscont, syscont221))
@pytest.mark.parametrize("kwargs", [
{'input_signal':'r', 'Kp0':0.01, 'derivative_in_feedback_path':True},
{'input_signal':'d', 'Kp0':0.01, 'derivative_in_feedback_path':True},])
Expand Down