/// <summary> /// Handler for Contact Sensor Notifications /// </summary> /// <param name="updateNotification"></param> void BumperNotificationHandler(contactsensor.Update updateNotification) { // Since we are writing a generic wander service we dont really know // which bumper is front, side, rear etc. We expect a navigation service to be tuned // to a robot platform or read configuration through its initial state. // here, we just assume the bumpers are named intuitively so we search by name contactsensor.ContactSensor s = updateNotification.Body; if (!s.Pressed) { return; } if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("front")) { SpawnIterator <double>(-1, BackUpTurnAndMove); return; } if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("rear")) { SpawnIterator <double>(1, BackUpTurnAndMove); return; } }
/// <summary> /// Handle Bumper Notifications /// </summary> /// <param name="notification">Update notification</param> private void BumperHandler(bumper.Update notification) { string message; if (!notification.Body.Pressed) { return; } // Toggle the motor state _state.MotorOn = !_state.MotorOn; // Create a motor request motor.SetMotorPowerRequest motorRequest = new motor.SetMotorPowerRequest(); if (_state.MotorOn) { // Set the motor power on motorRequest.TargetPower = 1.0; message = "Motor On"; } else { // Set the motor power off motorRequest.TargetPower = 0.0; message = "Motor Off"; } // Send the motor request _motorPort.SetMotorPower(motorRequest); // Show the motor status on the console screen LogInfo(LogGroups.Console, message); }
public virtual IEnumerator <ITask> UpdateHandler(bumper.Update update) { bool replace = false; DateTime timestamp = DateTime.Now; update.ResponsePort.Post(DefaultUpdateResponseType.Instance); foreach (bumper.ContactSensor contactSensor in _state.Sensors) { if (contactSensor.HardwareIdentifier == update.Body.HardwareIdentifier) { contactSensor.Name = update.Body.Name; contactSensor.Pressed = update.Body.Pressed; contactSensor.TimeStamp = timestamp; SendNotification <bumper.Update>(_subMgrPort, new bumper.Update(contactSensor)); replace = true; } } if (replace) { SendNotification <bumper.Replace>(_subMgrPort, new bumper.Replace(_state)); } yield break; }
protected void BumperHandler(bumper.Update notification) { if (string.IsNullOrEmpty(notification.Body.Name)) { LogInfo(LogGroups.Console, "Bumper name is null or empty."); return; } string bumperName = notification.Body.Name.ToLowerInvariant(); //Trace.WriteLine(bumperName + " @ " + DateTime.Now + ": " + notification.Body.Pressed); if (bumperName.Contains("front")) { lock (_soar.Bumper) { _soar.Bumper.FrontBumperPressed = notification.Body.Pressed; } } else if (bumperName.Contains("rear")) { lock (_soar.Bumper) { _soar.Bumper.RearBumperPressed = notification.Body.Pressed; } } }
/// <summary> /// Handle Bumper Notifications /// </summary> /// <param name="notification">Update notification</param> private void BumperHandler(bumper.Update notification) { if (notification.Body.Pressed) { LogInfo(LogGroups.Console, "Ouch - the bumper was pressed."); } }
public IEnumerator <ITask> UpdateHandler(bumper.Update update) { bumper.ContactSensor sensor = _state.Sensors.Find( delegate(bumper.ContactSensor s) { return(update.Body.HardwareIdentifier == s.HardwareIdentifier); }); if (sensor != null) { sensor.Name = update.Body.Name; sensor.Pressed = update.Body.Pressed; sensor.TimeStamp = update.Body.TimeStamp; update.ResponsePort.Post(DefaultUpdateResponseType.Instance); } throw new InvalidOperationException("Contact Sensor " + update.Body.HardwareIdentifier + " : " + update.Body.Name + " does not exist."); }
void BumperNotificationHandler(contactsensor.Update updateNotification) { contactsensor.ContactSensor s = updateNotification.Body; if (!s.Pressed) { return; } if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("left")) { //say something speech.SayTextRequest saythis = new speech.SayTextRequest(); saythis.SpeechText = "Turning right"; _speechPort.SayText(saythis); //update state _state.CurrentAction = "Turning right"; //move SpawnIterator <int>(-800, BackUpTurnAndMove); } else if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("right")) { //say something speech.SayTextRequest saythis = new speech.SayTextRequest(); saythis.SpeechText = "Turning left"; _speechPort.SayText(saythis); //update state _state.CurrentAction = "Turning left"; //move SpawnIterator <int>(800, BackUpTurnAndMove); } else if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("stall")) { //say something speech.SayTextRequest saythis = new speech.SayTextRequest(); saythis.SpeechText = "Ouch, let go."; _speechPort.SayText(saythis); //update state _state.CurrentAction = "Turning around"; //move SpawnIterator <int>(800, BackUpTurnAndMove); } }
/// <summary> /// Handles Update notification from the Bumper partner - updates a single sensor state (usually whiskers) /// </summary> /// <remarks>Posts a <typeparamref name="BumperUpdate"/> to itself.</remarks> /// <param name="update">notification</param> void BumperUpdateNotification(bumper.Update update) { LogInfo("DriveBehaviorServiceBase: BumperUpdateNotification()"); _mainPort.Post(new BumperUpdate(update.Body)); }
/// <summary> /// Handles Update notification from the Bumper partner /// </summary> /// <remarks>Posts a <typeparamref name="BumperUpdate"/> to itself.</remarks> /// <param name="update">notification</param> void BumperUpdateNotification(bumper.Update update) { _mainPort.Post(new BumperUpdate(update.Body)); }
public virtual IEnumerator<ITask> UpdateHandler(pxbumper.Update updateBumper) { throw new InvalidOperationException("Track Roamer Bumper Sensors are not updateable"); }
/// <summary> /// Handles Update notification from the Bumper partner /// </summary> /// <remarks>Posts a <typeparamref name="BumperUpdate"/> to itself.</remarks> /// <param name="update">notification</param> void BumperUpdateNotification(bumper.Update update) { LogInfo("Explorer: BumperUpdateNotification()"); _mainPort.Post(new BumperUpdate(update.Body)); }
public virtual IEnumerator <ITask> GenericUpdateHandler(bumper.Update update) { throw new InvalidOperationException("Contact Sensor Update is a Notification and not valid in this context."); }