Пример #1
0
        /// <summary>
        /// User clicked on button.  Depending on state machine
        /// state, handle it
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (_appState == ButtonState.NONE)
            {
                var mainThread = new Thread(startvision);
                mainThread.Start();

                _appState         = ButtonState.START_VISION;
                buttonVision.Text = "Stop";
            }
            else if (_appState == ButtonState.START_VISION)
            {
                if (!_hasExitAppSent)
                {
                    _hasExitAppSent = true;
                    VisionSensor.visionCommand("action=EXITAPP");
                }

                _appState         = ButtonState.STOP_VISION;
                buttonVision.Text = "Exit";
            }
            else if (_appState == ButtonState.STOP_VISION)
            {
                if (!_hasExitAppSent)
                {
                    VisionSensor.visionCommand("action=EXITAPP");
                }

                Close();
            }
        }
Пример #2
0
 /// <summary>
 /// Form is closing. Quit vision
 /// </summary>
 /// <param name="sender">event sender</param>
 /// <param name="e">event args</param>
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!_hasExitAppSent)
     {
         VisionSensor.visionCommand("action=EXITAPP");
     }
 }
Пример #3
0
        /// <summary>
        /// Detects cameras installed on the computer and if reqd,
        /// asks the user to select from the list.  Saves the
        /// list of currently active cameras so if any change is detected
        /// the next time ACAT is run, we can display the list again.
        /// Also instructs ACAT Vision to use the selected camera
        /// </summary>
        /// <returns></returns>
        private bool detectAndSetPreferredCamera()
        {
            var  installedCameras = Cameras.GetCameraNames();
            var  preferredCamera  = String.Empty;
            bool retVal           = true;

            if (hasCameraListChanged() || !isCameraInstalled(VisionActuatorSettings.PreferredCamera))
            {
                VisionActuatorSettings.CameraList = installedCameras.ToArray();

                // if there is more than one camera, let the user pick
                if (installedCameras.Count() > 1)
                {
                    var form = new CameraSelectForm
                    {
                        CameraNames      = installedCameras,
                        Prompt           = R.GetString("SelectCamera"),
                        OKButtonText     = R.GetString("OK"),
                        CancelButtonText = R.GetString("Cancel"),
                        Name             = _title
                    };

                    var result = form.ShowDialog();

                    if (result == DialogResult.Cancel)
                    {
                        MessageBox.Show(R.GetString("NoCameraSelectedVisionWillNotBeActivated"),
                                        _title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        retVal = false;
                    }
                    else
                    {
                        MessageBox.Show(String.Format(R.GetString("SelectedCamera"), form.SelectedCamera),
                                        _title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);

                        preferredCamera = form.SelectedCamera;
                    }
                }
                else
                {
                    preferredCamera = installedCameras.ElementAt(0);
                }
            }
            else
            {
                preferredCamera = VisionActuatorSettings.PreferredCamera;
            }

            VisionActuatorSettings.PreferredCamera = preferredCamera;

            VisionActuatorSettings.Save();

            VisionSensor.selectCamera(preferredCamera);

            return(retVal);
        }
Пример #4
0
        private static bool NoShields(BotController myself, BotController target)
        {
            VisionSensor visSensor = myself.GetComponentInChildren <VisionSensor>();

            return(visSensor == null || visSensor.BotHasPartOfType(target, "Reflective Armor") &&
                   visSensor.PartsOnBotOfType <ReflectiveArmorController>(target, "Reflective Armor")[0].CanReflect());
        }
Пример #5
0
 // Start is called before the first frame update
 void Start()
 {
     myAnimator = GetComponent <Animator>();
     estado     = 0;
     InvokeRepeating("changeState", 4, 3);
     vision = GetComponentInChildren <VisionSensor>();
     grassTiles.GetComponent <grassTiles>();
 }
Пример #6
0
        /// <summary>
        /// Thread function that runs the vision module (which is
        /// a blocking call)
        /// </summary>
        private void visionThread()
        {
            _visionSensorCallback = callbackFromVision;

            VisionSensor.SetVisionEventHandler(_visionSensorCallback);

            VisionSensor.acatVision();
        }
Пример #7
0
        /// <summary>
        /// Release resources
        /// </summary>
        /// <returns></returns>
        private void unInit()
        {
            actuatorState = State.Stopped;

            VisionSensor.quit();

            // perform unitialization here
        }
Пример #8
0
 public ChaseState(
     Transform player,
     MovementBehaviour movementBehaviour,
     VisionSensor visionSensor)
 {
     _player            = player;
     _movementBehaviour = movementBehaviour;
     _visionSensor      = visionSensor;
 }
Пример #9
0
        private void Awake()
        {
            _player             = GameObject.FindGameObjectWithTag(Tags.PLAYER).transform;
            _movementBehaviour  = GetComponent <MovementBehaviour>();
            _animationBehaviour = GetComponent <AnimationBehaviour>();
            _visionSensor       = GetComponent <VisionSensor>();

            CreateStages();
        }
Пример #10
0
        /// <summary>
        /// Form load event handler.  Quit if there are no
        /// cameras.  If multiple cameras, let the user select
        /// the preferred one to use
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            Text = _title;

            var _installedCameras = Cameras.GetCameraNames();

            if (!_installedCameras.Any())
            {
                MessageBox.Show("No cameras detected. Exiting",
                                _title,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Close();
                return;
            }

            var preferredCamera = String.Empty;

            if (_installedCameras.Count() > 1)
            {
                var form = new CameraSelectForm
                {
                    CameraNames      = _installedCameras,
                    Name             = _title,
                    Prompt           = "Select Camera",
                    OKButtonText     = "OK",
                    CancelButtonText = "Cancel"
                };

                var result = form.ShowDialog();

                if (result == DialogResult.Cancel)
                {
                    MessageBox.Show("No camera selected.  Exiting", _title);
                    Close();
                    return;
                }

                preferredCamera = form.SelectedCamera;
            }
            else
            {
                preferredCamera = _installedCameras.ElementAt(0);
            }

            VisionSensor.selectCamera(preferredCamera);

            Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width,
                                 Screen.PrimaryScreen.WorkingArea.Height - Height);

            TopMost = false;
            TopMost = true;

            VisionSensor.SetVisionEventHandler(CallbackFromVision);
        }
