]> git.basschouten.com Git - openhab-addons.git/blob
1e105d53733bfe91c83a4ec549a6afd8aa0bbf41
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.automation.pidcontroller.internal.type;
14
15 import static org.openhab.automation.pidcontroller.internal.PIDControllerConstants.*;
16
17 import java.math.BigDecimal;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.automation.pidcontroller.internal.handler.PIDControllerTriggerHandler;
23 import org.openhab.core.automation.Visibility;
24 import org.openhab.core.automation.type.Output;
25 import org.openhab.core.automation.type.TriggerType;
26 import org.openhab.core.config.core.ConfigDescriptionParameter;
27 import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
28 import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
29
30 /**
31  *
32  * @author Hilbrand Bouwkamp - Initial Contribution
33  */
34 @NonNullByDefault
35 public class PIDControllerTriggerType extends TriggerType {
36     private static final String DEFAULT_LOOPTIME_MS = "1000";
37
38     public static PIDControllerTriggerType initialize() {
39         List<ConfigDescriptionParameter> configDescriptions = new ArrayList<>();
40         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_INPUT_ITEM, Type.TEXT).withRequired(true)
41                 .withReadOnly(true).withMultiple(false).withContext("item").withLabel("Input Item")
42                 .withDescription("Item to monitor").build());
43         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_SETPOINT_ITEM, Type.TEXT)
44                 .withRequired(true).withReadOnly(true).withMultiple(false).withContext("item").withLabel("Setpoint")
45                 .withDescription("Targeted setpoint").build());
46         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KP_GAIN, Type.DECIMAL).withRequired(true)
47                 .withMultiple(false).withDefault("1.0").withLabel("Proportional Gain (Kp)")
48                 .withDescription("Change to output propertional to current error value.").build());
49         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KI_GAIN, Type.DECIMAL).withRequired(true)
50                 .withMultiple(false).withDefault("1.0").withLabel("Integral Gain (Ki)")
51                 .withDescription("Accelerate movement towards the setpoint.").build());
52         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KD_GAIN, Type.DECIMAL).withRequired(true)
53                 .withMultiple(false).withDefault("1.0").withLabel("Derivative Gain (Kd)")
54                 .withDescription("Slows the rate of change of the output.").build());
55         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KD_TIMECONSTANT, Type.DECIMAL)
56                 .withRequired(true).withMultiple(false).withDefault("1.0").withLabel("Derivative Time Constant")
57                 .withDescription("Slows the rate of change of the D Part (T1) in seconds.").withUnit("s").build());
58         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_OUTPUT_LOWER_LIMIT, Type.DECIMAL)
59                 .withRequired(true).withMultiple(false).withDefault("0").withLabel("Output Lower Limit")
60                 .withDescription("The output of the PID controller will be min this value").build());
61         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_OUTPUT_UPPER_LIMIT, Type.DECIMAL)
62                 .withRequired(true).withMultiple(false).withDefault("100").withLabel("Output Upper Limit")
63                 .withDescription("The output of the PID controller will be max this value").build());
64         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_LOOP_TIME, Type.DECIMAL)
65                 .withRequired(true).withMultiple(false).withDefault(DEFAULT_LOOPTIME_MS).withLabel("Loop Time")
66                 .withDescription("The interval the output value is updated in ms").withUnit("ms").build());
67
68         Output output = new Output(OUTPUT, BigDecimal.class.getName(), "Output", "Output value of the PID Controller",
69                 null, null, null);
70         Output pInspector = new Output(P_INSPECTOR, BigDecimal.class.getName(), "P Inspector",
71                 "Current P value of the pid controller", null, null, null);
72         Output iInspector = new Output(I_INSPECTOR, BigDecimal.class.getName(), "I Inspector",
73                 "Current I value of the pid controller", null, null, null);
74         Output dInspector = new Output(D_INSPECTOR, BigDecimal.class.getName(), "D Inspector",
75                 "Current D value of the pid controller", null, null, null);
76         Output eInspector = new Output(E_INSPECTOR, BigDecimal.class.getName(), "Error Value Inspector",
77                 "Current error value of the pid controller", null, null, null);
78
79         List<Output> outputs = List.of(output, pInspector, iInspector, dInspector, eInspector);
80
81         return new PIDControllerTriggerType(configDescriptions, outputs);
82     }
83
84     public PIDControllerTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
85         super(PIDControllerTriggerHandler.MODULE_TYPE_ID, configDescriptions, "PID controller triggers", null, null,
86                 Visibility.VISIBLE, outputs);
87     }
88 }