Class: PIDController::PID

Inherits:
Object
  • Object
show all
Defined in:
lib/rb-pid-controller/pid.rb

Direct Known Subclasses

PD, PI

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#consignObject

Returns the value of attribute consign.



6
7
8
# File 'lib/rb-pid-controller/pid.rb', line 6

def consign
  @consign
end

#kdObject

Returns the value of attribute kd.



6
7
8
# File 'lib/rb-pid-controller/pid.rb', line 6

def kd
  @kd
end

#kiObject

Returns the value of attribute ki.



6
7
8
# File 'lib/rb-pid-controller/pid.rb', line 6

def ki
  @ki
end

#kpObject

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

#resetObject



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