Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the Color Sensor state
        /// </summary>
        private void InitializeState()
        {
            if (_state == null)
            {
                _state = new ColorSensorState();
                // Default to Color mode if no config file
                _state.SensorMode = ColorSensorMode.Color;
            }

            if (_state.PollingFrequencyMs == 0)
            {
                _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs;
            }

            _state.TimeStamp = DateTime.MinValue;
            _state.Reading   = 0;
            _state.Connected = false;


            if (_genericState == null)
            {
                _genericState = new pxanalogsensor.AnalogSensorState();
            }

            // Analog range is 0-1023 (10-bit A/D)
            _genericState.RawMeasurementRange   = 1023.0;
            _genericState.RawMeasurement        = 0.0;
            _genericState.NormalizedMeasurement = 0.0;
            _genericState.TimeStamp             = DateTime.MinValue;

            // Set the hardware identifier from the connected motor port.
            _genericState.HardwareIdentifier = NxtCommon.HardwareIdentifier(_state.SensorPort);
        }
Ejemplo n.º 2
0
        protected override void Start()
        {
            //configure default state
            if (_state == null)
            {
                _state = new analog.AnalogSensorState();
                _state.HardwareIdentifier  = 3;
                _state.RawMeasurementRange = 100;

                SaveState(_state);
            }

            // Listen for each of my handlers
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            // Subscribe to NXT for light sensor notifications
            if (ValidState(_state))
            {
                SubscribeToNXT();
            }
        }
        /// <summary>
        /// Initialize the Light Sensor state
        /// </summary>
        private void InitializeState()
        {
            if (_state == null)
            {
                _state = new LightSensorState();
            }

            if (_state.PollingFrequencyMs == 0)
            {
                _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs;
            }

            _state.TimeStamp = DateTime.MinValue;
            _state.Intensity = 0;
            _state.Connected = false;


            if (_genericState == null)
            {
                _genericState = new pxanalogsensor.AnalogSensorState();
            }

            _genericState.RawMeasurementRange   = 255.0;
            _genericState.RawMeasurement        = 0.0;
            _genericState.NormalizedMeasurement = 0.0;
            _genericState.TimeStamp             = DateTime.MinValue;

            // Set the hardware identifier from the connected motor port.
            _genericState.HardwareIdentifier = NxtCommon.HardwareIdentifier(_state.SensorPort);
        }
Ejemplo n.º 4
0
 public virtual IEnumerator <ITask> AlternateGetHandler(analog.Get get)
 {
     _alternateState = new analog.AnalogSensorState();
     _alternateState.RawMeasurement = _state.SoundReading;
     _alternateState.TimeStamp      = _state.TimeStamp;
     get.ResponsePort.Post(_alternateState);
     yield break;
 }
Ejemplo n.º 5
0
 private static bool ValidState(analog.AnalogSensorState state)
 {
     if (state != null)
     {
         if (state.HardwareIdentifier >= 1 && state.HardwareIdentifier <= 4)
         {
             return(true);
         }
     }
     return(false);
 }
        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);
                }));
            }
        }
        /// <summary>
        /// Configure sensors
        /// </summary>
        /// <returns>A CCR iterator</returns>
        private IEnumerator <ITask> ConfigureSensors()
        {
            int i = 0;

            // Get each sensor's current state
            // And assign hardware identifiers
            var replaceSensorState = new analogsensor.Replace();

            foreach (var sensor in this.sensorPorts)
            {
                var getResultPort = this.sensorPorts[i].Get();
                yield return(getResultPort.Choice());

                analogsensor.AnalogSensorState sensorState = getResultPort;
                if (sensorState != null)
                {
                    replaceSensorState.Body = sensorState;
                }
                else
                {
                    replaceSensorState.Body = new analogsensor.AnalogSensorState();
                }

                replaceSensorState.Body.HardwareIdentifier = i;
                sensor.Post(replaceSensorState);
                i++;
            }

            ICollection <Fault> faults = null;

            yield return(replaceSensorState.ResponsePort.MultipleItemReceive(
                             this.sensorPorts.Length,
                             (successes, f) =>
            {
                faults = f;
            }));

            if (faults != null && faults.Count > 0)
            {
                LogError("Failure configuring IR sensors");
                this.mainPort.Post(new DsspDefaultDrop());
            }

            this.StartAfterConfigure();
        }
