class Motor::Motor
Attributes
free_speed[R]
max_power[R]
quantity[R]
stall_current[R]
stall_torque[R]
Public Class Methods
new()
click to toggle source
# File lib/vex-motors.rb, line 9 def initialize @quantity = 1 end
Public Instance Methods
current(speed: nil, torque: nil)
click to toggle source
# File lib/vex-motors.rb, line 13 def current(speed: nil, torque: nil) unless speed.nil? return @stall_current * (@free_speed - speed) / @free_speed end unless torque.nil? return @stall_current * torque / @stall_torque end end
set_quantity(qty)
click to toggle source
Sets the # of motors being used.
Note: because this may be called in initialize, we rely on the @quantity value to default to one (and not be nil) - this is set in the super initialize in Motor
.
# File lib/vex-motors.rb, line 50 def set_quantity(qty) #should be quantity=(), but then calling from child doesn't work? @stall_current *= qty / @quantity @stall_torque *= qty / @quantity @max_power *= qty / @quantity @quantity = qty end
speed(current: nil, torque: nil)
click to toggle source
# File lib/vex-motors.rb, line 23 def speed(current: nil, torque: nil) unless current.nil? return @free_speed * (@stall_current - current) / @stall_current end unless torque.nil? return @free_speed * (@stall_torque - torque) / @stall_torque end end
torque(speed: nil, current: nil)
click to toggle source
# File lib/vex-motors.rb, line 33 def torque(speed: nil, current: nil) unless speed.nil? return @stall_torque * (@free_speed - speed) / @free_speed end unless current.nil? return @stall_torque * current / @stall_current end end