/// <summary> /// Move Rovio forwards and backwards. /// </summary> /// <param name="iterations">Number of times to loop through.</param> /// <param name="speed">Movement speed (1-10 highest to lowest). Negative value to move backwards.</param> protected void MoveForward(int iterations, int speed) { lock (commandLock) for (int i = 0; i < iterations; i++) { if (speed < 0) { Drive.Backward(Math.Abs(speed)); } else { Drive.Forward(speed); } } }
/// <summary> /// Implement base class method to define user input. /// </summary> protected override void KeyboardInput() { if (keys.Count > 0) { moving = true; } if (keys.Contains(87)) { Drive.Forward(1); } else if (keys.Contains(81)) { Drive.RotateLeft(5); } else if (keys.Contains(69)) { Drive.RotateRight(5); } else if (keys.Contains(83)) { Drive.Backward(1); } else if (keys.Contains(65)) { Drive.DiagForwardLeft(1); } else if (keys.Contains(68)) { Drive.DiagForwardRight(1); } else if (keys.Count == 0 && moving) { Drive.Stop(); moving = false; } }
//Move forward/backward at speed velocity for revolutions of repetions public void DriveStraight(int velocity, int repetitions) { if ((velocity > 0) && (velocity < 11)) { for (int x = 0; x < repetitions; x++) { Drive.Forward(velocity); } } else if ((velocity < 0) && (velocity > -11)) { velocity = velocity * -1; for (int x = 0; x < repetitions; x++) { Drive.Backward(velocity); } } else { System.Windows.Forms.MessageBox.Show("Invalid Command"); } }