예제 #1
0
파일: Window.cs 프로젝트: nimski/SatCamp
        public Window()
        {
            InitializeComponent();
            _um6Driver = new Um6Driver("COM1", 115200);
            _um6Driver.Init();
            _servoDriver = new ServoDriver();
            _updateTimer = new System.Timers.Timer(50);
            _updateTimer.Elapsed += _updateTimer_Elapsed;
            _cameraDriver = new CameraDriver(this.Handle.ToInt64());
            _cameraDriver.Init(pictureBox.Handle.ToInt64());
            _cameraDriver.CameraCapture += _cameraDriver_CameraCapture;

            // initialize the service
            //_host = new ServiceHost(typeof(SatService));
            NetTcpBinding binding = new NetTcpBinding();
            binding.MaxReceivedMessageSize = 20000000;
            binding.MaxBufferPoolSize = 20000000;
            binding.MaxBufferSize = 20000000;
            binding.Security.Mode = SecurityMode.None;
            _service = new SatService(_cameraDriver);
            _host = new ServiceHost(_service);
            _host.AddServiceEndpoint(typeof(ISatService),
                                   binding,
                                   "net.tcp://localhost:8000");
            _host.Open();

            _stabPitchServo = 6000;
            _stabYawServo = 6000;
        }
예제 #2
0
        public SatService(CameraDriver camDriver)
        {
            _camEvent = new AutoResetEvent(false);
            _camDriver = camDriver;
            _camDriver.CameraCapture += _camDriver_CameraCapture;

            _bStabilizationChanged = false;

            _servoPos = new int[10];
            _servoChanged = new bool[10];
            for (int ii = 0; ii < 10; ii++)
            {
                _servoPos[ii] = 6000;
                _servoChanged[ii] = false;
            }
            _eulerAngles = new double[3];
        }
예제 #3
0
        /**
         *
         */
        protected override void work()
        {
            _logger.log("Server main loop has started");

            // set default camera parameters
            _service._frameRate = Constants.DEF_FPS;
            _service._expTime = Constants.DEF_EXP_TIME;
            _cameraDriver.setFps(Constants.DEF_FPS);
            _cameraDriver.setExposureTime(Constants.DEF_EXP_TIME);

            _cameraDriver.StartVideo();

            while (_go && IsAlive())
            {
                // fetch euler angles
                lock (_um6Driver)
                {
                    _service._eulerAngles[0] = _um6Driver.Roll; // roll
                    _service._eulerAngles[1] = _um6Driver.Pitch; // pitch
                    _service._eulerAngles[2] = _um6Driver.Yaw; // yaw
                }

                // Transfer servo modification order to the servos
                // do it with Pitch
                if (_service._servoChanged[Constants.PITCH_SERVO_ADDR])
                {
                    _service._servoChanged[Constants.PITCH_SERVO_ADDR] = false;
                    _servoDriver.SetServo(Constants.PITCH_SERVO_ADDR, (ushort)_service._servoPos[Constants.PITCH_SERVO_ADDR]);
                }

                // do it with Yaw
                if (_service._servoChanged[Constants.YAW_SERVO_ADDR])
                {
                    _service._servoChanged[Constants.YAW_SERVO_ADDR] = false;
                    _servoDriver.SetServo(Constants.YAW_SERVO_ADDR, (ushort)_service._servoPos[Constants.YAW_SERVO_ADDR]);
                }

                // check if camera parameters were changed
                if (_service._expTimeChanged || _service._frameRateChanged)
                {
                    // create a new camera drive with the new parameters
                    lock (this)
                    {
                        _cameraDriver.StopVideo();
                        _cameraDriver.ShutDown();
                        _cameraDriver = null;
                        Thread.Sleep(200); // make sure everything is cleaned (dirty)
                        initCameraDriver();
                        _cameraDriver.setExposureTime(_service._expTime);
                        _cameraDriver.setFps(_service._frameRate);
                        _cameraDriver.StartVideo();
                        _service._frameRateChanged = false;
                        _service._expTimeChanged = false;
                    }
                }

                if (_service._bStabilizationActive)
                    startController();
                else
                {
                    // stop controller thread if it was launched
                    stopController();
                    // place here the code for controlling manually the servo
                }
            }

            _logger.log("Server main loop has ended");
            cleanRessources();
        }
예제 #4
0
 /**
  * Initialize the camera driver
  */
 private void initCameraDriver()
 {
     _cameraDriver = new CameraDriver(_hWind);
     _cameraDriver.Init(_hPbox);
     _cameraDriver.CameraCapture += cameraCaptureHandler;
     _logger.log("Camera driver successfully (re)initialized");
 }