Class: DeviceControl::Controller
- Inherits:
-
Object
- Object
- DeviceControl::Controller
- Includes:
- Updateable
- Defined in:
- lib/device_control.rb
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.
89 90 91 |
# File 'lib/device_control.rb', line 89 def initialize(setpoint) @setpoint, @measure = setpoint, 0.0 end |
Instance Attribute Details
#measure ⇒ Object (readonly)
Returns the value of attribute measure.
86 87 88 |
# File 'lib/device_control.rb', line 86 def measure @measure end |
#setpoint ⇒ Object
Returns the value of attribute setpoint.
87 88 89 |
# File 'lib/device_control.rb', line 87 def setpoint @setpoint end |
Instance Method Details
#input=(val) ⇒ Object Also known as: measure=
93 94 95 |
# File 'lib/device_control.rb', line 93 def input=(val) @measure = val.to_f end |
#output ⇒ Object
just output the error
99 100 101 |
# File 'lib/device_control.rb', line 99 def output @setpoint - @measure end |
#to_s ⇒ Object
103 104 105 |
# File 'lib/device_control.rb', line 103 def to_s format("Setpoint: %.3f\tMeasure: %.3f", @setpoint, @measure) end |