import numpy as np
import skfuzzy.control as ctrl
import skfuzzy as fuzz
import commands
error = ctrl.Antecedent(np.arange(-12,12, 0.01), 'error')
derivative = ctrl.Antecedent(np.arange(-12, 12, 0.01), 'derivative')
output = ctrl.Consequent(np.arange(-24, 24, 0.01), 'output')
error['N']=fuzz.trimf(error.universe,[-12,-12,0])
error['P']=fuzz.trimf(error.universe,[0,12,12])
error['Z']=fuzz.trimf(error.universe,[-10,0,10])
derivative['N']=fuzz.trimf(derivative.universe,[-12,-12,0])
derivative['P']=fuzz.trimf(derivative.universe,[0,12,12])
derivative['Z']=fuzz.trimf(derivative.universe,[-10,0,10])
output['N']=fuzz.trimf(output.universe, [-24,-12, 0])
output['P']=fuzz.trimf(output.universe, [0,12,24])
output['Z']=fuzz.trimf(output.universe, [-10,0,10])
rule1 = ctrl.Rule(error['N'] & derivative['N'],output['N'] )
rule2 = ctrl.Rule(error['N'] & derivative['Z'],output['N'] )
rule3 = ctrl.Rule(error['N'] & derivative['P'],output['Z'] )
rule4 = ctrl.Rule(error['P'] & derivative['N'],output['Z'] )
rule5 = ctrl.Rule(error['P'] & derivative['P'],output['P'])
rule6 = ctrl.Rule(error['P'] & derivative['Z'],output['P'])
rule7 = ctrl.Rule(error['Z'] & derivative['N'],output['N'])
rule8 = ctrl.Rule(error['Z'] & derivative['P'],output['P'])
rule9 = ctrl.Rule(error['Z'] & derivative['Z'],output['Z'])
output_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9])
outputs = ctrl.ControlSystemSimulation(output_ctrl)
```
Two problems are apparent:
- The new API has a bug where multiple Rules converging on a single Consequent Term overwrite each other instead of combining. An Issue is raised on GitHub (https://github.com/scikit-fuzzy/scikit-fuzzy/issues/108) and a fix is pending.
- Your Antecedent Terms called 'Z' should be extended to cover the full range of [-12, 12] instead of [-10, 10].
With the 'Z' range extended, this should run without problems after the fix for Issue #108 is merged.