Class: RapiroWrapper::Body
- Inherits:
-
Object
- Object
- RapiroWrapper::Body
- Defined in:
- lib/rapiro_wrapper/body.rb
Overview
Controll class for RAPIRO
Instance Method Summary collapse
- #execute!(duration = 10) ⇒ Object
-
#initialize(device = '/dev/ttyAMA0') ⇒ Body
constructor
A new instance of Body.
- #sequences(duration = 10) ⇒ Object
Constructor Details
#initialize(device = '/dev/ttyAMA0') ⇒ Body
Returns a new instance of Body.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rapiro_wrapper/body.rb', line 4 def initialize(device = '/dev/ttyAMA0') @commander = RapiroWrapper::Commander.new(device) servo_class = RapiroWrapper::ServoMotor.find_servos @servos = servo_class.inject({}) do |hash, klass| class_name = klass.to_s snake_case = class_name.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_').downcase hash[snake_case.split('/').last] = klass hash end @servos['eyes'] = RapiroWrapper::Eyes @servos.each do |s, k| self.class.class_eval " def \#{s}=(val)\n @\#{s} = \#{k}.new(val)\n end\n\n def \#{s}\n @\#{s}\n end\n EOF\n instance_variable_set('@'.concat(s).to_sym, k.new)\n end\nend\n" |
Instance Method Details
#execute!(duration = 10) ⇒ Object
39 40 41 |
# File 'lib/rapiro_wrapper/body.rb', line 39 def execute!(duration = 10) @commander.write(sequences(duration)) end |
#sequences(duration = 10) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/rapiro_wrapper/body.rb', line 32 def sequences(duration = 10) @commander.sequences( @servos.keys.map { |k| instance_variable_get('@'.concat(k).to_sym) }, duration ) end |