protected void DoCommand(byte[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (buffer.Length == 0) { throw new ArgumentException("Buffer is empty."); } // Roomba will ignore commands if it gets them too quickly. // Check when it executed it's last command, and sleep // until we've reached the lag time if it was too recent. // TODO better way to handle command lag/command queing var lastRun = (DateTime.Now - _lastCommand); if (lastRun < _commandLag) { System.Threading.Thread.Sleep(_commandLag - lastRun); } _communicationService.DoCommand(buffer); _lastCommand = DateTime.Now; }