protected override void Start() { _physicsEngine = PhysicsEngine.GlobalInstance; _notificationTarget = new SimulationEnginePort(); // PartnerType.Service is the entity instance name. SimulationEngine.GlobalInstancePort.Subscribe(ServiceInfo.PartnerList, _notificationTarget); LogInfo("Starting Simulated Sonar"); // Raul - If state cannot be read from file create a default one if (_state == null) { _state = CreateDefaultState(); } else // Use the state saved in the file, but don't forget to allocate memory for arrays. { _state.DistanceMeasurements = new double[SonarArrayLength]; formerDistanceMeasurements = new double[SonarArrayLength]; } // dont start listening to DSSP operations, other than drop, until notification of entity Activate(new Interleave( new TeardownReceiverGroup ( Arbiter.Receive <InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime), Arbiter.Receive <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler) ), new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup() )); // Publish the service to the local Node Directory // DirectoryInsert(); }
protected override void Start() { _simEngine = SimulationEngine.GlobalInstancePort; _notificationTarget = new SimulationEnginePort(); // request a notification when the arm is inserted into the sim engine var esrt = new EntitySubscribeRequestType {Name = RobotArmEntityName}; _simEngine.Subscribe(esrt, _notificationTarget); base.Start(); // Add the winform message handler to the interleave MainPortInterleave.CombineWith( new Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup ( Arbiter.Receive<InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime), Arbiter.ReceiveWithIterator<FromWinformMsg>(true, _fromWinformPort, OnWinformMessageHandler) ), new ConcurrentReceiverGroup() )); // Set the initial viewpoint SetupCamera(); // Set up the world PopulateWorld(); }
private bool checkSimulator() { if (_notifyTarget == null && SimulationEngine.GlobalInstancePort != null) { _notifyTarget = new SimulationEnginePort(); addCameraWatch("MainCamera", true); addCameraWatch("ScribblerCamera", false); return(true); } else { return(false); } }
/// <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> /// Service Start /// </summary> protected override void Start() { // Listen on the main port for requests and call the appropriate handler. ActivateDsspOperationHandlers(); // Publish the service to the local service Directory DirectoryInsert(); // display HTTP service Uri LogInfo(LogGroups.Console, "Service uri: "); // Cache reference to simulation/rendering _simEnginePort = SimulationEngine.GlobalInstancePort; // Add objects (entities) in our simulated world PopulateWorld(); }
protected override void Start() { _physicsEngine = PhysicsEngine.GlobalInstance; _notificationTarget = new SimulationEnginePort(); // PartnerType.Service is the entity instance name. SimulationEngine.GlobalInstancePort.Subscribe(ServiceInfo.PartnerList, _notificationTarget); LogInfo("Starting Simulated Sonar"); // Raul - If state cannot be read from file create a default one if (_state == null) { _state = CreateDefaultState(); } else // Use the state saved in the file, but don't forget to allocate memory for arrays. { _state.DistanceMeasurements = new double[SonarArrayLength]; formerDistanceMeasurements = new double[SonarArrayLength]; } // dont start listening to DSSP operations, other than drop, until notification of entity Activate(new Interleave( new TeardownReceiverGroup ( Arbiter.Receive<InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime), Arbiter.Receive<dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler) ), new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup() )); // Publish the service to the local Node Directory // DirectoryInsert(); }
//-- TT #endregion /// <summary> /// Service Start /// </summary> protected override void Start() { int i; // The state might already have been created using // the Initial State Partner above. If so, then we // don't want to create a new one! if (_state == null) { _state = new MazeSimulatorState(); // Do any other initialization here for the default // settings that you might want ... // Raul - Aug 2007 - Indicate what sensors are being used // Using LRF instead of Sonar doesn't work with control panel // until I fix the limit of 19 ports in Control Panel Operations portset _state.UseLRF = false; _state.UseSonar = true; // Raul - Aug 2007 - Initial position of the robot // This is valid for the maze I am using now // Note that position could be inside a wall in // your maze! _state.RobotStartCellCol = 30; _state.RobotStartCellRow = 30; } // TT Feb-2007 - Shock! Horror! Setting the maze in the config // file did not work because it was initialized in the constructor // for the State! // The maze here is one with lots of different objects including some balls // Note the path - It is relative to where dsshost is started from // Other samples are: // ModelSmall.gif -- A smaller model than the one above // office.bmp -- A black and white image of an "office" maze // Jul-2007: // Changed the location of the files if (_state.Maze == null || _state.Maze == "") _state.Maze = "Apps/UC3M/MazeSimulatorRA/OfficeRaul1.bmp"; // Make sure that there is a floor texture // Plenty of others to try, e.g. concrete.jpg. if (_state.GroundTexture == null || _state.GroundTexture == "") _state.GroundTexture = "cellfloor.jpg"; // _state.GroundTexture = "granito.bmp"; // TT Dec-2006 - This is a fudge to support upgrading from // prior versions where the RobotType did not exist. When // MSRS loades the config file, it does not populate any // of the fields that are missing. Therefore the RobotType // is null and this causes the code to crash later on. if (_state.RobotType == null) _state.RobotType = "Pioneer3DX"; // Now initialize our internal copies of state info // This is a little bit of insurance against a bad // config file ... // Copy as many textures as available up to the max for (i = 0; (i < 16) && (i < _state.WallTextures.Length); i++) { _WallTextures[i] = _state.WallTextures[i]; } // Fill any remaining textures with empty string for ( ; i < 16; i++) _WallTextures[i] = ""; // Copy as many colors as specified // NOTE: The constructor for the State sets all of the // colors to the standard ones, so any that are not // specified will default to them. for (i = 0; (i < 16) && (i < _state.WallColors.Length); i++) { _WallColors[i] = _state.WallColors[i]; } // Fill any remaining colors with the defaults for (; i < 16; i++) _WallColors[i] = MazeSimulatorState.DefaultColors[i]; // Copy as many heights as specified for (i = 0; (i < 16) && (i < _state.HeightMap.Length); i++) { _WallHeights[i] = _state.HeightMap[i]; } // Fill any remaining heights with the defaults for (; i < 16; i++) _WallHeights[i] = 5.0f; // Copy as many weights as specified for (i = 0; (i < 16) && (i < _state.MassMap.Length); i++) { _WallMasses[i] = _state.MassMap[i]; } // Fill any remaining weights with the defaults for (; i < 16; i++) _WallMasses[i] = 0.0f; // Copy as many sphere flags as specified for (i = 0; (i < 16) && (i < _state.UseSphere.Length); i++) { _UseSphere[i] = _state.UseSphere[i]; } // Fill any remaining flags with false for (; i < 16; i++) _UseSphere[i] = false; if (_state.SphereScale <= 0.0f) _state.SphereScale = 1.0f; if (_state.HeightScale <= 0.0f) _state.HeightScale = 1.0f; // Copy back our private versions which might have the // effect of extending the state _state.WallColors = _WallColors; _state.WallTextures = _WallTextures; _state.HeightMap = _WallHeights; _state.MassMap = _WallMasses; _state.UseSphere = _UseSphere; // Now save the State // This creates a new file the first time it is run // Later, it re-reads the existing file, but by then // the file has been populated with the defaults SaveState(_state); // Listen on the main port for requests and call the appropriate handler. ActivateDsspOperationHandlers(); // Publish the service to the local Node Directory DirectoryInsert(); // display HTTP service Uri LogInfo(LogGroups.Console, "Service uri: "); // Cache references to simulation/rendering and physics _physicsEngine = PhysicsEngine.GlobalInstance; _simEnginePort = SimulationEngine.GlobalInstancePort; // TT Dec-2006 - Set up the initial camera view SetupCamera(); // Add objects (entities) in our simulated world PopulateWorld(); }
private bool checkSimulator() { if (_notifyTarget == null && SimulationEngine.GlobalInstancePort != null) { _notifyTarget = new SimulationEnginePort(); addCameraWatch("MainCamera", true); addCameraWatch("ScribblerCamera", false); return true; } else return false; }
/// <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)); }