Beispiel #1
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            //
            // Add service specific initialization here
            //

            base.Start();

            #region Run WinForms and Activate Timers
            _stopWatch.Start();

            var webcamPorts = new[] { _firstWebcamPort, _secondWebcamPort };
            for (int idx = 0; idx < _webcamForms.Length; ++idx)
            {
                int i = idx;
                WinFormsServicePort.Post(new RunForm(() =>
                {
                    _webcamForms[i] = new ImageProcessingResultForm();
                    _webcamForms[i].Show();

                    Activate(Arbiter.Receive(false, _timers[i], dateTime => UpdateWebcam(webcamPorts[i],
                                                                                         _webcamForms[i], _timers[i])));
                    TaskQueue.EnqueueTimer(TimeSpan.FromMilliseconds(60), _timers[i]);

                    return(_webcamForms[i]);
                }));
            }
            #endregion
        }
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            base.Start();

            MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup
                    (
                        Arbiter.Receive <OnLoad>(true, _eventsPort, OnLoadHandler),
                        Arbiter.Receive <OnClosed>(true, _eventsPort, OnClosedHandler)
                    ),
                    new ConcurrentReceiverGroup()
                    )
                );

            WinFormsServicePort.Post(
                new RunForm(
                    delegate()
            {
                return(new VideoStreamViewerForm(_eventsPort));
            }
                    )
                );
            // Add service specific initialization here.
        }
Beispiel #3
0
        IEnumerator <ITask> DoStart()
        {
            try
            {
                _utilities = DsspHttpUtilitiesService.Create(Environment);

                RunForm runForm = new RunForm(CreateForm);

                WinFormsServicePort.Post(runForm);
                yield return(Arbiter.Choice(
                                 runForm.pResult,
                                 EmptyHandler,
                                 EmptyHandler
                                 ));

                FormInvoke invoke = new FormInvoke(
                    delegate
                {
                    _form.Initialize(_state);
                }
                    );

                WinFormsServicePort.Post(invoke);
                yield return(Arbiter.Choice(
                                 invoke.ResultPort,
                                 EmptyHandler,
                                 EmptyHandler
                                 ));
            }
            finally
            {
                FinishStarting();
            }
        }
        IEnumerator <ITask> OnConnectHandler(OnConnect onConnect)
        {
            if (onConnect.DriveControl == _driveControl)
            {
                UriBuilder builder = new UriBuilder(onConnect.Service);
                builder.Scheme = new Uri(ServiceInfo.Service).Scheme;

                ds.DirectoryPort port = ServiceForwarder <ds.DirectoryPort>(builder.Uri);
                ds.Get           get  = new ds.Get();

                port.Post(get);
                ServiceInfoType[] list = null;

                yield return(Arbiter.Choice(get.ResponsePort,
                                            delegate(ds.GetResponseType response)
                {
                    list = response.RecordList;
                },
                                            delegate(Fault fault)
                {
                    list = new ServiceInfoType[0];
                    LogError(fault);
                }
                                            ));

                WinFormsServicePort.FormInvoke(
                    delegate()
                {
                    _driveControl.ReplaceDirectoryList(list);
                }
                    );
            }
        }
