Method: Request::Choregraphy#move

Defined in:
lib/violet/request.rb

#move(command) ⇒ Object

Raises:



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/violet/request.rb', line 438

def move command
  raise BadChorDesc.new('wrong Choregraphy description')    unless command.is_a?(EarCommandStruct)
  raise BadChorDesc.new('need a time')                      unless command.time
  raise BadChorDesc.new('time must be >= zero')             unless command.time.to_i >= 0
  raise BadChorDesc.new('need an angle')                    unless command.angle
  raise BadChorDesc.new('angle must be between 0 and 180')  unless (0..180).include?(command.angle)
  raise BadChorDesc.new('need a direction')                 unless command.direction
  raise BadChorDesc.new('wrong direction')                  unless command.direction.between?(Ears::Directions::FORWARD,Ears::Directions::BACKWARD)
  raise BadChorDesc.new('need an element')                  unless command.element
  raise BadChorDesc.new('wrong element')                    unless command.element == :both or command.element.between?(Ears::Positions::RIGHT,Ears::Positions::LEFT)

  template = '%s,motor,%s,%s,0,%s'

  if command.element == :both
    # we don't know, maybe your rabbit has more than two ears :)
    (Ears::Positions.constants - ['BOTH']).each do |cste_name|
      cste = Helpers.constantize "#{self.class}::Ears::Positions::#{cste_name}"
      @chor << template % [ command.time.to_i, cste,  command.angle, command.direction ]
    end
  else
    @chor << template % [ command.time.to_i,  command.element, command.angle, command.direction ]
  end
end