/// <summary>
        /// Initialize service
        /// </summary>
        /// <returns>ITask enumerator</returns>
        private IEnumerator <ITask> Initialize()
        {
            if (this.serviceState == null)
            {
                this.serviceState = new DssLogAnalyzerState();
                this.serviceState.LogFilesFolder = string.Empty;
                this.serviceState.Envelopes      = new List <EnvelopeList>();
            }

            if (this.serviceState.Headless == false)
            {
                this.wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);
                var runWindow = this.wpfServicePort.RunWindow(() => new UserInterface(this));
                yield return((Choice)runWindow);

                var exception = (Exception)runWindow;
                if (exception != null)
                {
                    LogError(exception);
                    StartFailed();
                    yield break;
                }

                this.userInterface = (UserInterface)runWindow;
            }

            this.Load();
        }
Esempio n. 2
0
        private IEnumerator<ITask> DoStart()
        {
            DispatcherQueue queue = new DispatcherQueue();

            this._wpfServicePort = wpf.WpfAdapter.Create(queue);

            // invoke the UI
            var runWindow = this._wpfServicePort.RunWindow(() => (Window)new Dashboard(this));
            yield return (Choice)runWindow;

            var exception = (Exception)runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }    

            // Subscribe to partners  
            var subscribe1 = this._nxtDrivePort.Subscribe(_nxtDriveNotify);
            yield return (Choice)subscribe1;

            _timerPort.Post(DateTime.Now);
            
            // Activate independent tasks
            Activate<ITask>(
                Arbiter.Receive<drive.DriveEncodersUpdate>(true, _nxtDriveNotify, DriveEncoderHandler),
                Arbiter.Receive(true, _timerPort, TimerHandler)
            );

            // Start operation handlers and insert into directory service.
            StartHandlers();          
        }
Esempio n. 3
0
        private IEnumerator<ITask> Initialize()
        {
            // create WPF adapter
            _wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);
            var runWindow = _wpfServicePort.RunWindow(() => new MainWindow {ViewModel = new MainViewModel(this)});
            yield return (Choice) runWindow;
            var exception = (Exception) runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }
            _mainWindow = (Window) runWindow as MainWindow;

            // subscribe to Articulated Arm notifications
            var subscribe = _armPort.Subscribe(_armNotify);
            yield return (Choice)subscribe;
            var fault = (Fault)subscribe;
            if (fault != null)
            {
                LogError(fault);
                StartFailed();
                yield break;
            }

            // register
            base.Start();

            //TODO:
            MainPortInterleave.CombineWith(
                new Interleave());

            SpawnIterator(StartCompleted);
        }
Esempio n. 4
0
        private IEnumerator <ITask> InitializeGui()
        {
            // create WPF adapter
            this._wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);

            var runWindow = this._wpfServicePort.RunWindow(() => new libguiwpf.MainWindow());

            yield return((Choice)runWindow);

            var exception = (Exception)runWindow;

            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            var userInterface = ((Window)runWindow) as libguiwpf.MainWindow;

            if (userInterface == null)
            {
                var e = new ApplicationException("User interface was expected to be libguiwpf.MainWindow");
                LogError(e);
                throw e;
            }
            _mainWindow          = userInterface;
            _mainWindow.Closing += new CancelEventHandler(_mainWindow_Closing);

            // for convenience mark the initial robot position:
            DetectedObstacle dobst1 = new DetectedObstacle()
            {
                geoPosition       = (GeoPosition)_mapperVicinity.robotPosition.Clone(),
                firstSeen         = DateTime.Now.Ticks,
                lastSeen          = DateTime.Now.Ticks,
                color             = Colors.Green,
                detectorType      = DetectorType.NONE,
                objectType        = DetectedObjectType.Mark,
                timeToLiveSeconds = 3600
            };

            lock (_mapperVicinity)
            {
                _mapperVicinity.Add(dobst1);
            }

            _mainWindow.setMapper(_mapperVicinity, _routePlanner);
        }
