Class: PIDController::PID
- Inherits:
-
Object
- Object
- PIDController::PID
- Defined in:
- lib/rb-pid-controller/pid.rb
Instance Attribute Summary collapse
-
#consign ⇒ Object
Returns the value of attribute consign.
-
#kd ⇒ Object
Returns the value of attribute kd.
-
#ki ⇒ Object
Returns the value of attribute ki.
-
#kp ⇒ Object
Returns the value of attribute kp.
Instance Method Summary collapse
- #<<(value) ⇒ Object
-
#initialize(kp = 1, ki = 1, kd = 1) ⇒ PID
constructor
A new instance of PID.
- #reset ⇒ Object
- #set_consign(consign) ⇒ Object
Constructor Details
#initialize(kp = 1, ki = 1, kd = 1) ⇒ PID
Returns a new instance of PID.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rb-pid-controller/pid.rb', line 8 def initialize(kp = 1 ,ki = 1,kd = 1) # save pid coefficient @kp = kp.to_f @ki = ki.to_f @kd = kd.to_f @consign = nil self.reset end |
Instance Attribute Details
#consign ⇒ Object
Returns the value of attribute consign.
6 7 8 |
# File 'lib/rb-pid-controller/pid.rb', line 6 def consign @consign end |
#kd ⇒ Object
Returns the value of attribute kd.
6 7 8 |
# File 'lib/rb-pid-controller/pid.rb', line 6 def kd @kd end |
#ki ⇒ Object
Returns the value of attribute ki.
6 7 8 |
# File 'lib/rb-pid-controller/pid.rb', line 6 def ki @ki end |
#kp ⇒ Object
Returns the value of attribute kp.
6 7 8 |
# File 'lib/rb-pid-controller/pid.rb', line 6 def kp @kp end |
Instance Method Details
#<<(value) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rb-pid-controller/pid.rb', line 26 def <<(value) e,dt = error(value) out = proportional(e) + integrative(e,dt) + derivative(e,dt) @previous_error = e return out end |
#reset ⇒ Object
35 36 37 38 39 |
# File 'lib/rb-pid-controller/pid.rb', line 35 def reset @previous_error = 0.0 @integrative = 0.0 @last_time = nil end |
#set_consign(consign) ⇒ Object
22 23 24 |
# File 'lib/rb-pid-controller/pid.rb', line 22 def set_consign(consign) @consign = consign.to_f end |