コード例 #1
0
ファイル: BaseRobot.cs プロジェクト: jblakeLincoln/Rovio
        /// <summary>
        /// Constructor - initialises variables for derived classes.
        /// </summary>
        /// <param name="address">URL of robot.</param>
        /// <param name="user">Username for robot.</param>
        /// <param name="password">Password for robot.</param>
        /// <param name="matrix">Map to be used (null value is acceptable).</param>
        /// <param name="k">Keyboard dictionary.</param>
        public BaseRobot(string address, string user, string password, Map m, Object k)
            : base(address, user, password)
        {
            map = m;
            keys = (List<int>)k;

            try { API.Movement.GetLibNSVersion(); } // a dummy request
            catch (Exception)
            {
                //simple way of getting feedback in the form mode
                System.Windows.Forms.MessageBox.Show("Could not connect to the robot");
                cameraDimensions = new System.Drawing.Point(352, 288);
                connected = false;
                //cameraImage = new Bitmap("example.jpg");
                Environment.Exit(0);
            }

            cameraDimensions = System.Drawing.Point.Empty;

            lock (commandLock)
            {
                Camera.Resolution = Rovio.API.Camera.ImageResolution.CIF;

                if (Camera.Resolution == Rovio.API.Camera.ImageResolution.CIF)
                    cameraDimensions = new System.Drawing.Point(352, 288);
                else if (Camera.Resolution == Rovio.API.Camera.ImageResolution.QCIF)
                    cameraDimensions = new System.Drawing.Point(176, 114);
                else if (Camera.Resolution == Rovio.API.Camera.ImageResolution.CGA)
                    cameraDimensions = new System.Drawing.Point(320, 240);
                else
                    cameraDimensions = new System.Drawing.Point(640, 480);
            }

            threadKeyboardInput = new System.Threading.Thread(KeyboardStart);
            threadKeyboardInput.Start();
            threadCameraImage = new System.Threading.Thread(ImageGet);
            threadCameraImage.Start();
        }
コード例 #2
0
ファイル: UserRobot.cs プロジェクト: jblakeLincoln/Rovio
 public UserRobot(string address, string user, string password, Map m, Object k)
     : base(address, user, password, m, k)
 {
 }
コード例 #3
0
ファイル: PredatorMap.cs プロジェクト: jblakeLincoln/Rovio
 public PredatorMap(string address, string user, string password, Map m, Object k)
     : base(address, user, password, m, k)
 {
 }
コード例 #4
0
ファイル: PredatorSimple.cs プロジェクト: jblakeLincoln/Rovio
 public PredatorSimple(string address, string user, string password, Map m, Object k)
     : base(address, user, password, m, k)
 {
     // map = matrix;
 }
コード例 #5
0
ファイル: ArenaBot.cs プロジェクト: jblakeLincoln/Rovio
 public BaseArena(string address, string user, string password, Map m, Object k)
     : base(address, user, password, m, k)
 {
 }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: jblakeLincoln/Rovio
        /// <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();
            }
        }