public virtual IEnumerator <ITask> AnalogReplaceHandler(pxanalogsensor.Replace replace) { _state.SensorPort = NxtCommon.GetNxtSensorPortFromHardwareIdentifier(replace.Body.HardwareIdentifier); SendNotification <pxanalogsensor.Replace>(_genericSubMgrPort, replace); replace.ResponsePort.Post(DefaultReplaceResponseType.Instance); yield break; }
/// <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(); }
/// <summary> /// Analog Sensor Notification Handler /// </summary> /// <param name="notification"></param> private void AnalogSensorNotificationHandler(analog.Replace notification) { LogVerbose(LogGroups.Console, string.Format("Sensor Notification: {0} {1}", notification.Body.HardwareIdentifier, notification.Body.RawMeasurement)); foreach (SensorRange key in _state.RuntimeConfiguration.Keys) { if (key.HardwareIdentifier != notification.Body.HardwareIdentifier) { continue; } PortConfiguration sensorConfig = _state.RuntimeConfiguration[key]; string contactSensorName = key.ContactSensorName; int priorIx = _contactSensorArrayState.Sensors.FindIndex( delegate(bumper.ContactSensor gencs) { return(gencs.HardwareIdentifier == notification.Body.HardwareIdentifier && gencs.Name == contactSensorName); }); bool priorPressed = (priorIx < 0) ? false : _contactSensorArrayState.Sensors[priorIx].Pressed; // Send a ContactSensor notification here. bumper.ContactSensor cs = new bumper.ContactSensor(sensorConfig.HardwareIdentifier, contactSensorName); cs.Pressed = sensorConfig.Pressed(notification.Body.RawMeasurement); sensorConfig.Contact = cs.Pressed; if (priorIx < 0) { _contactSensorArrayState.Sensors.Add(cs); } if (priorIx < 0 || priorPressed != cs.Pressed) { if (priorIx >= 0) { _contactSensorArrayState.Sensors[priorIx].Pressed = cs.Pressed; } SendNotification <bumper.Update>(_subMgrPort, new bumper.Update(cs)); } } }
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; }
public virtual IEnumerator <ITask> ReplaceHandler(pxanalogsensor.Replace replace) { _state = replace.Body; replace.ResponsePort.Post(DefaultReplaceResponseType.Instance); yield break; }
public virtual IEnumerator <ITask> ReplaceHandler(pxanalogsensor.Replace replace) { replace.ResponsePort.Post(Fault.FromException(new InvalidOperationException("The LEGO NXT Ultrasonic sensor is updated from hardware."))); yield break; }