Ejemplo n.º 8
0
 public virtual IEnumerator <ITask> AlternateGetHandler(analogarray.Get get)
 {
     _alternateState         = new analogarray.AnalogSensorArrayState();
     _alternateState.Sensors = new List <analog.AnalogSensorState>();
     analog.AnalogSensorState sens = new analog.AnalogSensorState();
     sens.RawMeasurement = _state.Sensors[0].value;
     _alternateState.Sensors.Add(sens);
     sens = new analog.AnalogSensorState();
     sens.RawMeasurement = _state.Sensors[1].value;
     _alternateState.Sensors.Add(sens);
     sens = new analog.AnalogSensorState();
     sens.RawMeasurement = _state.Sensors[2].value;
     _alternateState.Sensors.Add(sens);
     sens = new analog.AnalogSensorState();
     sens.RawMeasurement = _state.Sensors[3].value;
     _alternateState.Sensors.Add(sens);
     get.ResponsePort.Post(_alternateState);
     yield break;
 }
Ejemplo n.º 9
0
        public IEnumerator <ITask> ReplaceHandler(analog.Replace replace)
        {
            if (_subscribed)
            {
                throw new Exception("Already subscribed");
            }
            else if (ValidState(replace.Body))
            {
                _state = replace.Body;
                SaveState(_state);
                replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
                SubscribeToNXT();
            }
            else
            {
                throw new Exception("Invalid State");
            }

            yield break;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initialize State
        /// </summary>
        private void InitializeState()
        {
            if (_state == null)
            {
                _state = new SoundSensorState();
            }

            if (_state.PollingFrequencyMs == 0)
            {
                _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs;
            }

            if (_genericState == null)
            {
                _genericState = new pxanalogsensor.AnalogSensorState();
            }

            _state.TimeStamp = DateTime.MinValue;
            _state.Connected = false;
            _state.Intensity = 0;

            _genericState.RawMeasurementRange = 255.0;
        }
 public virtual IEnumerator <ITask> ReplaceHandler(pxanalogsensor.Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }
        /// <summary>
        /// Initialize State
        /// </summary>
        private void InitializeState()
        {
            if (_state == null)
                _state = new SoundSensorState();

            if (_state.PollingFrequencyMs == 0)
                _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs;

            if (_genericState == null)
                _genericState = new pxanalogsensor.AnalogSensorState();

            _state.TimeStamp = DateTime.MinValue;
            _state.Connected = false;
            _state.Intensity = 0;

            _genericState.RawMeasurementRange = 255.0;
        }
        /// <summary>
        /// Initialize the Light Sensor state
        /// </summary>
        private void InitializeState()
        {
            if (_state == null)
                _state = new LightSensorState();

            if (_state.PollingFrequencyMs == 0)
                _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs;

            _state.TimeStamp = DateTime.MinValue;
            _state.Intensity = 0;
            _state.Connected = false;

            if (_genericState == null)
                _genericState = new pxanalogsensor.AnalogSensorState();

            _genericState.RawMeasurementRange = 255.0;
            _genericState.RawMeasurement = 0.0;
            _genericState.NormalizedMeasurement = 0.0;
            _genericState.TimeStamp = DateTime.MinValue;

            // Set the hardware identifier from the connected motor port.
            _genericState.HardwareIdentifier = NxtCommon.HardwareIdentifier(_state.SensorPort);
        }
        /// <summary>
        /// Initialize the Color Sensor state
        /// </summary>
        private void InitializeState()
        {
            if (_state == null)
            {
                _state = new ColorSensorState();
                // Default to Color mode if no config file
                _state.SensorMode = ColorSensorMode.Color;
            }

            if (_state.PollingFrequencyMs == 0)
                _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs;

            _state.TimeStamp = DateTime.MinValue;
            _state.Reading = 0;
            _state.Connected = false;

            if (_genericState == null)
                _genericState = new pxanalogsensor.AnalogSensorState();

            // Analog range is 0-1023 (10-bit A/D)
            _genericState.RawMeasurementRange = 1023.0;
            _genericState.RawMeasurement = 0.0;
            _genericState.NormalizedMeasurement = 0.0;
            _genericState.TimeStamp = DateTime.MinValue;

            // Set the hardware identifier from the connected motor port.
            _genericState.HardwareIdentifier = NxtCommon.HardwareIdentifier(_state.SensorPort);
        }