Class: DeviceControl::Controller

Inherits:
Object
  • Object
show all
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

StatefulController, Thermostat

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Updateable

#update

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

#measureObject (readonly)

Returns the value of attribute measure.



86
87
88
# File 'lib/device_control.rb', line 86

def measure
  @measure
end

#setpointObject

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

#outputObject

just output the error



99
100
101
# File 'lib/device_control.rb', line 99

def output
  @setpoint - @measure
end

#to_sObject



103
104
105
# File 'lib/device_control.rb', line 103

def to_s
  format("Setpoint: %.3f\tMeasure: %.3f", @setpoint, @measure)
end