class Lignite::Motors

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.

Attributes

dc[R]

@return [Lignite::DirectCommands]

layer[R]

do the DCs spawn independent threads?? must run ready in the same block?

nos[R]

Public Class Methods

new(layer, nos, dc = Lignite::DirectCommands.new) click to toggle source
# File lib/lignite/motors.rb, line 30
def initialize(layer, nos, dc = Lignite::DirectCommands.new)
  @layer = layer
  @nos = nos
  @dc = dc
end

Public Instance Methods

clr_count() click to toggle source

zero tachos, for use as sensor

# File lib/lignite/motors.rb, line 152
def clr_count
  dc.output_clr_count(layer, nos)
end
get_count() click to toggle source
# 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() click to toggle source

0x02 | 0x04 | 0x08 -> [0x02, 0x04, 0x08]

# 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() click to toggle source

0x02 | 0x04 | 0x08 -> [1, 2, 3]

# 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) click to toggle source

ATTR ~polarity

# File lib/lignite/motors.rb, line 78
def polarity(pol)
  dc.output_polarity(layer, nos, pol)
end
power(power) click to toggle source

ATTR power ~ speed ?

# File lib/lignite/motors.rb, line 65
def power(power)
  dc.output_power(layer, nos, power) # does this start them also?
end
prg_stop() click to toggle source

WTF?

# File lib/lignite/motors.rb, line 170
def prg_stop
  dc.output_prg_stop
end
read() click to toggle source
# 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() click to toggle source

which commands are affected? not output_start they say

# File lib/lignite/motors.rb, line 111
def ready
  dc.output_ready(layer, nos)
end
reset() click to toggle source

ATTR tacho, like degrees

# File lib/lignite/motors.rb, line 55
def reset
  dc.output_reset(lay, nos) # tacho counts
end
set_type() click to toggle source

the type is an OUT param so the VM SETs and we GET to learn the type?

# 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) click to toggle source
# File lib/lignite/motors.rb, line 69
def speed(speed)
  dc.output_speed(layer, nos, speed) # does this start them also?
end
start() click to toggle source
# 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) click to toggle source

@param power [Integer] -100..100 TODO better param protocol?

# 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) click to toggle source

@param speed [Integer] -100..100 tachos

# 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) click to toggle source

@param speed [Integer] -100..100 @param turn [Integer] -200..200:

0 straight, 100 stops the right motor, -100 stops the left motor
> 100 reverses the right motor, < -100 reverses the left motor
# 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) click to toggle source

ATTR running

# File lib/lignite/motors.rb, line 60
def stop(brake = Lignite::BRAKE)
  dc.output_stop(layer, nos, brake)
end
test() click to toggle source

ATTR running? @return [Boolean] true if busy/running

# 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) click to toggle source

@param power [Integer] -100..100 msec

# 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
time_speed(speed, ms1, ms2, ms3, brake = Lignite::BRAKE) click to toggle source

@param speed [Integer] -100..100 msec

# File lib/lignite/motors.rb, line 135
def time_speed(speed, ms1, ms2, ms3, brake = Lignite::BRAKE)
  dc.output_time_speed(layer, nos, speed, ms1, ms2, ms3, brake)
end
time_sync(speed, turn, ms, brake = Lignite::BRAKE) click to toggle source
# File lib/lignite/motors.rb, line 147
def time_sync(speed, turn, ms, brake = Lignite::BRAKE)
  dc.output_time_sync(layer, nos, speed, turn, ms, brake)
end