Class: DeviceControl::RateLimiter
- Inherits:
-
Object
- Object
- DeviceControl::RateLimiter
- Includes:
- Updateable
- Defined in:
- lib/device_control.rb
Instance Attribute Summary collapse
-
#val ⇒ Object
Returns the value of attribute val.
Instance Method Summary collapse
-
#initialize(max_step, val: 0) ⇒ RateLimiter
constructor
A new instance of RateLimiter.
-
#input=(val) ⇒ Object
never allow @val to grow / shrink more than @max_step.
- #output ⇒ Object
Methods included from Updateable
Constructor Details
#initialize(max_step, val: 0) ⇒ RateLimiter
Returns a new instance of RateLimiter.
305 306 307 308 |
# File 'lib/device_control.rb', line 305 def initialize(max_step, val: 0) @max_step = max_step @val = val end |
Instance Attribute Details
#val ⇒ Object
Returns the value of attribute val.
303 304 305 |
# File 'lib/device_control.rb', line 303 def val @val end |
Instance Method Details
#input=(val) ⇒ Object
never allow @val to grow / shrink more than @max_step
311 312 313 314 |
# File 'lib/device_control.rb', line 311 def input=(val) diff = val - @val @val += diff.clamp(-1 * @max_step, @max_step) end |
#output ⇒ Object
316 317 318 |
# File 'lib/device_control.rb', line 316 def output @val end |