# File lib/commands/move.rb, line 51
  def start
    @ports.each do |p|
      @nxt.reset_motor_position(NXTComm.const_get("MOTOR_#{p.to_s.upcase}"))
    end

    if @direction == :stop
      motor_power = 0
      mode        = NXTComm::COAST
      run_state   = NXTComm::MOTOR_RUN_STATE_IDLE
    else
      @direction == :forward ? motor_power = @power : motor_power = -@power
      mode        = NXTComm::MOTORON | NXTComm::BRAKE
      run_state   = NXTComm::MOTOR_RUN_STATE_RUNNING
    end

    if @ports.size == 2
      mode |= NXTComm::REGULATED
      reg_mode = NXTComm::REGULATION_MODE_MOTOR_SYNC

      case @steering[:direction]
        when :straight
          turn_ratio = 0
        when :spin_left
          turn_ratio = -100
        when :spin_right
          turn_ratio = 100
        when :left
          @steering[:power].nil? ? turn_ratio = -50 : turn_ratio = -@steering[:power]
        when :right
          @steering[:power].nil? ? turn_ratio = 50 : turn_ratio = @steering[:power]
      end
    else
      reg_mode = NXTComm::REGULATION_MODE_IDLE
      turn_ratio = 0
    end
    
    if @duration.class == Hash
      if @duration[:rotations]
        tacho_limit = @duration[:rotations] * 360
      end
    
      if @duration[:degrees]
        tacho_limit = @duration[:degrees]
      end
    
      if @duration[:seconds]
        tacho_limit = 0
      end
    else
      tacho_limit = 0
    end
    
    if @ports.include?(:a) and @ports.include?(:b) and @ports.include?(:c)
      @nxt.set_output_state(
        NXTComm::MOTOR_ALL,
        motor_power,
        mode,
        reg_mode,
        turn_ratio,
        run_state,
        tacho_limit
      )
    else
      @ports.each do |p|
        @nxt.set_output_state(
          NXTComm.const_get("MOTOR_#{p.to_s.upcase}"),
          motor_power,
          mode,
          reg_mode,
          turn_ratio,
          run_state,
          tacho_limit
        )
      end
    end
    
    unless @duration == :unlimited
      if @duration[:seconds]
        sleep(@duration[:seconds])
      else
        until self.run_state[@ports[0]] == NXTComm::MOTOR_RUN_STATE_IDLE
          sleep(0.25)
        end
      end
      self.stop
    end
  end