Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/src/edu/wpi/hri/gen/policy/DefaultGazePolicy.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright notice, this 00010 * list of conditions and the following disclaimer. * Redistributions in binary 00011 * form must reproduce the above copyright notice, this list of conditions and 00012 * the following disclaimer in the documentation and/or other materials provided 00013 * with the distribution. * Neither the name of Worcester Polytechnic Institute. 00014 * nor the names of its contributors may be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 package edu.wpi.hri.gen.policy; 00030 00031 import ros.NodeHandle; 00032 import ros.RosException; 00033 import ros.Subscriber; 00034 import ros.pkg.engagement_msgs.msg.ActorIDStatus; 00035 import edu.wpi.hri.gen.comm.GazeKnowledge; 00036 import edu.wpi.hri.gen.comm.GazeListener; 00037 import edu.wpi.hri.log.Logger; 00038 import edu.wpi.hri.log.Logger.Colors; 00039 import edu.wpi.hri.log.Logger.LoggerLevel; 00040 00049 public class DefaultGazePolicy extends GazeListener implements 00050 Subscriber.Callback<ActorIDStatus> { 00051 00052 private final Logger logger; 00053 private String faceTarget; 00054 private Subscriber<ActorIDStatus> hfacesub; 00055 00070 public DefaultGazePolicy(Logger logger, NodeHandle handle, 00071 GazeKnowledge gaze, GazeListener next) throws RosException { 00072 super(next); 00073 this.logger = logger.sub(Colors.POLICY, "DEF-GAZE"); 00074 gaze.addListener(this); 00075 this.faceTarget = ""; 00076 00077 this.hfacesub = handle.subscribe("vision/face", new ActorIDStatus(), 00078 this, 100); 00079 00080 this.logger.debug(LoggerLevel.INIT, "Created ..."); 00081 } 00082 00086 public void shutdown() { 00087 this.hfacesub.shutdown(); 00088 } 00089 00090 @Override 00091 public void gazeChanged(String target, boolean face, boolean lock) { 00092 if ((target == null) || (target.isEmpty())) { 00093 this.logger.debug(LoggerLevel.POLICY_EXECUTION, 00094 "Defaulting to face tracking"); 00095 setTarget(faceTarget); 00096 } else if (face && !this.faceTarget.equals(target)) { 00097 this.logger.debug(LoggerLevel.IO, "It's a neeeew faaaace!!"); 00098 this.faceTarget = target; 00099 setTarget(faceTarget); 00100 } 00101 } 00102 00103 @Override 00104 public void call(ActorIDStatus actor) { 00105 if (!this.faceTarget.equals(actor.actor.id)) { 00106 this.logger 00107 .debug(LoggerLevel.IO, "It's a neeeew (actor) faaaace!!"); 00108 setTarget(actor.actor.id); 00109 } 00110 } 00111 } |