Class: Klear::Motors

Inherits:
Object
  • Object
show all
Defined in:
lib/klear/motors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blade_count, frames = nil) ⇒ Motors

Returns a new instance of Motors.



9
10
11
12
13
# File 'lib/klear/motors.rb', line 9

def initialize blade_count, frames = nil
  @count = blade_count
  @frames = frames || [[0] * @count] # init with one frame
  @frame_count ||= @frames.size
end

Instance Attribute Details

#countObject (readonly) Also known as: blade_count

class Data < BinData::Record

array :numbers, :type => :uint16be, :read_until => :eof

end



6
7
8
# File 'lib/klear/motors.rb', line 6

def count
  @count
end

#frame_countObject (readonly)

class Data < BinData::Record

array :numbers, :type => :uint16be, :read_until => :eof

end



6
7
8
# File 'lib/klear/motors.rb', line 6

def frame_count
  @frame_count
end

Instance Method Details

#each(&blk) ⇒ Object

def frame_count end



18
19
20
21
22
23
# File 'lib/klear/motors.rb', line 18

def each &blk
  #0.upto(@frame_count - 1) do |frame_no|
  (1..@count).each do |motor_no|
    yield(get(motor_no), motor_no)
  end
end

#frame(frame_no) ⇒ Object

frame_no is zero based!!!



34
35
36
37
38
# File 'lib/klear/motors.rb', line 34

def frame frame_no
  (0 <= frame_no) or (raise "invalid negative frame no: #{frame_no}")
  (frame_no < @frame_count) or (raise "frame no out of bound: #{frame_no}")
  @frames[frame_no]
end

#get(motor_no) ⇒ Object

motor_no is one-based!!!



26
27
28
29
30
31
# File 'lib/klear/motors.rb', line 26

def get motor_no
  motor_no = Integer(motor_no)
  (0 < motor_no) or (raise "invalid motor no: #{motor_no}")
  (motor_no <= @count) or (raise "motor no out of bounds: #{motor_no}")
  @frames.map {|frame| frame[motor_no-1]}
end

#render(motor_no, options = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/klear/motors.rb', line 40

def render motor_no, options = {}
  low = options[:low] || 0
  high = options[:high] || 20000
  values = get(motor_no)
  values = f14jj(values)
  values = project(values, low, high)
end

#render_all(options = {}) ⇒ Object



48
49
50
51
52
# File 'lib/klear/motors.rb', line 48

def render_all options = {}
  low = options[:low] || 0
  high = options[:high] || 20000
  (1..@count).map {|i| render(i, low, high)}
end