1616
1717package org .strongback .control ;
1818
19+ import org .strongback .Executable ;
20+ import org .strongback .Executor ;
21+ import org .strongback .Strongback ;
22+
1923/**
2024 * A basic controller.
2125 *
2428public interface Controller {
2529
2630 /**
27- * Calculate the next controller output. This usually involves reading one or more inputs and computing the output based
28- * upon a model of the system.
31+ * Determine if this controller is {@link #enable() enabled}.
2932 *
30- * @return <code>true</code> if the execution completed because it resulted in a value that is within the tolerance of the
31- * setpoint, or <code>false</code> if this controller is not {@link #isEnabled() enabled} or has not yet reached the
32- * setpoint given the tolerance
33+ * @return <code>true</code> if enabled, or <code>false</code> otherwise
3334 */
34- public boolean computeOutput ();
35+ public boolean isEnabled ();
3536
3637 /**
37- * Determines whether the supplied value is within the tolerance of the setpoint.
38+ * Enable this controller so that it does read inputs, compute errors, and generate outputs when {@link #computeOutput()} is
39+ * called.
3840 *
39- * @param value the proposed value
40- * @return <code>true</code> if the proposed value is within the tolerance of the setpoint, or <code>false</code> otherwise
41+ * @return this object so that methods can be chained; never null
4142 */
42- public boolean checkTolerance (double value );
43+ public Controller enable ();
44+
45+ /**
46+ * Disable this controller to <em>not</em> read inputs, compute errors, and generate outputs when {@link #computeOutput()}
47+ * is called.
48+ *
49+ * @return this object so that methods can be chained; never null
50+ */
51+ public Controller disable ();
52+
53+ /**
54+ * Get the target value for this controller.
55+ * @return the target value
56+ * @see #setpoint(double)
57+ */
58+ public double getSetpoint ();
4359
4460 /**
4561 * Sets the target value for this controller.
4662 *
4763 * @param setpoint the desired setpoint that this controller will use as a target
4864 * @return this object so that methods can be chained; never null
65+ * @see #getSetpoint()
4966 */
5067 public Controller setpoint (double setpoint );
5168
@@ -58,33 +75,57 @@ public interface Controller {
5875 public Controller tolerance (double tolerance );
5976
6077 /**
61- * Reset any error values stored from previous {@link #computeOutput() executions} .
78+ * Determines whether the current value is within the tolerance of the setpoint .
6279 *
63- * @return this object so that methods can be chained; never null
80+ * @return <code>true</code> if the current value is within the tolerance of the setpoint, or <code>false</code> otherwise
81+ * @see #checkTolerance(double)
6482 */
65- public Controller reset ();
83+ public boolean withinTolerance ();
6684
6785 /**
68- * Determine if this controller is {@link #enable() enabled} .
86+ * Determines whether the supplied value is within the tolerance of the setpoint .
6987 *
70- * @return <code>true</code> if enabled, or <code>false</code> otherwise
88+ * @param value the proposed value
89+ * @return <code>true</code> if the proposed value is within the tolerance of the setpoint, or <code>false</code> otherwise
90+ * @see #withinTolerance()
7191 */
72- public boolean isEnabled ( );
92+ public boolean checkTolerance ( double value );
7393
7494 /**
75- * Enable this controller so that it does read inputs, compute errors, and generate outputs when {@link #computeOutput()} is
76- * called .
95+ * Calculate the next controller output. This usually involves reading one or more inputs and computing the output based
96+ * upon a model of the system .
7797 *
78- * @return this object so that methods can be chained; never null
98+ * @return <code>true</code> if the execution completed because it resulted in a value that is within the tolerance of the
99+ * setpoint, or <code>false</code> if this controller is not {@link #isEnabled() enabled} or has not yet reached the
100+ * setpoint given the tolerance
79101 */
80- public Controller enable ();
102+ public boolean computeOutput ();
81103
82104 /**
83- * Disable this controller to <em>not</em> read inputs, compute errors, and generate outputs when {@link #computeOutput()}
84- * is called.
105+ * Reset any error values stored from previous {@link #computeOutput() executions}.
85106 *
86107 * @return this object so that methods can be chained; never null
87108 */
88- public Controller disable ();
109+ public Controller reset ();
110+
111+ /**
112+ * Return whether the {@link Executable} instance returned by {@link #executable()} does anything useful. Software-based
113+ * controllers may often return <code>true</code>, whereas many hardware-based controllers may return <code>false</code>.
114+ * @return <code>true</code> if the {@link #executable()} does useful work and enables the controller to operate
115+ * continually and automatically, or <code>false</code> if the {@link #executable()} does nothing.
116+ */
117+ public boolean hasExecutable ();
118+
119+ /**
120+ * Get the {@link Executable} instance that will continuously {@link #computeOutput() execute} this controller to read
121+ * inputs from the source and generate outputs to reach the {@link #setpoint(double) setpoint}.
122+ * <p>
123+ * If this is used, then this same controller should <em>never</em> be used with commands. This is not checked, so robot
124+ * programs are responsible for ensuring this does not happen.
125+ *
126+ * @return the {@link Executable} object that can be registered with an {@link Executor} (typically Strongback's
127+ * {@link Strongback#executor() central executor}); never null and always the same instance for this controller
128+ */
129+ public Executable executable ();
89130
90131}
0 commit comments