Beispiel #5
0
        public IEnumerator <ITask> ClientAnnounceTeamNameHandler(ClientAnnounceTeamName announce)
        {
            if (MyMission.Instance().IsRomteMode == false)
            {// 服务端运行于Local模式时,策略从本地加载,不响应AnnounceTeamName消息
                announce.ResponsePort.Post(new Fault());
                yield break;
            }

            // 执行过ClientAnnounceUri保存了Client服务实例的Uri后才允许AnnounceTeamName
            if (_listClientUris.Contains(announce.Body.Service) == true)
            {// 半场交换队伍名称显示错误修正 LiYoubing 20120520
                int teamId = announce.Body.TeamId;
                if (MyMission.Instance().ParasRef.IsExchangedHalfCourt == true &&
                    MyMission.Instance().ParasRef.TeamCount == 2)
                {
                    teamId = (announce.Body.TeamId + 1) % 2;
                }
                MyMission.Instance().TeamsRef[teamId].Para.Name = announce.Body.TeamName;
            }

            // 重绘服务端界面
            Bitmap bmp = MyMission.Instance().IMissionRef.Draw();

            WinFormsServicePort.FormInvoke(delegate() { _serverControlBoard.DrawMatch(bmp); });

            yield break;
        }
        IEnumerator <ITask> RefreshListIterator()
        {
            var getOrFault = _simEngine.Get();

            yield return(getOrFault.Choice());

            Fault ex = (Fault)getOrFault;

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

            var simState = (sim.SimulationState)getOrFault;

            WinFormsServicePort.FormInvoke(() =>
            {
                foreach (var entity in simState.Entities)
                {
                    if (entity is simengine.GlobalJointEntity)
                    {
                        _simulatedBipedMoverUI.AddEntityName(entity.State.Name, _state.Joints == null || _state.Joints.Count == 0);
                    }
                }
            });
        }
        protected override void Start()
        {
            _simEngine          = simengine.SimulationEngine.GlobalInstancePort;
            _notificationTarget = new simengine.SimulationEnginePort();

            if (_state == null)
            {
                CreateDefaultState();
            }

            // PartnerType.Service is the entity instance name.
            _simEngine.Subscribe(ServiceInfo.PartnerList, _notificationTarget);

            // don't start listening to DSSP operations, other than drop, until notification of entity
            Activate(new Interleave(
                         new TeardownReceiverGroup
                         (
                             Arbiter.Receive <simengine.InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime),
                             Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DefaultDropHandler)
                         ),
                         new ExclusiveReceiverGroup
                         (
                             Arbiter.Receive <FromWinformMsg>(true, _fromWinformPort, OnWinformMessageHandler)
                         ),
                         new ConcurrentReceiverGroup()
                         ));

            // Create the user interface form
            WinFormsServicePort.Post(new Microsoft.Ccr.Adapters.WinForms.RunForm(CreateForm));

            Activate(Arbiter.Receive(false, TimeoutPort(5000), dateTime => SpawnIterator(RefreshListIterator)));
        }
        IEnumerator <ITask> OnConnectArticulatedArmHandler(OnConnectArticulatedArm onConnect)
        {
            arm.ArticulatedArmState armState = null;

            if (onConnect.DriveControl != _driveControl)
            {
                yield break;
            }

            _articulatedArmPort = ServiceForwarder <arm.ArticulatedArmOperations>(onConnect.Service);
            yield return(Arbiter.Choice(
                             _articulatedArmPort.Get(new GetRequestType()),
                             delegate(arm.ArticulatedArmState state) { armState = state; },
                             delegate(Fault f) { LogError(f); }
                             ));

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

            WinFormsServicePort.FormInvoke(delegate()
            {
                _driveControl.ReplaceArticulatedArmJointList(armState);
            });

            yield break;
        }
Beispiel #9
0
        /// <summary>
        /// Initialize the Depth Camera
        /// </summary>
        /// <returns>An iterator</returns>
        private IEnumerator <ITask> ConnectDepthCamHandler()
        {
            Fault fault = null;

            yield return(Arbiter.Choice(
                             this.depthCamSensorPort.Subscribe(this.depthCamSensorNotify),
                             EmptyHandler,
                             f => fault = f));

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to DepthCam", fault);
                yield break;
            }

            var runForm = new RunForm(this.CreateDepthCamForm);

            WinFormsServicePort.Post(runForm);

            yield return(Arbiter.Choice(runForm.pResult, EmptyHandler, e => fault = Fault.FromException(e)));

            if (fault != null)
            {
                LogError(null, "Failed to Create DepthCam window", fault);
                yield break;
            }

            yield break;
        }
