Пример #1
0
        /// <summary>
        /// PursuitCamera Start is called when service initializes
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new PursuitCameraState
                {
                    MinDistance        = 4,
                    MaxDistance        = 6,
                    FieldOfView        = 45,
                    Altitude           = 2,
                    OcclusionThreshold = 0.5f,
                    PreventOcclusion   = true,
                    CameraName         = "PursuitCamera"
                };
            }

            base.Start();

            _physics = physics.PhysicsEngine.GlobalInstance;
            _simPort = sime.SimulationEngine.GlobalInstancePort;

            _simPort.Subscribe(ServiceInfo.PartnerList, _simNotify);

            base.MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.ReceiveWithIterator <sime.InsertSimulationEntity>(true, _simNotify, OnInsertEntity),
                        Arbiter.Receive <sime.DeleteSimulationEntity>(true, _simNotify, OnDeleteEntity)
                        ),
                    new ConcurrentReceiverGroup()
                    )
                );
        }
        /// <summary>
        /// Start initializes SimulatedLRFService and listens for drop messages
        /// </summary>
        protected override void Start()
        {
            _physicsEngine      = physics.PhysicsEngine.GlobalInstance;
            _notificationTarget = new simengine.SimulationEnginePort();

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


            // dont 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 <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler)
                         ),
                         new ExclusiveReceiverGroup(),
                         new ConcurrentReceiverGroup()
                         ));
        }
Пример #3
0
        /// <summary>
        /// Start initializes SimulatedDepthcamService and listens for drop messages
        /// </summary>
        protected override void Start()
        {
            const double KinectMaxValidDepthMm = 4000.0;
            const double KinectMinValidDepthMm = 800.0;

            if (this._state == null)
            {
                // no config file found, initialize default state according to KinectReservedSampleValues
                this._state = new DepthCamSensorState();
                this._state.MaximumRange             = KinectMaxValidDepthMm / 1000.0;
                this._state.MinimumRange             = KinectMinValidDepthMm / 1000.0;
                this._state.FurtherThanMaxDepthValue = (short)4095.0;
                this._state.NearerThanMinDepthValue  = (short)0.0;

                this.SaveState(this._state);
            }

            this._physicsEngine = physics.PhysicsEngine.GlobalInstance;
            _notificationTarget = new simengine.SimulationEnginePort();

            utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

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


            // dont 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 <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler)
                         ),
                         new ExclusiveReceiverGroup(),
                         new ConcurrentReceiverGroup()
                         ));
        }
Пример #4
0
        /// <summary>
        /// Initialize the IR Distance sensor
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public override void Initialize(xnagrfx.GraphicsDevice device, simcommon.PhysicsEngine physicsEngine)
        {
            try
            {
                if (Parent == null)
                {
                    throw new Exception("This entity must be a child of another entity.");
                }

                // make sure that we take at least 2 samples in each direction
                if (Samples < 2f)
                {
                    Samples = 2f;
                }

                _raycastProperties                = new simcommon.RaycastProperties();
                _raycastProperties.StartAngle     = -DispersionConeAngle / 2.0f;
                _raycastProperties.EndAngle       = DispersionConeAngle / 2.0f;
                _raycastProperties.AngleIncrement = DispersionConeAngle / (Samples - 1f);
                _raycastProperties.Range          = MaximumRange;
                _raycastProperties.OriginPose     = new Pose();

                // set flag so rendering engine renders us last
                Flags |= simengine.VisualEntityProperties.UsesAlphaBlending;

                base.Initialize(device, physicsEngine);

                // set up for rendering impact points
                simcommon.HeightFieldShapeProperties hf = new simcommon.HeightFieldShapeProperties("height field", 2, 0.02f, 2, 0.02f, 0, 0, 1, 1);
                hf.HeightSamples = new simcommon.HeightFieldSample[hf.RowCount * hf.ColumnCount];
                for (int i = 0; i < hf.HeightSamples.Length; i++)
                {
                    hf.HeightSamples[i] = new simcommon.HeightFieldSample();
                }

                _particlePlane            = new simcommon.Shape(hf);
                _particlePlane.State.Name = "laser impact plane";

                // The mesh is used to render the ray impact points rather than the sensor geometry.
                int index = Meshes.Count;
                Meshes.Add(simengine.SimulationEngine.ResourceCache.CreateMesh(device, _particlePlane.State));
                Meshes[0].Textures[0] = simengine.SimulationEngine.ResourceCache.CreateTextureFromFile(device, "particle.bmp");

                // we have a custom effect, with an additional global parameter. Get handle to it here
                if (Effect != null)
                {
                    _timeAttenuationHandle = Effect.GetParameter("timeAttenuation");
                }
            }
            catch (Exception ex)
            {
                // clean up
                if (PhysicsEntity != null)
                {
                    PhysicsEngine.DeleteEntity(PhysicsEntity);
                }

                HasBeenInitialized = false;
                InitError          = ex.ToString();
            }
        }