Esempio n. 5
0
        /// <summary>
        /// Initialize Kinect UI serice
        /// </summary>
        /// <returns>CCR Iterator</returns>
        private IEnumerator <ITask> Initialize()
        {
            this.frameProcessor = new FramePreProcessor(this.kinectPort);

            // create WPF adapter
            this.wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);

            var runWindow = this.wpfServicePort.RunWindow(() => new KinectUI(this));

            yield return((Choice)runWindow);

            var exception = (Exception)runWindow;

            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            this.userInterface = (Window)runWindow as KinectUI;

            yield return(this.kinectPort.Get().Choice(
                             kinectState =>
            {
                this.UpdateState(kinectState);
            },
                             failure =>
            {
                LogError(failure);
            }));

            yield return(this.kinectPort.GetDepthProperties().Choice(
                             GetDepthProperties =>
            {
                KinectUI.MaxValidDepth = GetDepthProperties.MaxDepthValue;
            },
                             failure =>
            {
                LogError(failure);
            }));

            base.Start();

            SpawnIterator(this.ReadKinectLoop);
        }
Esempio n. 6
0
        private IEnumerator<ITask> Initialize()
        {
            // create WPF adapter
            _wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);
            var runWindow = _wpfServicePort.RunWindow(() => new PololuMaestroUI{ ViewModel =  new MainViewModel(this)});
            yield return (Choice) runWindow;
            var exception = (Exception) runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }
            _userInterface = (Window) runWindow as PololuMaestroUI;

            // subscribe to Pololu Maestro
            var subscribe = _pololuMaestroServicePort.Subscribe(_pololuMaestroServiceNotify);
            yield return (Choice)subscribe;
            var fault = (Fault)subscribe;
            if (fault != null)
            {
                LogError(fault);
                StartFailed();
                yield break;
            }

            // register
            base.Start();

            // activate a handler for viseme notifications
            MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive<pololumaestro.Replace>(true, _pololuMaestroServiceNotify, ReplaceNotifyHandler),
                        Arbiter.Receive<pololumaestro.ChannelChange>(true, _pololuMaestroServiceNotify, ServoChangeNotifyHandler)
                        ),
                    new ConcurrentReceiverGroup()
                    )
                );

            SpawnIterator(StartCompleted);
        }
        private IEnumerator<ITask> Initialize()
        {
            // create WPF adapter
            _wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);

            var runWindow = _wpfServicePort.RunWindow(() => new ControlWindow(new MainWindowViewModel(this)));
            yield return (Choice)runWindow;

            var exception = (Exception)runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            _userInterface = (Window)runWindow as ControlWindow;
        }
        /// <summary>
        /// ITask enumerator interface for processing loaded log files
        /// </summary>
        /// <param name="logFilesLoaded">Which log files have been loaded</param>
        /// <returns>
        /// ITask enumerator
        /// </returns>
        public IEnumerator <ITask> LogFilesLoaded(loganalyzer.LogFilesLoaded logFilesLoaded)
        {
            if (this.wpfServicePort == null)
            {
                this.wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);
                var runWindow = this.wpfServicePort.RunWindow(() => new RawViewerPluginUi(this));
                yield return((Choice)runWindow);

                var exception = (Exception)runWindow;
                if (exception != null)
                {
                    LogError(exception);
                    StartFailed();
                    yield break;
                }

                this.userInterface = (RawViewerPluginUi)runWindow;
            }

            var get = new loganalyzer.Get();

            this.logAnalyzer.Post(get);

            loganalyzer.DssLogAnalyzerState logAnalyzerState = null;

            yield return(get.ResponsePort.Choice(
                             state => logAnalyzerState = state,
                             fault => LogError(fault)));

            if (logAnalyzerState == null)
            {
                yield break;
            }

            var listOfEnvelopes = logAnalyzerState.Envelopes;

            yield return(new IterativeTask(() => this.UpdateUiFromListsOfEnvelopes(listOfEnvelopes)));

            yield break;
        }
