/// <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));
        }
        /// <summary>
        /// Entry Point for the Dashboard Service
        /// </summary>
        protected override void Start()
        {
            // TT - Added code to create a default State if no
            // config file exists
            if (_state == null)
            {
                _state = new StateType();
                _state.Log = false;
                _state.LogFile = "";
                _state.Machine = "";
                _state.Port = 0;
            }

            // TT - Version 2 - The options "bag"
            // This is tacky, but we need to set the default values
            // in case there is no existing config.xml file
            if (_state.Options == null)
            {
                _state.Options = new GUIOptions();
                _state.Options.DeadZoneX = 80;
                _state.Options.DeadZoneY = 80;
                _state.Options.TranslateScaleFactor = 1.0;
                _state.Options.RotateScaleFactor = 0.5;
                _state.Options.ShowLRF = false;
                _state.Options.ShowArm = false;
                _state.Options.DisplayMap = false;

                // Raul - Sept 2007
                _state.Options.DisplaySonarMap = false;

                // Updated in later versions with more options
                // These values are in mm
                _state.Options.RobotWidth = 300;
                _state.Options.MaxLRFRange = 8192;
                _state.Options.DriveDistance = 300;
                // Speed is in mm/sec???
                _state.Options.MotionSpeed = 100;
                // Angle is in degrees
                _state.Options.RotateAngle = 45;
                // Camera update interval in milliseconds
                // Note that this is only required for the
                // simulated webcam because it does not provide
                // updates when you subscribe
                _state.Options.CameraInterval = 250;

                // Raul - Version 9
                _state.Options.SonarRange = 4000;
                _state.Options.SonarTransducerAngularRange = 15.0f;

                // Raul - Sonar transducer positions.
                // This is only valid for a single sonar array of 8 transducers!!
                _state.Options.SonarRadians = new double[8];
                // Orientations of the P3DX frontal sonar transducers
                _state.Options.SonarRadians[0] = (Math.PI * 90) / 180;
                _state.Options.SonarRadians[1] = (Math.PI * 50) / 180;
                _state.Options.SonarRadians[2] = (Math.PI * 30) / 180;
                _state.Options.SonarRadians[3] = (Math.PI * 10) / 180;
                _state.Options.SonarRadians[4] = -(Math.PI * 10) / 180;
                _state.Options.SonarRadians[5] = -(Math.PI * 30) / 180;
                _state.Options.SonarRadians[6] = -(Math.PI * 50) / 180;
                _state.Options.SonarRadians[7] = -(Math.PI * 90) / 180;

            }
            if (_state.Options.CameraInterval < 100)
                _state.Options.CameraInterval = 100;

            // 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.ReceiveWithIteratorFromPortSet<OnLoad>(true, _eventsPort, OnLoadHandler),
                    Arbiter.ReceiveFromPortSet<OnClosed>(true, _eventsPort, OnClosedHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnChangeJoystick>(true, _eventsPort, OnChangeJoystickHandler),
                    Arbiter.ReceiveFromPortSet<OnLogSetting>(true, _eventsPort, OnLogSettingHandler),
                    // TT - Added this handler for Connection parameters
                    Arbiter.ReceiveFromPortSet<OnConnectSetting>(true, _eventsPort, OnConnectSettingHandler),
                    // TT - Added this handler for Options
                    Arbiter.ReceiveFromPortSet<OnOptionSettings>(true, _eventsPort, OnOptionSettingsHandler),

                    
                    Arbiter.ReceiveWithIterator<cam.UpdateFrame>(true, _webCamNotify, CameraUpdateFrameHandler),
                    
                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectPanTilt>(true, _eventsPort, OnConnectPanTiltHandler)
                    

                    // Raul - Sept. Added this handler to disconnect cam - doesn't work yet
                    // Arbiter.ReceiveFromPortSet<OnDisconnectWebCam>(true, _eventsPort, OnDisconnectWebCamHandler),
                    // Raul - Handler for Cera Vision
                    // Arbiter.ReceiveWithIteratorFromPortSet<OnConnectVision>(true, _eventsPort, OnConnectVisionHandler),
                    // Arbiter.ReceiveFromPortSet<OnDisconnectVision>(true, _eventsPort, OnDisconnectVisionHandler)                   
                ),
                new ConcurrentReceiverGroup
                (
                    Arbiter.Receive<DsspDefaultLookup>(true,_mainPort,DefaultLookupHandler),
                    Arbiter.ReceiveWithIterator<Get>(true, _mainPort, GetHandler),
                    
                    // TT Dec-2006 - Updated for V1.0
                    Arbiter.ReceiveWithIterator<game.Replace>(true, _gameControllerNotify, JoystickReplaceHandler),
                    Arbiter.ReceiveWithIterator<sicklrf.Replace>(true, _laserNotify, OnLaserReplaceHandler),
                    

                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnect>(true, _eventsPort, OnConnectHandler),
                    
                    Arbiter.ReceiveWithIterator<drive.Update>(true, _driveNotify, OnDriveUpdateNotificationHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectMotor>(true, _eventsPort, OnConnectMotorHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnMove>(true, _eventsPort, OnMoveHandler),
                    
                    // TT May-2007 - Added Rotate and Translate
                    Arbiter.ReceiveWithIteratorFromPortSet<OnRotate>(true, _eventsPort, OnRotateHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnTranslate>(true, _eventsPort, OnTranslateHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnEStop>(true, _eventsPort, OnEStopHandler),
                    
                    // Raul - LRF
                    Arbiter.ReceiveWithIteratorFromPortSet<OnStartService>(true, _eventsPort, OnStartServiceHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectSickLRF>(true, _eventsPort, OnConnectSickLRFHandler),
                    Arbiter.ReceiveFromPortSet<OnDisconnectSickLRF>(true, _eventsPort, OnDisconnectSickLRFHandler),

                    // Raul - Sonar 
                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectSonar>(true, _eventsPort, OnConnectSonarHandler),
                    Arbiter.ReceiveFromPortSet<OnDisconnectSonar>(true, _eventsPort, OnDisconnectSonarHandler),
                    Arbiter.ReceiveWithIterator<pxsonar.Replace>(true, _sonarNotify, OnSonarReplaceHandler),

                    // Raul - GPS
                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectGPS>(true, _eventsPort, OnConnectGPSHandler),
                    Arbiter.ReceiveFromPortSet<OnDisconnectGPS>(true, _eventsPort, OnDisconnectGPSHandler),
                    Arbiter.ReceiveWithIterator<pxGPS.Replace>(true, _gpsNotify, OnGPSReplaceHandler),

                    // Raul - Bumpers
                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectBumpers>(true, _eventsPort, OnConnectBumpersHandler),
                    Arbiter.ReceiveFromPortSet<OnDisconnectBumpers>(true, _eventsPort, OnDisconnectBumpersHandler),
                    Arbiter.ReceiveWithIterator<pxbumper.Replace>(true, _bumpersNotify, OnBumpersReplaceHandler),
                    Arbiter.ReceiveWithIterator<pxbumper.Update>(true, _bumpersNotify, OnBumperUpdateHandler),

                    Arbiter.ReceiveWithIteratorFromPortSet<OnConnectWebCam>(true, _eventsPort, OnConnectWebCamHandler),
                    Arbiter.ReceiveWithIteratorFromPortSet<OnPTMove>(true, _eventsPort, OnPanTiltMoveHandler)
                )
            ));

            DirectoryInsert();

            _notificationTarget = new SimulationEnginePort();
            EntitySubscribeRequestType req = new EntitySubscribeRequestType();
            req.Name = "PursuitCam";
            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 (_driveControl != null)
                        WinFormsServicePort.FormInvoke(delegate() { _driveControl.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.ReceiveFromPortSet<OnSimulLoaded>(true, _eventsPort, OnSimulLoadedHandler),
                    Arbiter.ReceiveFromPortSet<OnSimulDrag>(true, _eventsPort, OnSimulDragHandler),
                    Arbiter.ReceiveFromPortSet<OnSimulZoom>(true, _eventsPort, OnSimulZoomHandler)
                ),
                new ConcurrentReceiverGroup()
            ));


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