Class: Controller
Overview
A Controller is like a thermostat. It has a setpoint, and it reads a measurement from the environment, and it adjusts its output to try to make the measurement match the setpoint.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#measure ⇒ Object
readonly
Returns the value of attribute measure.
-
#setpoint ⇒ Object
Returns the value of attribute setpoint.
Instance Method Summary collapse
-
#initialize(setpoint) ⇒ Controller
constructor
A new instance of Controller.
- #input=(val) ⇒ Object (also: #measure=)
-
#output ⇒ Object
just output the error.
- #to_s ⇒ Object
Methods included from Updateable
Constructor Details
#initialize(setpoint) ⇒ Controller
Returns a new instance of Controller.
88 89 90 |
# File 'lib/device_control.rb', line 88 def initialize(setpoint) @setpoint, @measure = setpoint, 0.0 end |
Instance Attribute Details
#measure ⇒ Object (readonly)
Returns the value of attribute measure.
85 86 87 |
# File 'lib/device_control.rb', line 85 def measure @measure end |
#setpoint ⇒ Object
Returns the value of attribute setpoint.
86 87 88 |
# File 'lib/device_control.rb', line 86 def setpoint @setpoint end |
Instance Method Details
#input=(val) ⇒ Object Also known as: measure=
92 93 94 |
# File 'lib/device_control.rb', line 92 def input=(val) @measure = val.to_f end |
#output ⇒ Object
just output the error
98 99 100 |
# File 'lib/device_control.rb', line 98 def output @setpoint - @measure end |
#to_s ⇒ Object
102 103 104 |
# File 'lib/device_control.rb', line 102 def to_s format("Setpoint: %.3f\tMeasure: %.3f", @setpoint, @measure) end |