Class: SGS::Otto

Inherits:
RedisBase show all
Defined in:
lib/sgs/otto.rb

Constant Summary collapse

MODE_INERT =
0
MODE_DIAGNOSTICS =
1
MODE_MANUAL =
2
MODE_TRACK_COMPASS =
3
MODE_TRACK_AWA =
4
MODE_NAMES =
[
  "Inert Mode", "Diagnostics Mode", "Manual Control Mode",
  "Compass-Tracking Mode", "AWA-Tracking Mode"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RedisBase

#count, #count_name, #load, load, #make_redis_name, #publish, redis, redis_handle, #redis_read_var, #save, #save_and_publish, setup, subscribe, to_redis, var_init

Constructor Details

#initializeOtto

Set up some useful defaults. We assume rudder goes from 0 to 200 as does the sail angle.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sgs/otto.rb', line 51

def initialize
  #
 # Configure the Mx + C values for sail and rudder
  @rudder_m = 2.5
  @rudder_c = 100.0
  @sail_m = 2.0
  @sail_c = 0.0
  #
  # Now set the rudder and sail to default positions (rudder is centered)
  rudder = 0.0
  sail = 0.0
  #
  # Set up some basic parameters for battery/solar readings
  @bv_m = @bi_m = @bt_m = @sv_m = 1.0
  @bv_c = @bi_c = @bt_c = @sv_c = 0.0
  super
end

Instance Attribute Details

#bi_cObject

Returns the value of attribute bi_c.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def bi_c
  @bi_c
end

#bi_mObject

Returns the value of attribute bi_m.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def bi_m
  @bi_m
end

#bt_cObject

Returns the value of attribute bt_c.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def bt_c
  @bt_c
end

#bt_mObject

Returns the value of attribute bt_m.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def bt_m
  @bt_m
end

#bv_cObject

Returns the value of attribute bv_c.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def bv_c
  @bv_c
end

#bv_mObject

Returns the value of attribute bv_m.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def bv_m
  @bv_m
end

#modeObject

Returns the value of attribute mode.



34
35
36
# File 'lib/sgs/otto.rb', line 34

def mode
  @mode
end

#raw_awaObject

Returns the value of attribute raw_awa.



33
34
35
# File 'lib/sgs/otto.rb', line 33

def raw_awa
  @raw_awa
end

#raw_compassObject

Returns the value of attribute raw_compass.



33
34
35
# File 'lib/sgs/otto.rb', line 33

def raw_compass
  @raw_compass
end

#raw_rudderObject

Returns the value of attribute raw_rudder.



33
34
35
# File 'lib/sgs/otto.rb', line 33

def raw_rudder
  @raw_rudder
end

#raw_sailObject

Returns the value of attribute raw_sail.



33
34
35
# File 'lib/sgs/otto.rb', line 33

def raw_sail
  @raw_sail
end

#raw_taObject

Returns the value of attribute raw_ta.



33
34
35
# File 'lib/sgs/otto.rb', line 33

def raw_ta
  @raw_ta
end

#raw_tcObject

Returns the value of attribute raw_tc.



33
34
35
# File 'lib/sgs/otto.rb', line 33

def raw_tc
  @raw_tc
end

#rudder_cObject

Returns the value of attribute rudder_c.



34
35
36
# File 'lib/sgs/otto.rb', line 34

def rudder_c
  @rudder_c
end

#rudder_mObject

Returns the value of attribute rudder_m.



34
35
36
# File 'lib/sgs/otto.rb', line 34

def rudder_m
  @rudder_m
end

#sail_cObject

Returns the value of attribute sail_c.



34
35
36
# File 'lib/sgs/otto.rb', line 34

def sail_c
  @sail_c
end

#sail_mObject

Returns the value of attribute sail_m.



34
35
36
# File 'lib/sgs/otto.rb', line 34

def sail_m
  @sail_m
end

#sv_cObject

Returns the value of attribute sv_c.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def sv_c
  @sv_c
end

#sv_mObject

Returns the value of attribute sv_m.



35
36
37
# File 'lib/sgs/otto.rb', line 35

def sv_m
  @sv_m
end

Instance Method Details

#awaObject

Return the apparent wind angle (in radians)



105
106
107
# File 'lib/sgs/otto.rb', line 105

def awa
  @raw_awa.to_f * Math::PI / 128.0
end

#compassObject

Return the compass angle (in radians)



99
100
101
# File 'lib/sgs/otto.rb', line 99

def compass
  @raw_compass.to_f * Math::PI / 128.0
end

#rudderObject

Return the rudder angle in degrees



79
80
81
# File 'lib/sgs/otto.rb', line 79

def rudder
  (@raw_rudder.to_f - @rudder_c) / @rudder_m
end

#rudder=(val) ⇒ Object

Set the required rudder angle. Input values range from +/- 40.0 degrees



71
72
73
74
75
# File 'lib/sgs/otto.rb', line 71

def rudder=(val)
  val = -40.0 if val < -40.0
  val = 40.0 if val > 40.0
  @raw_rudder = (@rudder_m * val.to_f + @rudder_c).to_i
end

#sailObject

Return the sail setting (0.0 -> 100.0)



93
94
95
# File 'lib/sgs/otto.rb', line 93

def sail
  (@raw_sail.to_f - @sail_c) / @sail_m
end

#sail=(val) ⇒ Object

Set the required sail angle. Input values range from 0 -> 90 degrees.



85
86
87
88
89
# File 'lib/sgs/otto.rb', line 85

def sail=(val)
  val = 0.0 if val < 0.0
  val = 100.0 if val > 100.0
  @raw_sail = (@sail_m * val.to_f + @sail_c).to_i
end

#track_awaObject

Return the current tracking AWA.



135
136
137
# File 'lib/sgs/otto.rb', line 135

def track_awa
  @raw_ta.to_f * Math::PI / 128.0
end

#track_awa=(val) ⇒ Object

Set the required AWA for tracking.



127
128
129
130
131
# File 'lib/sgs/otto.rb', line 127

def track_awa=(val)
  val = -180.0 if val < -180.0
  val = 180.0 if val > 180.0
  @raw_ta = (val.to_f * 128.0 / Math::PI).to_i
end

#track_compassObject

 Return the compass value for tracking.



121
122
123
# File 'lib/sgs/otto.rb', line 121

def track_compass
  @raw_tc.to_f * Math::PI / 128.0
end

#track_compass=(val) ⇒ Object

Set the required compass reading. Input values range from 0 -> 359 degrees



111
112
113
114
115
116
117
# File 'lib/sgs/otto.rb', line 111

def track_compass=(val)
  while val < 0.0
    val += 360.0
  end
  val %= 360.0
  @raw_tc = (val.to_f * 128.0 / Math::PI).to_i
end