Пример #11
0
        /// <summary>
        /// Callback from the status form that the user closed
        /// it manually
        /// </summary>
        private void cameraStatusForm_EvtCancel()
        {
            VisionSensor.hideVideoWindow();

            if (_initInProgress)
            {
                _initInProgress = false;
                OnInitDone();
            }
        }
Пример #12
0
 public StrafeState(
     Transform owner,
     Transform player,
     MovementBehaviour movementBehaviour,
     VisionSensor visionSensor)
 {
     _owner             = owner;
     _player            = player;
     _movementBehaviour = movementBehaviour;
     _visionSensor      = visionSensor;
 }
Пример #13
0
 protected override void Awake()
 {
     _aimAngleTolerance = Mathf.Deg2Rad * GetComponent <ConfigurableJoint>().highAngularXLimit.limit;
     base.Awake();
     VisionSensor = GetComponentInChildren <VisionSensor>();
     Gun          = GetComponentInChildren <Gun>();
     if (Gun != null)
     {
         Gun.MountOnto(this);
     }
 }
Пример #14
0
        /// <summary>
        /// Invoked if the calibration is canceled
        /// </summary>
        public override void OnCalibrationCanceled()
        {
            VisionSensor.hideVideoWindow();

            // if we are in the initialization state, signal that
            // we are done
            if (_initInProgress)
            {
                OnInitDone();
                _initInProgress = false;
            }
        }
Пример #15
0
        /// <summary>
        /// Starts calibration of the actuator
        /// </summary>
        public override void StartCalibration()
        {
            try
            {
                Log.Debug("Calling UpdateCalibrationstatus");

                UpdateCalibrationStatus(_title,
                                        R.GetString("CalibratingCameraRemainStill"),
                                        0,
                                        !VisionSensor.isVideoWindowVisible(),
                                        R.GetString("ShowVideo"));
            }
            catch (Exception ex)
            {
                Log.Debug(ex.ToString());
            }
        }