Beispiel #10
0
        /// <summary>
        /// Handle the Form Closed event for the Dashboard Form
        /// </summary>
        /// <param name="onClosed">The closed message</param>
        private void OnClosedHandler(OnClosed onClosed)
        {
            if (onClosed.DashboardForm == this.dashboardForm)
            {
                LogInfo("Form Closed");

                this.mainPort.Post(new DsspDefaultDrop(DropRequestType.Instance));
                ControlPanelPort.Post(new DsspDefaultDrop(DropRequestType.Instance));

                if (this.cameraForm != null)
                {
                    var closeWebcam = new FormInvoke(
                        delegate
                    {
                        this.cameraForm.Close();
                        this.cameraForm = null;
                    });

                    WinFormsServicePort.Post(closeWebcam);
                }

                if (this.depthCameraForm != null)
                {
                    var closeDepthcam = new FormInvoke(
                        delegate
                    {
                        this.depthCameraForm.Close();
                        this.depthCameraForm = null;
                    });

                    WinFormsServicePort.Post(closeDepthcam);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            base.Start();
            // Add service specific initialization here.


            WinFormsServicePort.Post(
                new RunForm(
                    delegate()
            {
                return(new DSSOpenCVForm(
                           ServiceForwarder <Dssopencv2Operations>(ServiceInfo.Service)
                           ));
            }
                    )
                );


            //WinFormConstructor wc = new WinFormConstructor(
            //    delegate
            //    {
            //        return new DSSOpenCVForm(_mainPort);
            //    }
            //    );

            //_MovingDetect = (DSSOpenCVForm)wc.Invoke();

            //WinFormsServicePort.FormInvoke(
            //    delegate() { _MovingDetect.Show(); }
            //);
        }
Beispiel #12
0
        /// <summary>
        /// Handle updates to the buttons on the Gamepad
        /// </summary>
        /// <param name="update">The parameter is not used.</param>
        /// <returns>An Iterator</returns>
        private IEnumerator <ITask> JoystickUpdateButtonsHandler(game.UpdateButtons update)
        {
            if (this.dashboardForm != null)
            {
                WinFormsServicePort.FormInvoke(() => this.dashboardForm.UpdateJoystickButtons(update.Body));
            }

            yield break;
        }
Beispiel #13
0
        //20101214
        void TeamIdChangedAnnounceHandler(client.TeamIdChanged announce)
        {
            int tmp = _teamId;

            _teamId = announce.Body.TeamId;

            /*
             * WinFormsServicePort.FormInvoke(delegate()
             * {
             *  _clientControlBoard.DisplayCompetitionState(string.Format("ID Changed from {0} to {1}", tmp + 1, _teamId + 1));
             * });
             */

            //modified 20110218
            if (_teamId >= 0)
            {
                WinFormsServicePort.FormInvoke(delegate()
                {
                    _clientControlBoard.DisplayCompetitionState(string.Format("ID Changed from {0} to {1}", tmp + 1, _teamId + 1));
                });
            }
            else
            {
                WinFormsServicePort.FormInvoke(delegate()
                {
                    _clientControlBoard.DisplayCompetitionState(string.Format("Connection rejected. Only {0} teams are allowed.", _teamCount));
                });

                return;
            }

            if (_teamCount == 2)
            {// 当前使命为对抗性比赛时才设置左右半场
                if (_teamId == 0)
                {
                    WinFormsServicePort.FormInvoke(delegate() { _clientControlBoard.SetRadioTeamState(true, false); });
                }
                else if (_teamId == 1)
                {
                    WinFormsServicePort.FormInvoke(delegate() { _clientControlBoard.SetRadioTeamState(false, true); });
                }
            }
            WinFormsServicePort.FormInvoke(delegate()
            {
                _clientControlBoard.SetTeamId(_teamId);
            });

            SpawnIterator <string>(_teamName, AnnounceTeamNameToServer);

            //如果该队已经向Server服务实例发送过准备好的信息了,则需要带着新的编号再发送一遍供Server判断。
            //如果没有发送过,则不需要处理。
            if (_isReady == true)
            {
                SpawnIterator(AnnounceReadyToServer);
            }
        }
Beispiel #14
0
        public virtual IEnumerator <ITask> ReplaceHandler(ButtonPress replace)
        {
            WinFormsServicePort.FormInvoke(
                delegate
            {
                _form.AddMsg(replace.Body.msg);
            }
                );

            yield break;
        }
        protected override void Start()
        {
            base.Start();

            WinFormsServicePort.Post(new RunForm(StartForm));

            #region CODECLIP 01-5
            _drivePort.Subscribe(_driveNotify);
            Activate(Arbiter.Receive <drive.Update>(true, _driveNotify, NotifyDriveUpdate));
            #endregion
        }
Beispiel #16
0
        protected override void Start()
        {
            base.Start();

            WinFormsServicePort.Post(new RunForm(StartForm));

            // Start listening for colors
            //SubscribeToColorSensor();

            _drivePort.Subscribe(_driveNotify);
            Activate(Arbiter.Receive <drive.Update>(true, _driveNotify, NotifyDriveUpdate));
        }
Beispiel #17
0
        /// <summary>
        /// Perform the initial setup
        /// </summary>
        /// <returns>An iterator</returns>
        private IEnumerator <ITask> Setup()
        {
            SpawnIterator(this.ConnectDriveHandler);
            SpawnIterator(this.ConnectPanTiltHandler);
            SpawnIterator(this.ConnectWebCamHandler);
            SpawnIterator(this.ConnectDepthCamHandler);

            WinFormsServicePort.Post(new RunForm(this.CreateForm));

            SpawnIterator(this.ProcessSensors);

            yield break;
        }
 IEnumerator <ITask> JoystickUpdateButtonsHandler(game.UpdateButtons update)
 {
     if (_driveControl != null)
     {
         WinFormsServicePort.FormInvoke(
             delegate()
         {
             _driveControl.UpdateJoystickButtons(update.Body);
         }
             );
     }
     yield break;
 }
 void DeleteEntityInternal()
 {
     _entity = null;
     // add a slider for each joint to the UI
     WinFormsServicePort.FormInvoke(
         delegate()
     {
         _simulatedBipedMoverUI.ClearNames();
         _simulatedBipedMoverUI.ClearSliders();
         Activate(Arbiter.Receive(false, TimeoutPort(5000), dateTime => SpawnIterator(RefreshListIterator)));
     }
         );
 }
Beispiel #20
0
        /// <summary>
        /// Start the PID controller tuning window
        /// </summary>
        private void SetupWindowPIDTuning()
        {
            // TODO Arbiter.Interleave?
            // Start handlers handling the different window events allowing the communication between simulator and window
            Activate <ITask>(
                Arbiter.ReceiveWithIterator <OnLoad>(true, _windowPIDTuningEventsPort, OnWindowPIDTuningLoadHandler),
                Arbiter.Receive <OnClosed>(true, _windowPIDTuningEventsPort, OnWindowPIDTuningClosedHandler),
                Arbiter.Receive <WindowPIDTuning.OnPIDValueChanged>(true, _windowPIDTuningEventsPort, OnWindowPIDTuningPIDValueChangedHandler)
                );

            // Start the PID controller window
            WinFormsServicePort.Post(new RunForm(CreateWindowPIDTuning));
        }
Beispiel #21
0
        /// <summary>
        /// 改变比赛类型时重新初始化与队伍数量和每队仿真机器鱼数量相关的动态界面元素
        /// </summary>
        public void InitUi()
        {
            WinFormsServicePort.FormInvoke(delegate() {
                // 初始化主界面Referee面板Strategy区动态控件
                _serverControlBoard.InitTeamStrategyControls();

                // 初始化主界面Fish面板Fish Setting区动态控件
                _serverControlBoard.InitFishAndBallSettingControls();

                // 重置ServerControlBoard中随使命运行动态变化的私有变量值和控件状态
                _serverControlBoard.ResetPrivateVarsAndControls();
            });
        }
        /// <summary>
        /// Entry Point for the SimpleDashboard Service
        /// </summary>
        protected override void Start()
        {
            // This service does not use base.Start() because of the way that
            // the handlers are hooked up. Notice the mixture of _mainPort and
            // _eventsPort in the interleave.
            // Also, because the interleave is created explicitly there must be
            // Get and HttpGet handlers instead of using the default ones.
            // 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.
            Activate(Arbiter.Interleave(
                         new TeardownReceiverGroup
                         (
                             Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler)
                         ),
                         new ExclusiveReceiverGroup
                         (
                             Arbiter.ReceiveWithIterator <Replace>(true, _mainPort, ReplaceHandler),
                             Arbiter.ReceiveWithIterator <OnLoad>(true, _eventsPort, OnLoadHandler),
                             Arbiter.Receive <OnClosed>(true, _eventsPort, OnClosedHandler),
                             Arbiter.ReceiveWithIterator <OnChangeJoystick>(true, _eventsPort, OnChangeJoystickHandler),
                             Arbiter.Receive <OnLogSetting>(true, _eventsPort, OnLogSettingHandler)
                         ),
                         new ConcurrentReceiverGroup
                         (
                             Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler),
                             Arbiter.ReceiveWithIterator <Get>(true, _mainPort, GetHandler),

                             Arbiter.ReceiveWithIterator <game.Replace>(true, _gameControllerNotify, JoystickReplaceHandler),
                             Arbiter.ReceiveWithIterator <game.UpdateAxes>(true, _gameControllerNotify, JoystickUpdateAxesHandler),
                             Arbiter.ReceiveWithIterator <game.UpdateButtons>(true, _gameControllerNotify, JoystickUpdateButtonsHandler),
                             Arbiter.ReceiveWithIterator <sicklrf.Replace>(true, _laserNotify, OnLaserReplaceHandler),
                             Arbiter.ReceiveWithIterator <OnConnect>(true, _eventsPort, OnConnectHandler),

                             Arbiter.ReceiveWithIterator <drive.Update>(true, _driveNotify, OnDriveUpdateNotificationHandler),
                             Arbiter.ReceiveWithIterator <OnConnectMotor>(true, _eventsPort, OnConnectMotorHandler),
                             Arbiter.ReceiveWithIterator <OnMove>(true, _eventsPort, OnMoveHandler),
                             Arbiter.ReceiveWithIterator <OnEStop>(true, _eventsPort, OnEStopHandler),

                             Arbiter.ReceiveWithIterator <OnStartService>(true, _eventsPort, OnStartServiceHandler),
                             Arbiter.ReceiveWithIterator <OnConnectSickLRF>(true, _eventsPort, OnConnectSickLRFHandler),
                             Arbiter.Receive <OnDisconnectSickLRF>(true, _eventsPort, OnDisconnectSickLRFHandler)
                         )
                         ));

            DirectoryInsert();

            WinFormsServicePort.Post(new RunForm(CreateForm));
        }
