Class: AgriController::Value_controller

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps = 5, up_sec = 60, down_sec = open_sec, sensitivity = 1, set_value = 20, dead_time = 2, verbose = false, first = true) ⇒ Value_controller

Returns a new instance of Value_controller.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/agri-controller/value_controller.rb', line 10

def initialize(steps=5,up_sec=60,down_sec=open_sec,sensitivity=1,set_value=20,dead_time=2,verbose=false,first=true)
  @bit=0

  @steps            =steps            #多段制御>=1
  @up_sec=up_sec
  @down_sec=down_sec          #閉時動作時間(秒)
  @sensitivity      =sensitivity      #感度
  @set_value        =set_value        #設定値
  @dead_time        =dead_time        #不感時間
  @dead_bool        =false
  if first
    @now_step=@steps          #現在の段(2010.5.23変更)
  else
    @now_step=0
  end
  @controll_bool=false #割り込みswitch(0n,0ff)[move:true],[stop:false]
  @time=Time.now
  @acting=false
  @bool=false         #true(on)  false(off)方向
  @verbose=verbose
  @reset_time=Time.now+@up_sec*@steps+3
  @emergency=false
  @first=first
  p "Value_controller initialized at #{@reset_time}" if @verbose
end

Instance Attribute Details

#actingObject

Returns the value of attribute acting.



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

def acting
  @acting
end

#boolObject

Returns the value of attribute bool.



8
9
10
# File 'lib/agri-controller/value_controller.rb', line 8

def bool
  @bool
end

#controll_boolObject

Returns the value of attribute controll_bool.



7
8
9
# File 'lib/agri-controller/value_controller.rb', line 7

def controll_bool
  @controll_bool
end

#dead_boolObject

Returns the value of attribute dead_bool.



8
9
10
# File 'lib/agri-controller/value_controller.rb', line 8

def dead_bool
  @dead_bool
end

#down_secObject

Returns the value of attribute down_sec.



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

def down_sec
  @down_sec
end

#emergencyObject

Returns the value of attribute emergency.



7
8
9
# File 'lib/agri-controller/value_controller.rb', line 7

def emergency
  @emergency
end

#firstObject

Returns the value of attribute first.



8
9
10
# File 'lib/agri-controller/value_controller.rb', line 8

def first
  @first
end

#now_stepObject

Returns the value of attribute now_step.



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

def now_step
  @now_step
end

#reset_timeObject

Returns the value of attribute reset_time.



7
8
9
# File 'lib/agri-controller/value_controller.rb', line 7

def reset_time
  @reset_time
end

#set_valueObject

Returns the value of attribute set_value.



7
8
9
# File 'lib/agri-controller/value_controller.rb', line 7

def set_value
  @set_value
end

#stepsObject

Returns the value of attribute steps.



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

def steps
  @steps
end

#up_secObject

Returns the value of attribute up_sec.



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

def up_sec
  @up_sec
end

Instance Method Details

#before_value_controll(now_value) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/agri-controller/value_controller.rb', line 56

def before_value_controll(now_value)
  if false#now_value > @set_value+@sensitivity*@steps+@sensitivity
    #too high
    p "too high!" if $DEBUG
    
    @emergency=true
    @now_step=@steps
    return true
  
  elsif false#now_value < @set_value-@sensitivity
    #too low
    p "too low!" if $DEBUG
    
    @emergency=true
    @now_step=0
    return false
  elsif Time.now <= @reset_time
    return @first
  else#normaly
    @emergency=false
    return @bool
  end
end

#step_downObject



168
169
170
171
# File 'lib/agri-controller/value_controller.rb', line 168

def step_down
  @now_step=now_step-1 if @now_step > 0
  return @now_step
end

#step_upObject



163
164
165
166
# File 'lib/agri-controller/value_controller.rb', line 163

def step_up
  @now_step+=1 if @now_step < @steps
  return @now_step
end

#switchObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/agri-controller/value_controller.rb', line 36

def switch
  if @now_step==0 or @now_step==@steps or  @emergency==true
    return true
  else
    if @dead_bool==true && @acting==true
        @controll_bool=false
    end
    
    return @controll_bool
  end
end

#switch_offObject



52
53
54
# File 'lib/agri-controller/value_controller.rb', line 52

def switch_off
  @controll_bool = false
end

#switch_onObject



48
49
50
# File 'lib/agri-controller/value_controller.rb', line 48

def switch_on
  @controll_bool = true
end

#value_controll(now_value) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/agri-controller/value_controller.rb', line 80

def value_controll(now_value)
  if Time.now > @reset_time
  if @acting==false
    #now_value:nil or tempareture
    if now_value != nil
      high=(now_value <=> @set_value+@sensitivity*(@now_step)+@sensitivity)
      low =(now_value <=> (@set_value+@sensitivity*(@now_step))-@sensitivity*2)
    else
      high=0#そのまま  #1:温度を下げる方向へセット
      low=0 #そのまま
      p Time.now.inspect+" :"+now_value.inspect
      #raise "value_controller.rb:60 error!!"
    end
    
    #もし動作中なら、そのときの温度に関係なく動作続行(下記の判定は読みとばす)
    #動作してなくて、且つステップの範囲内でstep_up , step_downさせる
    if @dead_bool==false  
      if high==1 && @now_step<@steps
        #且つ、スイッチがオフ
        if  @controll_bool == false
          #時間
          @time=Time.now
          switch_on#スイッチオン
          @bool=true#return true
          #タイマー時間設定
          step_up 
        end
      elsif low==-1 && @now_step>0
        #且つ、スイッチがオフ
        if  @controll_bool == false
          #時間
          @time=Time.now
          switch_on#スイッチオン
          @bool=false#return true
          #タイマー時間設定
          step_down 
        end
      elsif high==1 && @now_step==@steps
        @bool=true
      elsif low==-1 && @now_step==0
        @bool=false
      else
        #
      end
    end
  end
    
    ##
    #時刻設定
    #スイッチがオン
    #時間までタイマーオン
    #時間になったらスイッチオフ
    #デッドタイム処理
    #スイッチオフ
    #value_controllもnil
    if @bool==true
      x=pulse_timer([@time,@up_sec])
      y=pulse_timer([@time,@up_sec+@dead_time])
    elsif @bool==false
      x=pulse_timer([@time,@down_sec])
      y=pulse_timer([@time,@down_sec+@dead_time])
    else
    end
    if y==true
      @acting=true
    else
      @acting=false
    end
    
    if x==true
    elsif x!=true && y==true
      switch_off
      @dead_bool = true
    else
      if x!=true && y!=true
        @dead_bool = false
      end
    end
else #reset_time
end
  before_value_controll(now_value)
end