Пример #16
0
        /// <summary>
        /// This is the callback function from ACAT vision. This is
        /// in form of a string.
        /// Format of the string is:
        ///    gesture=gesturetype;action=gestureevent;conf=confidence;time=timestamp;actuate=flag;tag=userdata
        /// where
        ///  gesturetype    is a string representing the gesture. This is used as
        ///                 the 'source' field in the actuator switch object
        ///  gestureevent   should be a valid value from the SwitchAction enum
        ///  confidence     Integer representing the confidence level, for future use
        ///  timestamp      Timestamp of when the switch event triggered (in ticks)
        ///  flag           true/false.  If false, the switch trigger event will be ignored
        ///  userdata       Any user data
        /// Eg
        ///    gesture=G1;action=trigger;conf=75;time=3244394443
        /// </summary>
        /// <param name="text"></param>
        private void callbackFromVision(string text)
        {
            var gesture = String.Empty;

            IActuatorSwitch actuatorSwitch = parseActuatorMsgAndGetSwitch(text, ref gesture);

            if (actuatorSwitch != null)
            {
                triggerEvent(actuatorSwitch);
            }
            else if (gesture == "CALIB_START") // begin camera calibration
            {
                // if the camera status form is currently displayed, close it
                dismissCameraStatus();

                try
                {
                    Log.Debug("Received CALIB_START");

                    Log.Debug("Calling RequestCalibration");
                    RequestCalibration();
                    Log.Debug("Returned from RequestCalibration");
                }
                catch (Exception ex)
                {
                    Log.Debug("Exception " + ex);
                }
            }
            else if (gesture == "CALIB_END") // end camera calibration
            {
                Log.Debug("CALIB_END");

                // if we are in the initialization state, signal that
                // we are done
                if (_initInProgress)
                {
                    OnInitDone();
                    _initInProgress = false;
                }

                VisionSensor.hideVideoWindow();

                OnEndCalibration();
            }
        }
Пример #17
0
        /// <summary>
        /// Initialize the vision actuator.  Detect cameras,
        /// let the user select the preferred camera (if reqd),
        /// spawn threads etc.
        /// </summary>
        /// <returns>true on success, false otherwise</returns>
        public override bool Init()
        {
            Attributions.Add("ACAT Vision",
                             "Open Source Computer Vision Library (OpenCV) is licensed under the BSD license");

            if (!Cameras.GetCameraNames().Any())
            {
                MessageBox.Show(R.GetString("NoCamerasFoundACATVisionDisabled"),
                                _title,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                OnInitDone();

                return(true);
            }

            _initInProgress = true;

            // load settings from the settings file
            Settings.SettingsFilePath = UserManager.GetFullPath(SettingsFileName);
            VisionActuatorSettings    = Settings.Load();

            VisionSensor.init();

            bool retVal = detectAndSetPreferredCamera();

            if (retVal)
            {
                showCameraStatus(R.GetString("InitializingCamera"));

                _acatVisionThread = new Thread(visionThread)
                {
                    IsBackground = true
                };
                _acatVisionThread.Start();
            }
            else
            {
                _initInProgress = false;
                OnInitDone();
            }

            return(retVal);
        }
    private void OnSceneGUI()
    {
        VisionSensor vision = (VisionSensor)target;

        Handles.DrawWireArc(vision.transform.position, Vector3.forward, Vector3.up, 360, vision.radiusVision);


        Vector3 viewAngleDirectionA = vision.DirFromAngle(-vision.angleVision / 2, false);
        Vector3 viewAngleDirectionB = vision.DirFromAngle(vision.angleVision / 2, false);

        Handles.DrawLine(vision.transform.position, vision.transform.position + viewAngleDirectionA * vision.radiusVision);
        Handles.DrawLine(vision.transform.position, vision.transform.position + viewAngleDirectionB * vision.radiusVision);

        if (GameManager.Instance != null && vision.IsTargetVisible(GameManager.Instance.playerTransform))
        {
            Handles.color = Color.red;
            Handles.DrawLine(vision.transform.position, GameManager.Instance.playerTransform.position);
        }
    }
Пример #19
0
 /// <summary>
 /// Invoked when the user presses the button on the
 /// calibration dialog
 /// </summary>
 public override void OnCalibrationAction()
 {
     VisionSensor.showVideoWindow();
 }
Пример #20
0
 void Awake()
 {
     gameManager     = GameManager.Instance;
     vision          = GetComponentInChildren <VisionSensor>();
     playerTransform = gameManager.playerTransform;
 }
Пример #21
0
 // Use this for initialization
 void Start()
 {
     targetLocation = this.transform.position;
     visionSensor = this.GetComponent<VisionSensor>();
     characterController = this.GetComponent<CharacterController>();
 }
Пример #22
0
 /// <summary>
 /// Starts ACAT vision
 /// </summary>
 private static void startvision()
 {
     VisionSensor.acatVision();
 }