public ObjectTrackingController()
        {
            ZumoMotorShieldConfig config;
            config = new ZumoMotorShieldConfig();
            config.LeftMotorDirPin = 5;
            config.RightMotorDirPin = 4;
            config.LeftPwmChannel = 1;
            config.RightPwmChannel = 0;
            config.BuzzerPwmChannel = 2;
            config.PwmDriverSlaveAddress = 0x40;

            watch = new Stopwatch();

            motorDriver = new ZumoMotorShield(config);
            pixyCam = new PixyCam();
            panLoop = new ServoLoop(200, 200);
            tiltLoop = new ServoLoop(150, 200);
        }
Exemplo n.º 2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (pixyCam == null)
            {
                pixyCam = new PixyCam();

                // Initialize camera
                await pixyCam.Init();
            }

            if (!isCameraThreadRunning)
            {
                stopCameraThread = false;

                // Set LED to blue
                pixyCam.SetLED(0, 0, 255);
                
                // Start reading frames from camera
                await ThreadPool.RunAsync((s) =>
                {
                    isCameraThreadRunning = true;

                    while (!stopCameraThread)
                    {
                        var blocks = pixyCam.GetBlocks(10);

                        if (blocks != null && blocks.Count > 0)
                        {
                            var trackedBlock = trackBlock(blocks.ToArray());
                            if (trackedBlock != null)
                            {
                                followBlock(trackedBlock);
                                updateUI(trackedBlock);
                            }
                        }
                    }

                    isCameraThreadRunning = false;
                });
            }
        }
Exemplo n.º 3
0
        public ObjectTrackingController()
        {
            ZumoMotorShieldConfig config;
            config = new ZumoMotorShieldConfig();
            config.LeftMotorDirPin = 5;
            config.RightMotorDirPin = 4;
            config.LeftPwmChannel = 1;
            config.RightPwmChannel = 0;
            config.BuzzerPwmChannel = 2;
            config.PwmDriverSlaveAddress = 0x40;

            watch = new Stopwatch();

            motorDriver = new ZumoMotorShield(config);
            pixyCam = new PixyCam();
            panLoop = new ServoLoop(200, 200);
            tiltLoop = new ServoLoop(150, 200);

            stateMachine = new Dictionary<ControllerStateID, ControllerState>();
            stateMachine.Add(ControllerStateID.Scan, new ScanState(this));
            stateMachine.Add(ControllerStateID.Track, new TrackState(this));
            stateMachine.Add(ControllerStateID.Follow, new FollowState(this));
            currentState = ControllerStateID.Scan;
        }