Class: BBB::Components::ESC

Inherits:
Object
  • Object
show all
Includes:
Pinnable
Defined in:
lib/BBB/components/esc.rb

Instance Attribute Summary collapse

Attributes included from Pinnable

#pins, #positions

Instance Method Summary collapse

Methods included from Pinnable

#after_connect_callbacks, #connect, included, #pin, #pinnable?, #set_options, #verify_pin_position_count

Constructor Details

#initialize(options = {}) ⇒ ESC

Initialize a new ESC using default values for period, min_duty and

max_duty if present. Please beware that at initialization stage there
is no initialized PWM pin yet. So you can set the period and the
min/max_duty instance variables, but not the variables on the pin.
Only after "connecting" the esc to a board can you set the duty and
period of the pin. Use the "after pin initialization" method for that.


19
20
21
22
23
24
25
26
27
# File 'lib/BBB/components/esc.rb', line 19

def initialize(options={})
  set_options(options)

  @period = options.fetch(:period, 20e6)
  @speed  = 0

  @min_duty = options.fetch(:min_duty, 17.5e6)
  @max_duty = options.fetch(:max_duty, 19e6)
end

Instance Attribute Details

#max_dutyObject

Returns the value of attribute max_duty.



7
8
9
# File 'lib/BBB/components/esc.rb', line 7

def max_duty
  @max_duty
end

#min_dutyObject

Returns the value of attribute min_duty.



7
8
9
# File 'lib/BBB/components/esc.rb', line 7

def min_duty
  @min_duty
end

#periodObject

Returns the value of attribute period.



7
8
9
# File 'lib/BBB/components/esc.rb', line 7

def period
  @period
end

Instance Method Details

#armObject



48
49
50
# File 'lib/BBB/components/esc.rb', line 48

def arm
  pwm.run=1
end

#armed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/BBB/components/esc.rb', line 52

def armed?
  pwm.run == 1
end

#calibrateObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/BBB/components/esc.rb', line 35

def calibrate
  pwm.run = 0
  puts "Disconnect the battery of the motor (press any key)"; gets
  puts "Get ready to connect the battery after 2 seconds, ready? (press any key)"; gets
  speed(1)
  pwm.run = 1
  puts "one missisipi"; sleep(1)
  puts "two missisipi"; sleep(1)
  puts "connect the battery"; sleep(1)
  speed(0)
  puts "Calibrated and ready to go"
end

#disarmObject



56
57
58
# File 'lib/BBB/components/esc.rb', line 56

def disarm
  pwm.run=0
end

#disarmed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/BBB/components/esc.rb', line 60

def disarmed?
  !armed?
end

#duty=(value) ⇒ Object



64
65
66
67
# File 'lib/BBB/components/esc.rb', line 64

def duty=(value)
  @duty = value
  synchronize_duty
end

#pwmObject



74
75
76
# File 'lib/BBB/components/esc.rb', line 74

def pwm
  pin
end

#speed(value) ⇒ Object



29
30
31
32
33
# File 'lib/BBB/components/esc.rb', line 29

def speed(value)
  @speed = value
  @duty = max_duty - value * duty_range
  synchronize_duty
end