Beispiel #23
0
        public IEnumerator <ITask> OnUpdateButton(UpdateButton update)
        {
            int index = _state.Buttons.FindIndex(update.Body.CompareId);

            if (index < 0)
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "A button with the requested ID does not exist: " + update.Body.Id
                        )
                    );
            }
            else
            {
                bool isInternal = update.GetHeader <InternalUpdate>() != null;

                if (!isInternal)
                {
                    Fault      fault  = null;
                    FormInvoke invoke = new FormInvoke(
                        delegate
                    {
                        _form.UpdateButton(update.Body);
                    }
                        );

                    WinFormsServicePort.Post(invoke);
                    yield return(Arbiter.Choice(
                                     invoke.ResultPort,
                                     EmptyHandler,
                                     delegate(Exception e)
                    {
                        fault = Fault.FromException(e);
                    }
                                     ));

                    if (fault != null)
                    {
                        update.ResponsePort.Post(fault);
                        yield break;
                    }
                }

                _state.Buttons[index] = update.Body;
                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                DoSendNotification(update);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Start the simulation settings window
        /// </summary>
        private void SetupWindowSimulationSettings()
        {
            // TODO Arbiter.Interleave?
            // Start handlers handling the different window events allowing the communication between simulator and window
            Activate <ITask>(
                Arbiter.ReceiveWithIterator <OnLoad>(true, _windowSimulationSettingsEventsPort, OnWindowSimulationSettingsLoadHandler),
                Arbiter.Receive <OnClosed>(true, _windowSimulationSettingsEventsPort, OnWindowSimulationSettingsCloseHandler),
                Arbiter.Receive <WindowSimulationSettings.OnAction>(true, _windowSimulationSettingsEventsPort, OnWindowSimulationActionHandler),
                Arbiter.Receive <WindowSimulationSettings.OnWindSettingsChanged>(true, _windowSimulationSettingsEventsPort, OnWindowSimulationWindSettingsChangedHandler)
                );

            // Start the simulation settings window
            WinFormsServicePort.Post(new RunForm(CreateWindowSimulationSettings));
        }
Beispiel #25
0
        /// <summary>
        /// Called on a rotate single axis.
        /// </summary>
        /// <param name="rotate">The rotation.</param>
        private void OnRotateSingleAxis(pantilt.Rotate rotate)
        {
            var degrees = rotate.Body.RotateTiltRequest.TargetRotationAngleInRadians * 180 / Math.PI;

            this.state.TiltAngle = Math.Round(degrees);

            var angle  = (int)this.state.TiltAngle;
            var update = new FormInvoke(() =>
            {
                this.dashboardForm.TiltTextbox.Text = angle.ToString();
            });

            WinFormsServicePort.Post(update);
        }
        /// <summary>
        /// Entry Point for the SimpleDashboard Service
        /// </summary>
        protected override void Start()
        {
            // 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.
            Activate(Arbiter.Interleave(
                         new TeardownReceiverGroup
                         (
                             Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler)
                         ),
                         new ExclusiveReceiverGroup
                         (
                             Arbiter.ReceiveWithIterator <Replace>(true, _mainPort, ReplaceHandler),
                             Arbiter.ReceiveWithIterator <OnLoad>(true, _eventsPort, OnLoadHandler),
                             Arbiter.Receive <OnClosed>(true, _eventsPort, OnClosedHandler),
                             Arbiter.ReceiveWithIterator <OnChangeJoystick>(true, _eventsPort, OnChangeJoystickHandler),
                             Arbiter.Receive <OnLogSetting>(true, _eventsPort, OnLogSettingHandler)
                         ),
                         new ConcurrentReceiverGroup
                         (
                             Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler),
                             Arbiter.ReceiveWithIterator <Get>(true, _mainPort, GetHandler),

                             Arbiter.ReceiveWithIterator <game.Replace>(true, _gameControllerNotify, JoystickReplaceHandler),
                             Arbiter.ReceiveWithIterator <game.UpdateAxes>(true, _gameControllerNotify, JoystickUpdateAxesHandler),
                             Arbiter.ReceiveWithIterator <game.UpdateButtons>(true, _gameControllerNotify, JoystickUpdateButtonsHandler),
                             Arbiter.ReceiveWithIterator <sicklrf.Replace>(true, _laserNotify, OnLaserReplaceHandler),
                             Arbiter.ReceiveWithIterator <OnConnect>(true, _eventsPort, OnConnectHandler),

                             Arbiter.ReceiveWithIterator <drive.Update>(true, _driveNotify, OnDriveUpdateNotificationHandler),
                             Arbiter.ReceiveWithIterator <OnConnectMotor>(true, _eventsPort, OnConnectMotorHandler),
                             Arbiter.ReceiveWithIterator <OnMove>(true, _eventsPort, OnMoveHandler),
                             Arbiter.ReceiveWithIterator <OnEStop>(true, _eventsPort, OnEStopHandler),

                             Arbiter.ReceiveWithIterator <OnStartService>(true, _eventsPort, OnStartServiceHandler),
                             Arbiter.ReceiveWithIterator <OnConnectSickLRF>(true, _eventsPort, OnConnectSickLRFHandler),
                             Arbiter.Receive <OnDisconnectSickLRF>(true, _eventsPort, OnDisconnectSickLRFHandler),

                             Arbiter.ReceiveWithIterator <OnConnectArticulatedArm>(true, _eventsPort, OnConnectArticulatedArmHandler),
                             Arbiter.ReceiveWithIterator <OnApplyJointParameters>(true, _eventsPort, OnApplyJointParametersHandler)
                         )
                         ));

            DirectoryInsert();

            WinFormsServicePort.Post(new RunForm(CreateForm));
        }
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            base.Start();
            _notificationTarget = new SimulationEnginePort();
            EntitySubscribeRequestType req = new EntitySubscribeRequestType();

            req.Name = "MainCamera";
            SimulationEngine.GlobalInstancePort.Subscribe(req, _notificationTarget);

            // Set the Simulator camera view and resolution
            UpdateCameraView view = new UpdateCameraView(new CameraView());

            view.Body.EyePosition = new Vector3(1, 5, 1);
            view.Body.LookAtPoint = new Vector3(0, 0, 0);
            view.Body.XResolution = 640;
            view.Body.YResolution = 480;
            SimulationEngine.GlobalInstancePort.Post(view);

            // get the current simulator configuration
            _defaultConfig = new SimulatorConfiguration(true);

            Activate(Arbiter.Choice(SimulationEngine.GlobalInstancePort.Query(_defaultConfig),
                                    delegate(SimulatorConfiguration config)
            {
                _defaultConfig = config;
                if (_embeddedSimUI != null)
                {
                    WinFormsServicePort.FormInvoke(delegate() { _embeddedSimUI.SetHeadless(config.Headless); });
                }
            },
                                    delegate(W3C.Soap.Fault fault)
            {
            }
                                    ));

            // Add the winform message handler to the interleave
            Activate(Arbiter.Interleave(
                         new TeardownReceiverGroup(),
                         new ExclusiveReceiverGroup
                         (
                             Arbiter.Receive <InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime),
                             Arbiter.Receive <FromWinformMsg>(true, _fromWinformPort, OnWinformMessageHandler)
                         ),
                         new ConcurrentReceiverGroup()
                         ));

            // Create the user interface form
            WinFormsServicePort.Post(new RunForm(CreateForm));
        }
