Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/src/edu/wpi/hri/gen/Generation.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.gen; 00035 00036 import java.io.BufferedReader; 00037 import java.io.File; 00038 import java.io.InputStreamReader; 00039 00040 import ros.NodeHandle; 00041 import ros.Ros; 00042 import ros.RosException; 00043 import edu.wpi.hri.bml.XMLInterface; 00044 import edu.wpi.hri.comm.MasterSpinner; 00045 import edu.wpi.hri.gen.comm.BMLEmitListener; 00046 import edu.wpi.hri.gen.comm.BMLRealizer; 00047 import edu.wpi.hri.gen.comm.GazeKnowledge; 00048 import edu.wpi.hri.gen.comm.SituationKnowledge; 00049 import edu.wpi.hri.gen.comm.TurnFragmentProvider; 00050 import edu.wpi.hri.gen.policy.DefaultGazePolicy; 00051 import edu.wpi.hri.gen.policy.GazeInterestPolicy; 00052 import edu.wpi.hri.gen.policy.GlancePolicy; 00053 import edu.wpi.hri.gen.policy.HIDGPolicy; 00054 import edu.wpi.hri.gen.policy.HIMFGPolicy; 00055 import edu.wpi.hri.gen.policy.TurnPositionPolicy; 00056 import edu.wpi.hri.gen.policy.ref.DegradedReferencePolicy; 00057 import edu.wpi.hri.gen.policy.ref.NoPointZone; 00058 import edu.wpi.hri.gen.policy.ref.ReferencePolicy; 00059 import edu.wpi.hri.log.Logger; 00060 import edu.wpi.hri.log.Logger.Colors; 00061 import edu.wpi.hri.log.Logger.LoggerLevel; 00062 00070 public class Generation { 00071 00072 // the basic stuff 00073 private final NodeHandle handle; 00074 private final Logger logger; 00075 private final XMLInterface xml; 00076 private final NoPointZone noZone; 00077 00078 // the comm objects 00079 private final BMLEmitListener emit; 00080 private final BMLRealizer realizer; 00081 private final GazeKnowledge gaze; 00082 private final MasterSpinner spinner; 00083 private final TurnFragmentProvider turnFrags; 00084 private final SituationKnowledge situation; 00085 00086 // then the policies 00087 private final DefaultGazePolicy defaultPolicy; 00088 private final GazeInterestPolicy interestPolicy; 00089 private final GlancePolicy glancePolicy; 00090 private final HIDGPolicy hidgPolicy; 00091 private final HIMFGPolicy himfgPolicy; 00092 private final ReferencePolicy refPolicy; 00093 private final TurnPositionPolicy turnPolicy; 00094 00095 private Generation() throws RosException { 00096 setupParameters(); 00097 00098 boolean full = GenerationParams.RUN_FULL.getBoolean(); 00099 00100 handle = Ros.getInstance().createNodeHandle(); 00101 00102 // create the logger by checking which to create 00103 LoggerLevel maxLevel = LoggerLevel.valueOf(GenerationParams.DEBUG_LEVEL 00104 .getString()); 00105 String type = GenerationParams.LOGGER_TYPE.getString(); 00106 logger = Logger.createBase(maxLevel, type, Colors.GENER, "GENER"); 00107 xml = createXML(logger); 00108 00109 // now instantiate all of the the member variables 00110 emit = new BMLEmitListener(handle, logger); 00111 spinner = new MasterSpinner(logger, true); 00112 realizer = new BMLRealizer(handle, spinner, logger); 00113 gaze = new GazeKnowledge(handle, logger, xml, realizer); 00114 situation = new SituationKnowledge(logger, handle); 00115 00116 noZone = new NoPointZone(logger, situation, gaze); 00117 noZone.addAllZones(handle); 00118 00119 // then the policies 00120 if (full) { 00121 glancePolicy = new GlancePolicy(handle, logger, gaze, gaze); 00122 hidgPolicy = new HIDGPolicy(handle, logger, gaze, glancePolicy); 00123 himfgPolicy = new HIMFGPolicy(handle, logger, gaze, hidgPolicy); 00124 interestPolicy = new GazeInterestPolicy(handle, logger, gaze, 00125 himfgPolicy); 00126 defaultPolicy = new DefaultGazePolicy(logger, handle, gaze, 00127 interestPolicy); 00128 00129 gaze.setBottomListener(defaultPolicy); 00130 00131 refPolicy = new ReferencePolicy(logger, emit, noZone); 00132 } else { 00133 defaultPolicy = null; 00134 interestPolicy = null; 00135 glancePolicy = null; 00136 hidgPolicy = null; 00137 himfgPolicy = null; 00138 refPolicy = new DegradedReferencePolicy(logger, emit, noZone); 00139 } 00140 turnPolicy = new TurnPositionPolicy(handle, logger, emit, full); 00141 00142 // then the objects which require policies 00143 turnFrags = new TurnFragmentProvider(handle, logger, realizer, xml, 00144 gaze, situation, emit, refPolicy, turnPolicy); 00145 00146 // in form the outside world that generation is ready to go 00147 logger.debug(LoggerLevel.ALWAYS, "Generation started"); 00148 } 00149 00158 public static XMLInterface createXML(Logger logger) { 00159 try { 00160 Process p = Runtime.getRuntime().exec( 00161 "rospack find engagement_generation"); 00162 p.waitFor(); 00163 BufferedReader stdInput = new BufferedReader(new InputStreamReader( 00164 p.getInputStream())); 00165 String egFolder = stdInput.readLine(); 00166 String file = egFolder + "/ebml.xsd"; 00167 return new XMLInterface(logger, new File(file)); 00168 } catch (Exception e) { 00169 } 00170 return null; 00171 } 00172 00177 public static void setupParameters() { 00178 // logger stuff 00179 GenerationParams.DEBUG_LEVEL.setString(LoggerLevel.ALL.toString()); 00180 GenerationParams.LOGGER_TYPE.setString("SYSTEM"); 00181 00182 // glance timing 00183 GenerationParams.GLANCE_DELAY_FACTOR.setDouble(2.0); 00184 GenerationParams.GLANCE_DURATION_MS.setInt(1000); 00185 GenerationParams.GLANCE_DELAY_MAX.setInt(5000); 00186 GenerationParams.GLANCE_DELAY_MIN.setInt(1000); 00187 00188 // recognition paths 00189 GenerationParams.ROBOT_AP_PATH 00190 .setString("recognition/robot/adjacency_pair"); 00191 GenerationParams.ROBOT_DG_PATH 00192 .setString("recognition/robot/directed_gaze"); 00193 GenerationParams.ROBOT_MFG_PATH 00194 .setString("recognition/robot/mutual_facial_gaze"); 00195 GenerationParams.HUMAN_AP_PATH 00196 .setString("recognition/human/adjacency_pair"); 00197 GenerationParams.HUMAN_DG_PATH 00198 .setString("recognition/human/directed_gaze"); 00199 GenerationParams.HUMAN_MFG_PATH 00200 .setString("recognition/human/mutual_facial_gaze"); 00201 00202 // bml paths 00203 GenerationParams.BML_EMIT_PATH.setString("bml/emit"); 00204 00205 // reliability values 00206 GenerationParams.RELIABILITY_SPEECH.setDouble(0.6); 00207 GenerationParams.RELIABILITY_GAZE.setDouble(0.1); 00208 GenerationParams.RELIABILITY_DIRECTED_GAZE.setDouble(0.2); 00209 GenerationParams.RELIABILITY_DIRECTED_GAZE_POINTING.setDouble(0.3); 00210 00211 // then situation specific 00212 GenerationParams.ROBOT_SHOULDER_LENGTH.setDouble(20.0); 00213 GenerationParams.ROBOT_SHOULDER_HEIGHT.setDouble(85.0); 00214 GenerationParams.ROBOT_ARM_LENGTH.setDouble(56.0); 00215 GenerationParams.ROBOT_HEAD_HEIGHT.setDouble(90.0); 00216 00217 // then constants for factors 00218 GenerationParams.CONSTANT_GAZE_COST_FACTOR.setDouble(0.01); 00219 GenerationParams.CONSTANT_POINT_COST_FACTOR.setDouble(0.001); 00220 GenerationParams.CONSTANT_GAZE_DISTRACTOR_DISTANCE.setDouble(750.0); 00221 GenerationParams.CONSTANT_POINT_DISTRACTOR_DISTANCE.setDouble(350.0); 00222 00223 // by default run the full generation node 00224 GenerationParams.RUN_FULL.setBoolean(true); 00225 } 00226 00227 private void run() { 00228 spinner.joinOldMasters(); 00229 } 00230 00231 private void shutdown() { 00232 // the comm shutdowns 00233 realizer.shutdown(); 00234 gaze.shutdown(); 00235 turnFrags.shutdown(); 00236 situation.shutdown(); 00237 00238 // then the policy shutdowns 00239 if (GenerationParams.RUN_FULL.getBoolean()) { 00240 emit.shutdown(); 00241 defaultPolicy.shutdown(); 00242 interestPolicy.shutdown(); 00243 glancePolicy.shutdown(); 00244 hidgPolicy.shutdown(); 00245 himfgPolicy.shutdown(); 00246 } 00247 00248 // then the handle itself 00249 handle.shutdown(); 00250 } 00251 00260 public static void main(String[] args) throws RosException { 00261 Ros.getInstance().init("generation", false, false, false, args); 00262 Generation generation = new Generation(); 00263 generation.run(); 00264 generation.shutdown(); 00265 } 00266 } |