Example #1
0
 private void Front_ObstacleDetection_ObstacleDetected(Sensor.ObstacleDetection.DetectionState arg1, double arg2)
 {
     // If AvoideObstacle is set, check for the detection state
     if (AvoidObstacle == true)
     {
         // Verify detection state and current driving state, if matched, stop robot
         if (arg1 == Sensor.ObstacleDetection.DetectionState.Detected && MotorDriver.CurrentState == MotorDriver.State.MovingForward)
         {
             MotorDriver.Stop();
             Debug.WriteLine("Robot stopped! (Obstacle Detected)");
         }
     }
 }
Example #2
0
        public MainPage()
        {
            this.InitializeComponent();

            // Initialize Motor Driver Pins
            MotorDriver.InitializePins(MotorDriver.AvailableGpioPin.GpioPin_5, MotorDriver.AvailableGpioPin.GpioPin_6, MotorDriver.AvailableGpioPin.GpioPin_13, MotorDriver.AvailableGpioPin.GpioPin_26);

            // Initialize MyRecognizer and Load Grammar
            InitializeSpeechRecognizer();

            // Initialize front distance sensor
            Sensor.UltrasonicDistanceSensor Front_DistanceSensor = new Sensor.UltrasonicDistanceSensor(Sensor.UltrasonicDistanceSensor.AvailableGpioPin.GpioPin_12, Sensor.UltrasonicDistanceSensor.AvailableGpioPin.GpioPin_16);

            // Initialize ObstacleDetection object
            Sensor.ObstacleDetection Front_ObstacleDetection = new Sensor.ObstacleDetection(Front_DistanceSensor);
            Front_ObstacleDetection.ObstacleDetected += Front_ObstacleDetection_ObstacleDetected;
        }
Example #3
0
        /// <summary>
        /// Fires when MyRecognizer successfully parses a speech
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void MyRecognizer_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
        {
            // Write Debug Information
            Debug.WriteLine(args.Result.Text);

            // Drive robot on recognized speech
            switch (args.Result.Text)
            {
            case "move forward":
                MotorDriver.MoveForward();
                break;

            case "move reverse":
                MotorDriver.MoveReverse();
                break;

            case "turn right":
                MotorDriver.TurnRight();
                break;

            case "turn left":
                MotorDriver.TurnLeft();
                break;

            case "stop":
                MotorDriver.Stop();
                break;

            case "engage obstacle detection":
                AvoidObstacle = true;
                break;

            case "disengage obstacle detection":
                AvoidObstacle = false;
                break;

            default:
                break;
            }

            // Turn on/off obstacle detection
        }