]> git.basschouten.com Git - openhab-addons.git/blob
0909c90abcb0418a0f3c136ab3706b5bf595f98f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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) //
41                 .withRequired(true) //
42                 .withMultiple(false) //
43                 .withContext("item") //
44                 .withLabel("Input Item") //
45                 .withDescription("Item to monitor") //
46                 .build());
47         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_SETPOINT_ITEM, Type.TEXT) //
48                 .withRequired(true) //
49                 .withMultiple(false) //
50                 .withContext("item") //
51                 .withLabel("Setpoint") //
52                 .withDescription("Targeted setpoint") //
53                 .build());
54         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KP_GAIN, Type.DECIMAL).withRequired(true) //
55                 .withMultiple(false) //
56                 .withDefault("1.0") //
57                 .withMinimum(BigDecimal.ZERO) //
58                 .withLabel("Proportional Gain (Kp)") //
59                 .withDescription("Change to output propertional to current error value.") //
60                 .build());
61         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KI_GAIN, Type.DECIMAL) //
62                 .withRequired(true) //
63                 .withMultiple(false) //
64                 .withDefault("1.0") //
65                 .withMinimum(BigDecimal.ZERO) //
66                 .withLabel("Integral Gain (Ki)") //
67                 .withDescription("Accelerate movement towards the setpoint.") //
68                 .build());
69         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KD_GAIN, Type.DECIMAL) //
70                 .withRequired(true) //
71                 .withMultiple(false) //
72                 .withDefault("1.0") //
73                 .withMinimum(BigDecimal.ZERO) //
74                 .withLabel("Derivative Gain (Kd)") //
75                 .withDescription("Slows the rate of change of the output.") //
76                 .build());
77         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KD_TIMECONSTANT, Type.DECIMAL) //
78                 .withRequired(true) //
79                 .withMultiple(false) //
80                 .withMinimum(BigDecimal.ZERO) //
81                 .withDefault("1.0") //
82                 .withLabel("Derivative Time Constant") //
83                 .withDescription("Slows the rate of change of the D part (T1) in seconds.") //
84                 .withUnit("s") //
85                 .build());
86         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_COMMAND_ITEM, Type.TEXT) //
87                 .withRequired(false) //
88                 .withMultiple(false) //
89                 .withContext("item") //
90                 .withLabel("Command Item") //
91                 .withDescription("You can send String commands to this Item like \"RESET\".") //
92                 .build());
93         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_LOOP_TIME, Type.DECIMAL) //
94                 .withRequired(true) //
95                 .withMultiple(false) //
96                 .withDefault(DEFAULT_LOOPTIME_MS) //
97                 .withLabel("Loop Time") //
98                 .withDescription("The interval the output value is updated in ms") //
99                 .withUnit("ms") //
100                 .build());
101         Output output = new Output(OUTPUT, BigDecimal.class.getName(), "Output", "Output value of the PID Controller",
102                 null, null, null);
103         Output pInspector = new Output(P_INSPECTOR, BigDecimal.class.getName(), "P Inspector",
104                 "Current P value of the pid controller", null, null, null);
105         Output iInspector = new Output(I_INSPECTOR, BigDecimal.class.getName(), "I Inspector",
106                 "Current I value of the pid controller", null, null, null);
107         Output dInspector = new Output(D_INSPECTOR, BigDecimal.class.getName(), "D Inspector",
108                 "Current D value of the pid controller", null, null, null);
109         Output eInspector = new Output(E_INSPECTOR, BigDecimal.class.getName(), "Error Value Inspector",
110                 "Current error value of the pid controller", null, null, null);
111
112         List<Output> outputs = List.of(output, pInspector, iInspector, dInspector, eInspector);
113
114         return new PIDControllerTriggerType(configDescriptions, outputs);
115     }
116
117     public PIDControllerTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
118         super(PIDControllerTriggerHandler.MODULE_TYPE_ID, configDescriptions, "PID controller triggers", null, null,
119                 Visibility.VISIBLE, outputs);
120     }
121 }