Class: 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.



88
89
90
# File 'lib/device_control.rb', line 88

def initialize(setpoint)
  @setpoint, @measure = setpoint, 0.0
end

Instance Attribute Details

#measureObject (readonly)

Returns the value of attribute measure.



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

def measure
  @measure
end

#setpointObject

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

#outputObject

just output the error



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

def output
  @setpoint - @measure
end

#to_sObject



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

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