]> git.basschouten.com Git - openhab-addons.git/blob
856ded793f3f488719755bcd747c31d66b3a5d72
[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).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").withMinimum(BigDecimal.ZERO).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").withMinimum(BigDecimal.ZERO).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").withMinimum(BigDecimal.ZERO).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).withMinimum(BigDecimal.ZERO).withDefault("1.0")
57                 .withLabel("Derivative Time Constant")
58                 .withDescription("Slows the rate of change of the D part (T1) in seconds.").withUnit("s").build());
59         configDescriptions
60                 .add(ConfigDescriptionParameterBuilder.create(CONFIG_COMMAND_ITEM, Type.TEXT).withRequired(false)
61                         .withReadOnly(true).withMultiple(false).withContext("item").withLabel("Command Item")
62                         .withDescription("You can send String commands to this Item like \"RESET\".").build());
63         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_LOOP_TIME, Type.DECIMAL)
64                 .withRequired(true).withMultiple(false).withDefault(DEFAULT_LOOPTIME_MS).withLabel("Loop Time")
65                 .withDescription("The interval the output value is updated in ms").withUnit("ms").build());
66
67         Output output = new Output(OUTPUT, BigDecimal.class.getName(), "Output", "Output value of the PID Controller",
68                 null, null, null);
69         Output pInspector = new Output(P_INSPECTOR, BigDecimal.class.getName(), "P Inspector",
70                 "Current P value of the pid controller", null, null, null);
71         Output iInspector = new Output(I_INSPECTOR, BigDecimal.class.getName(), "I Inspector",
72                 "Current I value of the pid controller", null, null, null);
73         Output dInspector = new Output(D_INSPECTOR, BigDecimal.class.getName(), "D Inspector",
74                 "Current D value of the pid controller", null, null, null);
75         Output eInspector = new Output(E_INSPECTOR, BigDecimal.class.getName(), "Error Value Inspector",
76                 "Current error value of the pid controller", null, null, null);
77
78         List<Output> outputs = List.of(output, pInspector, iInspector, dInspector, eInspector);
79
80         return new PIDControllerTriggerType(configDescriptions, outputs);
81     }
82
83     public PIDControllerTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
84         super(PIDControllerTriggerHandler.MODULE_TYPE_ID, configDescriptions, "PID controller triggers", null, null,
85                 Visibility.VISIBLE, outputs);
86     }
87 }