class BBB::Components::ESC
Attributes
max_duty[RW]
min_duty[RW]
period[RW]
Public Class Methods
new(options={})
click to toggle source
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.
# 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
Public Instance Methods
arm()
click to toggle source
# File lib/BBB/components/esc.rb, line 48 def arm pwm.run=1 end
armed?()
click to toggle source
# File lib/BBB/components/esc.rb, line 52 def armed? pwm.run == 1 end
calibrate()
click to toggle source
# 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
disarm()
click to toggle source
# File lib/BBB/components/esc.rb, line 56 def disarm pwm.run=0 end
disarmed?()
click to toggle source
# File lib/BBB/components/esc.rb, line 60 def disarmed? !armed? end
duty=(value)
click to toggle source
# File lib/BBB/components/esc.rb, line 64 def duty=(value) @duty = value synchronize_duty end
period=(value)
click to toggle source
# File lib/BBB/components/esc.rb, line 69 def period=(value) @period = value synchronize_period end
pwm()
click to toggle source
# File lib/BBB/components/esc.rb, line 74 def pwm pin end
speed(value)
click to toggle source
# File lib/BBB/components/esc.rb, line 29 def speed(value) @speed = value @duty = max_duty - value * duty_range synchronize_duty end
Private Instance Methods
after_pin_initialization()
click to toggle source
# File lib/BBB/components/esc.rb, line 88 def after_pin_initialization disarm synchronize_period speed(0) end
duty_range()
click to toggle source
# File lib/BBB/components/esc.rb, line 80 def duty_range max_duty - min_duty end
synchronize_period()
click to toggle source
# File lib/BBB/components/esc.rb, line 84 def synchronize_period pwm.period = @period end