Class: Lignite::Motors
- Inherits:
-
Object
- Object
- Lignite::Motors
- Defined in:
- lib/lignite/motors.rb
Overview
Send DirectCommands to motors. It’s called Motors instead of Motor because some methods are designed to work on a pair if motors driving a vehicle.
Instance Attribute Summary collapse
- #dc ⇒ Lignite::DirectCommands readonly
-
#layer ⇒ Object
readonly
do the DCs spawn independent threads?? must run ready in the same block?.
-
#nos ⇒ Object
readonly
Returns the value of attribute nos.
Instance Method Summary collapse
-
#clr_count ⇒ Object
zero tachos, for use as sensor.
-
#get_count ⇒ Object
rubocop:disable Naming/AccessorMethodName, upstream API name.
-
#initialize(layer, nos, dc = Lignite::DirectCommands.new) ⇒ Motors
constructor
A new instance of Motors.
-
#nos_as_bits ⇒ Object
0x02 | 0x04 | 0x08 -> [0x02, 0x04, 0x08].
-
#nos_as_indices ⇒ Object
0x02 | 0x04 | 0x08 -> [1, 2, 3].
-
#polarity(pol) ⇒ Object
ATTR ~polarity.
-
#power(power) ⇒ Object
ATTR power ~ speed ?.
-
#prg_stop ⇒ Object
WTF?.
- #read ⇒ Object
-
#ready ⇒ Object
which commands are affected? not output_start they say.
-
#reset ⇒ Object
ATTR tacho, like degrees.
-
#set_type ⇒ Object
the type is an OUT param so the VM SETs and we GET to learn the type?.
- #speed(speed) ⇒ Object
- #start ⇒ Object
-
#step_power(power, deg1, deg2, deg3, brake = Lignite::BRAKE) ⇒ Object
TODO better param protocol?.
-
#step_speed(speed, deg1, deg2, deg3, brake = Lignite::BRAKE) ⇒ Object
tachos.
- #step_sync(speed, turn, tachos, brake = Lignite::BRAKE) ⇒ Object
-
#stop(brake = Lignite::BRAKE) ⇒ Object
ATTR running.
-
#test ⇒ Boolean
ATTR running?.
-
#time_power(power, ms1, ms2, ms3, brake = Lignite::BRAKE) ⇒ Object
msec.
-
#time_speed(speed, ms1, ms2, ms3, brake = Lignite::BRAKE) ⇒ Object
msec.
- #time_sync(speed, turn, ms, brake = Lignite::BRAKE) ⇒ Object
Constructor Details
#initialize(layer, nos, dc = Lignite::DirectCommands.new) ⇒ Motors
Returns a new instance of Motors.
30 31 32 33 34 |
# File 'lib/lignite/motors.rb', line 30 def initialize(layer, nos, dc = Lignite::DirectCommands.new) @layer = layer @nos = nos @dc = dc end |
Instance Attribute Details
#dc ⇒ Lignite::DirectCommands (readonly)
12 13 14 |
# File 'lib/lignite/motors.rb', line 12 def dc @dc end |
#layer ⇒ Object (readonly)
do the DCs spawn independent threads?? must run ready in the same block?
9 10 11 |
# File 'lib/lignite/motors.rb', line 9 def layer @layer end |
#nos ⇒ Object (readonly)
Returns the value of attribute nos.
10 11 12 |
# File 'lib/lignite/motors.rb', line 10 def nos @nos end |
Instance Method Details
#clr_count ⇒ Object
zero tachos, for use as sensor
152 153 154 |
# File 'lib/lignite/motors.rb', line 152 def clr_count dc.output_clr_count(layer, nos) end |
#get_count ⇒ Object
rubocop:disable Naming/AccessorMethodName, upstream API name
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/lignite/motors.rb', line 156 def get_count # rubocop:disable Naming/AccessorMethodName, upstream API name layer = @layer nos_as_indices.map do |no| tachos = dc.with_reply do data32 :tachos block do output_get_count(layer, no, :tachos) end end tachos end end |
#nos_as_bits ⇒ Object
0x02 | 0x04 | 0x08 -> [0x02, 0x04, 0x08]
23 24 25 26 27 28 |
# File 'lib/lignite/motors.rb', line 23 def nos_as_bits r = [1, 2, 4, 8].find_all do |n| (nos & n) != 0 end r end |
#nos_as_indices ⇒ Object
0x02 | 0x04 | 0x08 -> [1, 2, 3]
15 16 17 18 19 20 |
# File 'lib/lignite/motors.rb', line 15 def nos_as_indices r = [0, 1, 2, 3].find_all do |n| (nos & (1 << n)) != 0 end r end |
#polarity(pol) ⇒ Object
ATTR ~polarity
78 79 80 |
# File 'lib/lignite/motors.rb', line 78 def polarity(pol) dc.output_polarity(layer, nos, pol) end |
#power(power) ⇒ Object
ATTR power ~ speed ?
65 66 67 |
# File 'lib/lignite/motors.rb', line 65 def power(power) dc.output_power(layer, nos, power) # does this start them also? end |
#prg_stop ⇒ Object
WTF?
170 171 172 |
# File 'lib/lignite/motors.rb', line 170 def prg_stop dc.output_prg_stop end |
#read ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lignite/motors.rb', line 82 def read layer = @layer nos_as_indices.map do |no| speed_tacho_pair = dc.with_reply do data32 :tacho data8 :speed block do output_read(layer, no, :speed, :tacho) end end speed_tacho_pair end end |
#ready ⇒ Object
which commands are affected? not output_start they say
111 112 113 |
# File 'lib/lignite/motors.rb', line 111 def ready dc.output_ready(layer, nos) end |
#reset ⇒ Object
ATTR tacho, like degrees
55 56 57 |
# File 'lib/lignite/motors.rb', line 55 def reset dc.output_reset(lay, nos) # tacho counts end |
#set_type ⇒ Object
the type is an OUT param so the VM SETs and we GET to learn the type?
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lignite/motors.rb', line 39 def set_type layer = @layer nos_as_indices.map do |no| type = dc.with_reply do data8 :type block do output_set_type(layer, no, :type) end end type end end |
#speed(speed) ⇒ Object
69 70 71 |
# File 'lib/lignite/motors.rb', line 69 def speed(speed) dc.output_speed(layer, nos, speed) # does this start them also? end |
#start ⇒ Object
73 74 75 |
# File 'lib/lignite/motors.rb', line 73 def start dc.output_start(layer, nos) # apparently not end |
#step_power(power, deg1, deg2, deg3, brake = Lignite::BRAKE) ⇒ Object
TODO better param protocol?
117 118 119 |
# File 'lib/lignite/motors.rb', line 117 def step_power(power, deg1, deg2, deg3, brake = Lignite::BRAKE) dc.output_step_power(layer, nos, power, deg1, deg2, deg3, brake) end |
#step_speed(speed, deg1, deg2, deg3, brake = Lignite::BRAKE) ⇒ Object
tachos
129 130 131 |
# File 'lib/lignite/motors.rb', line 129 def step_speed(speed, deg1, deg2, deg3, brake = Lignite::BRAKE) dc.output_step_speed(layer, nos, speed, deg1, deg2, deg3, brake) end |
#step_sync(speed, turn, tachos, brake = Lignite::BRAKE) ⇒ Object
143 144 145 |
# File 'lib/lignite/motors.rb', line 143 def step_sync(speed, turn, tachos, brake = Lignite::BRAKE) dc.output_step_sync(layer, nos, speed, turn, tachos, brake) end |
#stop(brake = Lignite::BRAKE) ⇒ Object
ATTR running
60 61 62 |
# File 'lib/lignite/motors.rb', line 60 def stop(brake = Lignite::BRAKE) dc.output_stop(layer, nos, brake) end |
#test ⇒ Boolean
ATTR running?
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/lignite/motors.rb', line 98 def test layer = @layer nos = @nos busy = dc.with_reply do data8 :busy block do output_test(layer, nos, :busy) end end busy != 0 end |
#time_power(power, ms1, ms2, ms3, brake = Lignite::BRAKE) ⇒ Object
msec
123 124 125 |
# File 'lib/lignite/motors.rb', line 123 def time_power(power, ms1, ms2, ms3, brake = Lignite::BRAKE) dc.output_time_power(layer, nos, power, ms1, ms2, ms3, brake) end |