Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/src/edu/wpi/hri/gen/GenerationParams.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.util.Hashtable; 00037 00038 import ros.Ros; 00039 00049 public enum GenerationParams { 00050 // FIRST the testing params for this enum 00052 _TEST_BOOL_("_test_bool_", Type.BOOLEAN), 00054 _TEST_INT_("_test_int_", Type.INT), 00056 _TEST_DOUBLE_("_test_double_", Type.DOUBLE), 00058 _TEST_STRING_("_test_string_", Type.STRING), 00059 // then the actual params which can come from the ROS network stuff 00060 // first the logger information 00062 DEBUG_LEVEL("debug_level", Type.STRING), 00064 LOGGER_TYPE("logger_type", Type.STRING), 00065 // then how to talk to recognition 00067 ROBOT_AP_PATH("robot_ap_path", Type.STRING), 00069 ROBOT_DG_PATH("robot_dg_path", Type.STRING), 00071 ROBOT_MFG_PATH("robot_mfg_path", Type.STRING), 00073 HUMAN_AP_PATH("human_ap_path", Type.STRING), 00075 HUMAN_DG_PATH("human_dg_path", Type.STRING), 00077 HUMAN_MFG_PATH("human_mfg_path", Type.STRING), 00078 // then how to talk to the bml realizer 00080 BML_EMIT_PATH("bml_emit_path", Type.STRING), 00081 // then reliability information for references 00083 RELIABILITY_SPEECH("reliability/speech", Type.DOUBLE), 00085 RELIABILITY_GAZE("reliability/gaze", Type.DOUBLE), 00087 RELIABILITY_DIRECTED_GAZE("reliability/directed_gaze", Type.DOUBLE), 00089 RELIABILITY_DIRECTED_GAZE_POINTING("reliability/directed_gaze_pointing", 00090 Type.DOUBLE), 00091 // then situation specific information 00093 ROBOT_SHOULDER_LENGTH("robot/shoulder_length", Type.DOUBLE), 00095 ROBOT_SHOULDER_HEIGHT("robot/shoulder_height", Type.DOUBLE), 00097 ROBOT_ARM_LENGTH("robot/arm_length", Type.DOUBLE), 00099 ROBOT_HEAD_HEIGHT("robot/head_height", Type.DOUBLE), 00100 // then all of the constants that are required 00102 CONSTANT_GAZE_COST_FACTOR("constant/gaze_cost_factor", Type.DOUBLE), 00104 CONSTANT_POINT_COST_FACTOR("constant/point_cost_factor", Type.DOUBLE), 00106 CONSTANT_GAZE_DISTRACTOR_DISTANCE("constant/gaze_distractor_distance", 00107 Type.DOUBLE), 00112 CONSTANT_POINT_DISTRACTOR_DISTANCE("constant/point_distractor_distance", 00113 Type.DOUBLE), 00114 // then glancing information 00119 GLANCE_DELAY_FACTOR("constant/glance_delay_factor", Type.DOUBLE), 00124 GLANCE_DURATION_MS("constant/glance_duration_ms", Type.INT), 00126 GLANCE_DELAY_MAX("constant/glance_delay_max", Type.INT), 00128 GLANCE_DELAY_MIN("constant/glance_delay_min", Type.INT), 00130 RUN_FULL("run_full", Type.BOOLEAN); 00131 00133 private static final ParamTable<Boolean> boolParam = new ParamTable<Boolean>( 00134 false); 00136 private static final ParamTable<Integer> intParam = new ParamTable<Integer>( 00137 0); 00139 private static final ParamTable<Double> doubleParam = new ParamTable<Double>( 00140 0.0); 00142 private static final ParamTable<String> stringParam = new ParamTable<String>( 00143 ""); 00144 00145 // private stuff from here 00146 public static final String NAMESPACE = "generation/conf"; 00147 private final String param; 00148 private final Type type; 00149 00158 private GenerationParams(String param, Type type) { 00159 this.param = param; 00160 this.type = type; 00161 } 00162 00169 public void setBoolean(boolean value) { 00170 if (this.type == Type.BOOLEAN) 00171 boolParam.set(this.param, value); 00172 } 00173 00180 public void setDouble(double value) { 00181 if (this.type == Type.DOUBLE) 00182 doubleParam.set(this.param, value); 00183 } 00184 00191 public void setInt(int value) { 00192 if (this.type == Type.INT) 00193 intParam.set(this.param, value); 00194 } 00195 00202 public void setString(String value) { 00203 if (this.type == Type.STRING) 00204 stringParam.set(this.param, value); 00205 } 00206 00212 public boolean getBoolean() { 00213 if (this.type == Type.BOOLEAN) 00214 try { 00215 return Ros.getInstance().createNodeHandle(NAMESPACE) 00216 .getBooleanParam(this.param, false); 00217 } catch (Exception e) { 00218 return boolParam.get(this.param); 00219 } 00220 else 00221 return false; 00222 } 00223 00229 public double getDouble() { 00230 if (this.type == Type.DOUBLE) 00231 try { 00232 return Ros.getInstance().createNodeHandle(NAMESPACE) 00233 .getDoubleParam(this.param, false); 00234 } catch (Exception e) { 00235 return doubleParam.get(this.param); 00236 } 00237 else 00238 return 0.0; 00239 } 00240 00246 public int getInt() { 00247 if (this.type == Type.INT) 00248 try { 00249 return Ros.getInstance().createNodeHandle(NAMESPACE) 00250 .getIntParam(this.param, false); 00251 } catch (Exception e) { 00252 return intParam.get(this.param); 00253 } 00254 else 00255 return 0; 00256 } 00257 00263 public String getString() { 00264 if (this.type == Type.STRING) 00265 try { 00266 return Ros.getInstance().createNodeHandle(NAMESPACE) 00267 .getStringParam(this.param, false); 00268 } catch (Exception e) { 00269 return stringParam.get(this.param); 00270 } 00271 else 00272 return ""; 00273 } 00274 00275 private static enum Type { 00276 STRING, INT, DOUBLE, BOOLEAN; 00277 } 00278 00287 private static class ParamTable<T> { 00288 final Hashtable<String, T> table; 00289 final T defaultValue; 00290 00297 ParamTable(T def) { 00298 this.table = new Hashtable<String, T>(); 00299 this.defaultValue = def; 00300 } 00301 00310 void set(String s, T value) { 00311 this.table.put(s, value); 00312 } 00313 00321 T get(String s) { 00322 T value = this.table.get(s); 00323 if (value != null) 00324 return value; 00325 else 00326 return this.defaultValue; 00327 } 00328 } 00329 } |