Exemple #1
0
        private async void DoWork3(object sender, DoWorkEventArgs e)
        {
            var driver = new TwoMotorsDriver(new Motor(27, 22), new Motor(5, 6));
            var ultrasonicDistanceSensor = new UltrasonicDistanceSensor(23, 24);

            await WriteLog("Moving forward");

            while (_worker2 != null && !_worker2.CancellationPending)
            {
                driver.MoveForward();

                await Task.Delay(200);

                var distance = await ultrasonicDistanceSensor.GetDistanceInCmAsync(1000);

                if (distance > 35.0)
                {
                    continue;
                }

                await WriteLog($"Obstacle found at {distance} cm or less. Turning right");

                await driver.TurnRightAsync();

                await WriteLog("Moving forward");
            }
        }
Exemple #2
0
        private void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            _twoMotorsDriver = new TwoMotorsDriver(new Motor(6, 5), new Motor(13, 26));
            _uln2003Driver = new Uln2003Driver(16, 12, 25, 24);
            _ultrasonicDistanceSensor = new UltrasonicDistanceSensor(4, 27);

            _worker = new BackgroundWorker();
            _worker.DoWork += QueueListener_DoWork;
            _worker.RunWorkerAsync();

            _worker2 = new BackgroundWorker();
            _worker2.DoWork += AvoidCrash_DoWork;
            _worker2.RunWorkerAsync();
        }
Exemple #3
0
        private void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            _twoMotorsDriver          = new TwoMotorsDriver(new Motor(6, 5), new Motor(13, 26));
            _uln2003Driver            = new Uln2003Driver(16, 12, 25, 24);
            _ultrasonicDistanceSensor = new UltrasonicDistanceSensor(4, 27);

            _worker         = new BackgroundWorker();
            _worker.DoWork += DoWork;
            _worker.RunWorkerAsync();

            _worker2         = new BackgroundWorker();
            _worker2.DoWork += DoWork2;
            _worker2.RunWorkerAsync();
        }
Exemple #4
0
        private async void DoWork3(object sender, DoWorkEventArgs e)
        {
            var driver = new TwoMotorsDriver(new Motor(27, 22), new Motor(5, 6));
            var ultrasonicDistanceSensor = new UltrasonicDistanceSensor(23, 24);

            await WriteLog("Moving forward");

            while (_worker2 != null && !_worker2.CancellationPending)
            {
                driver.MoveForward();

                await Task.Delay(200);

                var distance = await ultrasonicDistanceSensor.GetDistanceInCmAsync(1000);
                if (distance > 35.0)
                    continue;

                await WriteLog($"Obstacle found at {distance} cm or less. Turning right");

                await driver.TurnRightAsync();

                await WriteLog("Moving forward");
            }
        }