Esempio n. 9
0
        IEnumerator <ITask> Initialize()
        {
            #region Subscribe to TTS
            // subscribe to TTS service to receive viseme notifications
            var subscribe = _ttsPort.Subscribe(_ttsNotifications, typeof(texttospeech.VisemeNotify));

            yield return((Choice)subscribe);

            var fault = (Fault)subscribe;
            if (fault != null)
            {
                LogError(fault);
                StartFailed();
                yield break;
            }
            #endregion

            #region Create UI
            // create WPF adapter
            _wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);

            var runWindow = _wpfServicePort.RunWindow(() => new TextToSpeechUI(this));
            yield return((Choice)runWindow);

            var exception = (Exception)runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            _userInterface = (Window)runWindow as TextToSpeechUI;
            #endregion

            StartComplete();
        }
        private IEnumerator<ITask> InitializeGui()
        {
            // create WPF adapter
            this._wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);

            var runWindow = this._wpfServicePort.RunWindow(() => new libguiwpf.MainWindow());

            yield return (Choice)runWindow;

            var exception = (Exception)runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            var userInterface = ((Window)runWindow) as libguiwpf.MainWindow;
            if (userInterface == null)
            {
                var e = new ApplicationException("User interface was expected to be libguiwpf.MainWindow");
                LogError(e);
                throw e;
            }
            _mainWindow = userInterface;
            _mainWindow.Closing += new CancelEventHandler(_mainWindow_Closing);

            // for convenience mark the initial robot position:
            DetectedObstacle dobst1 = new DetectedObstacle()
            {
                geoPosition = (GeoPosition)_mapperVicinity.robotPosition.Clone(),
                firstSeen = DateTime.Now.Ticks,
                lastSeen = DateTime.Now.Ticks,
                color = Colors.Green,
                detectorType = DetectorType.NONE,
                objectType = DetectedObjectType.Mark,
                timeToLiveSeconds = 3600
            };

            lock (_mapperVicinity)
            {
                _mapperVicinity.Add(dobst1);
            }

            _mainWindow.setMapper(_mapperVicinity, _routePlanner);
        }
        protected override void Start()
        {
            LogInfo("DriveBehaviorServiceBase:Start()  _doUnitTest=" + _doUnitTest + "   _doSimulatedLaser=" + _doSimulatedLaser + "   _testBumpMode=" + _testBumpMode);

            base.Start();   // start MainPortInterleave; wireup [ServiceHandler] methods

            InitGunTurrets();

            // HeadlightsOff(); -- this will be done by SafePositions in PololuMaestroService

            if (_state == null)
            {
                // no partner-supplied initial state found - create default one:

                LogInfo("DriveBehaviorServiceBase:: initial _state null");

                _state = new TrackRoamerBehaviorsState();

                SaveState(_state);
            }
            else
            {
                LogInfo("DriveBehaviorServiceBase:: initial _state supplied by partner");

                _state.Init();  // clear and re-create some members that should not be taken from the saved state
            }

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            if (_doUnitTest)
            {
                Talker.Say(9, "unit test mode");
            }

            if (_testBumpMode)
            {
                Talker.Say(9, "bumper test mode");
            }

            if (_doSimulatedLaser)
            {
                Talker.Say(9, "laser will be simulated");

                WatchdogInterval = _simulatedLaserWatchdogInterval;    // about the time ultrasonic sensor makes a sweep
            }

            if (!_doUnitTest || _unitTestSensorsOn)
            {
                // Handlers that need write or exclusive access to state go under
                // the exclusive group. Handlers that need read or shared access, and can be
                // concurrent to other readers, go to the concurrent group.
                // Other internal ports can be included in interleave so you can coordinate
                // intermediate computation with top level handlers.

                #region request handler setup
                MainPortInterleave.CombineWith(new Interleave(
                        new TeardownReceiverGroup(),
                        new ExclusiveReceiverGroup(
                            Arbiter.Receive<LaserRangeFinderResetUpdate>(true, _mainPort, LaserRangeFinderResetUpdateHandler),
                            Arbiter.Receive<LaserRangeFinderUpdate>(true, _mainPort, LaserRangeFinderUpdateHandler),
                            Arbiter.Receive<BumpersArrayUpdate>(true, _mainPort, BumpersArrayUpdateHandler),
                            Arbiter.Receive<BumperUpdate>(true, _mainPort, BumperUpdateHandler),
                            Arbiter.Receive<DriveUpdate>(true, _mainPort, DriveUpdateHandler),
                            //Arbiter.Receive<EncoderUpdate>(true, _mainPort, EncoderUpdateHandler),
                            Arbiter.Receive<WatchDogUpdate>(true, _mainPort, WatchDogUpdateHandler)
                        ),
                        new ConcurrentReceiverGroup(
                            Arbiter.Receive<Get>(true, _mainPort, GetHandler),
                            //Arbiter.Receive<HttpGet>(true, _mainPort, HttpGetHandler),
                            Arbiter.Receive<dssp.DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler)
                        )
                    )
                );
                #endregion

                #region notification handler setup
                MainPortInterleave.CombineWith(new Interleave(
                        new TeardownReceiverGroup(),
                        new ExclusiveReceiverGroup(),
                        new ConcurrentReceiverGroup(
                            Arbiter.Receive<sicklrf.Reset>(true, _laserNotify, LaserResetNotification),

                            Arbiter.Receive<proxibrick.UpdateAccelerometerData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateAccelerometerNotification),
                            Arbiter.Receive<proxibrick.UpdateDirectionData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateDirectionNotification),
                            Arbiter.Receive<proxibrick.UpdateProximityData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateProximityNotification),
                            Arbiter.Receive<proxibrick.UpdateParkingSensorData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateParkingSensorNotification),
                            Arbiter.Receive<proxibrick.UpdateAnalogData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateAnalogNotification),

                            Arbiter.Receive<drive.Update>(true, _driveNotify, DriveUpdateNotification),
                            Arbiter.ReceiveWithIterator<drive.DriveDistance>(true, _driveNotify, DriveDistanceUpdateHandler),
                            Arbiter.ReceiveWithIterator<drive.RotateDegrees>(true, _driveNotify, RotateDegreesUpdateHandler),

                            //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyLeft, EncoderUpdateTickCountNotificationLeft),
                            //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyRight, EncoderUpdateTickCountNotificationRight),

                            Arbiter.Receive<powerbrick.UpdateMotorEncoder>(true, notificationPortEncoder, EncoderNotificationHandler),
                            Arbiter.Receive<powerbrick.UpdateMotorEncoderSpeed>(true, notificationPortEncoderSpeed, EncoderSpeedNotificationHandler),
                            Arbiter.Receive<bumper.Replace>(true, _bumperNotify, BumperReplaceNotification),
                            Arbiter.Receive<bumper.Update>(true, _bumperNotify, BumperUpdateNotification)
                        )
                    )
                );
                #endregion

                // We cannot replicate the activation of laser notifications because the
                // handler uses Test() to skip old laser notifications.
                // Activate the handler once, it will re-activate itself:
                Activate(
                    Arbiter.ReceiveWithIterator<sicklrf.Replace>(false, _laserNotify, LaserReplaceNotificationHandler)
                );

                if (USE_ORIENTATION_UM6 || USE_DIRECTION_UM6_QUATERNION || USE_DIRECTION_UM6_EULER)
                {
                    // Start listening to CH Robotics UM6 Orientation Sensor:
                    SubscribeToChrUm6OrientationSensor();
                }

                // Start listening to GPS:
                SubscribeToGps();

                // Start watchdog timer - we need it to detect that the laser does not return current picture and stop:
                _mainPort.Post(new WatchDogUpdate(new WatchDogUpdateRequest(DateTime.Now)));
            }
            else
            {
                // for unit tests - drive only operation:
                #region request handler setup
                MainPortInterleave.CombineWith(new Interleave(
                        new TeardownReceiverGroup(),
                        new ExclusiveReceiverGroup(
                            Arbiter.Receive<BumpersArrayUpdate>(true, _mainPort, BumpersArrayUpdateHandler),
                            Arbiter.Receive<BumperUpdate>(true, _mainPort, BumperUpdateHandler),
                            //Arbiter.Receive<EncoderUpdate>(true, _mainPort, EncoderUpdateHandler),
                            Arbiter.Receive<DriveUpdate>(true, _mainPort, DriveUpdateHandler)
                        ),
                        new ConcurrentReceiverGroup(
                            Arbiter.Receive<Get>(true, _mainPort, GetHandler),
                            //Arbiter.Receive<HttpGet>(true, _mainPort, HttpGetHandler),
                            Arbiter.Receive<dssp.DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler)
                        )
                    )
                );
                #endregion

                #region notification handler setup
                MainPortInterleave.CombineWith(new Interleave(
                        new TeardownReceiverGroup(),
                        new ExclusiveReceiverGroup(),
                        new ConcurrentReceiverGroup(
                            Arbiter.Receive<drive.Update>(true, _driveNotify, DriveUpdateNotification),
                            Arbiter.ReceiveWithIterator<drive.DriveDistance>(true, _driveNotify, DriveDistanceUpdateHandler),
                            Arbiter.ReceiveWithIterator<drive.RotateDegrees>(true, _driveNotify, RotateDegreesUpdateHandler),

                            //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyLeft, EncoderUpdateTickCountNotificationLeft),
                            //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyRight, EncoderUpdateTickCountNotificationRight),

                            Arbiter.Receive<powerbrick.UpdateMotorEncoder>(true, notificationPortEncoder, EncoderNotificationHandler),
                            Arbiter.Receive<powerbrick.UpdateMotorEncoderSpeed>(true, notificationPortEncoderSpeed, EncoderSpeedNotificationHandler),
                            Arbiter.Receive<bumper.Replace>(true, _bumperNotify, BumperReplaceNotification),
                            Arbiter.Receive<bumper.Update>(true, _bumperNotify, BumperUpdateNotification)
                        )
                    )
                );
                #endregion
            }

            // Subscribe to the direct drive for notification messages:
            _drivePort.Subscribe(_driveNotify);

            //_encoderPortLeft.Subscribe(_encoderNotifyLeft);
            //_encoderPortRight.Subscribe(_encoderNotifyRight);

            SubscribeToPowerBrick();    // for Encoders distance and speed

            _bumperPort.Subscribe(_bumperNotify);

            SpawnIterator(this.AhrsZeroGyrosAndAccelerometer);

            SpawnIterator(this.InitializeSpeechRecognizer);

            // create WPF adapter
            this.wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue);

            SpawnIterator(InitializeGui);

            if (!_doUnitTest || _unitTestSensorsOn)
            {
                Tracer.Trace("DriveBehaviorServiceBase:Start():  calling Subscribe() for laser range, proximity, accelerometer, compass partners");

                _laserPort.Subscribe(_laserNotify);

                Type[] notifyMeOf = new Type[] {
                    typeof(proxibrick.UpdateAccelerometerData),
                    typeof(proxibrick.UpdateDirectionData),
                    typeof(proxibrick.UpdateProximityData),
                    typeof(proxibrick.UpdateParkingSensorData),
                    typeof(proxibrick.UpdateAnalogData)
                };

                _trackRoamerBrickProximityBoardServicePort.Subscribe(_trackRoamerBrickProximityBoardServiceNotify, notifyMeOf);

                SpawnIterator(this.InitializeKinectUI);
            }

            SafePosture();

            SetLightsTest();    // SetLightsNormal() is called at the end of CalibrateKinectPlatform iteration

            SpawnIterator(this.LightsControlLoop);

            SpawnIterator(this.ConnectObstacleAvoidanceDrive);

            SpawnIterator(this.CalibrateKinectPlatform);

            SpawnIterator(this.TestAnimatedHead);

            if (_doUnitTest)
            {
                performUnitTest();
            }
            else
            {
                SpawnIterator(this.InitializeDecisionMainLoop);
            }

            // we will need this later:
            robotCornerDistanceMeters = Math.Sqrt(_mapperVicinity.robotState.robotLengthMeters * _mapperVicinity.robotState.robotLengthMeters + _mapperVicinity.robotState.robotWidthMeters * _mapperVicinity.robotState.robotWidthMeters) / 2.0d;
        }