Beispiel #28
0
        public virtual IEnumerator <ITask> ConfirmHandler(Confirm confirm)
        {
            PortSet <bool, Exception> result = new PortSet <bool, Exception>();
            ConfirmForm form = null;

            RunForm runForm = new RunForm(
                delegate()
            {
                form           = new ConfirmForm(result);
                form.Message   = confirm.Body.Message;
                form.Countdown = _defaultTimeout;

                return(form);
            }
                );

            WinFormsServicePort.Post(runForm);

            yield return(Arbiter.Choice(
                             runForm.pResult,
                             delegate(SuccessResult success) { },
                             delegate(Exception e)
            {
                result.Post(e);
            }
                             ));

            yield return(Arbiter.Choice(
                             result,
                             delegate(bool confirmed)
            {
                ConfirmResponse response = new ConfirmResponse();
                response.Confirmed = confirmed;

                confirm.ResponsePort.Post(response);

                if (form.Timeout)
                {
                    LogWarning("Confirm dialog cancelled due to timeout.");
                }
            },
                             delegate(Exception e)
            {
                Fault fault = Fault.FromException(e);
                LogError(null, "Error in Confirm Handler", fault);
                confirm.ResponsePort.Post(fault);
            }
                             ));
        }
        IEnumerator <ITask> UpdateCompass()
        {
            var sensorOrFault = _simulatedCompassPort.Get();

            yield return(sensorOrFault.Choice());

            if (!HasError(sensorOrFault))
            {
                analogsensor.AnalogSensorState sensorState = (analogsensor.AnalogSensorState)sensorOrFault;
                WinFormsServicePort.Post(new FormInvoke(() =>
                {
                    _imageProcessingForm.SetCompassReadingValue(sensorState.RawMeasurement);
                }));
            }
        }
        IEnumerator <ITask> OnLaserReplaceHandler(sicklrf.Replace replace)
        {
            if (_driveControl != null)
            {
                WinFormsServicePort.FormInvoke(
                    delegate()
                {
                    _driveControl.ReplaceLaserData(replace.Body);
                }
                    );
            }

            LogObject(replace.Body);
            yield break;
        }