Exemple #1
0
        /// <summary>
        /// Set robot based on the string from the form button pressed.
        /// </summary>
        /// <param name="type">Which robot to start.</param>
        private void InitialiseRobot(string type)
        {
            buttonPredator.Enabled    = true;
            buttonUser.Enabled        = true;
            buttonPredatorFSM.Enabled = true;
            picBoxUserLabels.Visible  = false;
            SetFilterChangerVisibility(false);

            if (robot != null)
            {
                robot.KillThreads();
                while (robot_thread.ThreadState != System.Threading.ThreadState.Stopped && robot_thread.ThreadState != System.Threading.ThreadState.WaitSleepJoin)
                {
                    System.Threading.Thread.Sleep(1);
                }

                if (map != null)
                {
                    map.Hide();
                    map = null;
                }
            }

            if (type == "Predator")
            {
                buttonPredator.Enabled = false;
                map = new Map((robot as Rovio.BaseArena), Controls, 387, 18);
                map.UpdatePicBox += UpdatePictureBox;
                robot             = new Rovio.PredatorMap(robotURL, "user", "password", map, currentKeys);
                (robot as Rovio.BaseArena).SourceImage += UpdateImage;


                map.SetUpdate((robot as Rovio.BaseArena));

                updateTimer.Start();

                if (valueDict.Count == 0)
                {
                    ReadDictValues();
                }

                (robot as Rovio.BaseArena).SetFilters(valueDict);
                robot_thread = new System.Threading.Thread(robot.Start);
                robot_thread.Start();
            }
            else if (type == "PredatorSimple")
            {
                if (map != null)
                {
                    map.Hide();
                }
                robot = new Rovio.PredatorSimple(robotURL, "user", "password", map, currentKeys);
                (robot as Rovio.BaseArena).SourceImage += UpdateImage;

                updateTimer.Start();

                if (valueDict.Count == 0)
                {
                    ReadDictValues();
                }
                (robot as Rovio.BaseArena).SetFilters(valueDict);
                SetFilterChangerVisibility(true);
                robot_thread = new System.Threading.Thread(robot.Start);
                robot_thread.Start();
            }
            else if (type == "User")
            {
                if (map != null)
                {
                    map.Hide();
                }
                robot = new Rovio.UserRobot(robotURL, "user", "password", map, currentKeys);
                (robot as Rovio.UserRobot).SourceImage += UpdateImage;
                picBoxUserLabels.Visible = true;
                robot_thread             = new System.Threading.Thread(robot.Start);
                robot_thread.Start();
            }

            if (type == "Predator" || type == "PredatorSimple" || type == "User")
            {
                picboxCameraImage.Location = new Point(20, 22);
                picboxCameraImage.Size     = new Size((int)robot.cameraDimensions.X, (int)robot.cameraDimensions.Y);
                textBoxIP.Enabled          = false;
                buttonPredator.Enabled     = false;
                buttonUser.Enabled         = false;
                buttonPredatorFSM.Enabled  = false;
                buttonStop.Enabled         = true;
                Focus();
            }
            else
            {
                textBoxIP.Enabled  = true;
                buttonStop.Enabled = false;
                robot.KillThreads();
            }
        }
Exemple #2
0
        /// <summary>
        /// Set robot based on the string from the form button pressed.
        /// </summary>
        /// <param name="type">Which robot to start.</param>
        private void InitialiseRobot(string type)
        {
            buttonPredator.Enabled = true;
            buttonUser.Enabled = true;
            buttonPredatorFSM.Enabled = true;
            picBoxUserLabels.Visible = false;
            SetFilterChangerVisibility(false);

            if (robot != null)
            {
                robot.KillThreads();
                while (robot_thread.ThreadState != System.Threading.ThreadState.Stopped && robot_thread.ThreadState != System.Threading.ThreadState.WaitSleepJoin)
                    System.Threading.Thread.Sleep(1);

                if (map != null)
                {
                    map.Hide();
                    map = null;
                }
            }

            if (type == "Predator")
            {
                buttonPredator.Enabled = false;
                map = new Map((robot as Rovio.BaseArena), Controls, 387, 18);
                map.UpdatePicBox += UpdatePictureBox;
                robot = new Rovio.PredatorMap(robotURL, "user", "password", map, currentKeys);
                (robot as Rovio.BaseArena).SourceImage += UpdateImage;

                map.SetUpdate((robot as Rovio.BaseArena));

                updateTimer.Start();

                if (valueDict.Count == 0)
                    ReadDictValues();

                (robot as Rovio.BaseArena).SetFilters(valueDict);
                robot_thread = new System.Threading.Thread(robot.Start);
                robot_thread.Start();
            }
            else if (type == "PredatorSimple")
            {
                if (map != null)
                    map.Hide();
                robot = new Rovio.PredatorSimple(robotURL, "user", "password", map, currentKeys);
                (robot as Rovio.BaseArena).SourceImage += UpdateImage;

                updateTimer.Start();

                if (valueDict.Count == 0)
                    ReadDictValues();
                (robot as Rovio.BaseArena).SetFilters(valueDict);
                SetFilterChangerVisibility(true);
                robot_thread = new System.Threading.Thread(robot.Start);
                robot_thread.Start();
            }
            else if (type == "User")
            {
                if (map != null)
                    map.Hide();
                robot = new Rovio.UserRobot(robotURL, "user", "password", map, currentKeys);
                (robot as Rovio.UserRobot).SourceImage += UpdateImage;
                picBoxUserLabels.Visible = true;
                robot_thread = new System.Threading.Thread(robot.Start);
                robot_thread.Start();
            }

            if (type == "Predator" || type == "PredatorSimple" || type == "User")
            {
                picboxCameraImage.Location = new Point(20, 22);
                picboxCameraImage.Size = new Size((int)robot.cameraDimensions.X, (int)robot.cameraDimensions.Y);
                textBoxIP.Enabled = false;
                buttonPredator.Enabled = false;
                buttonUser.Enabled = false;
                buttonPredatorFSM.Enabled = false;
                buttonStop.Enabled = true;
                Focus();
            }
            else
            {
                textBoxIP.Enabled = true;
                buttonStop.Enabled = false;
                robot.KillThreads();
            }
        }