Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/test/edu/wpi/hri/gen/policy/GlancePolicyTest.javaGo to the documentation of this file.00001 package edu.wpi.hri.gen.policy; 00002 00003 import junit.framework.TestCase; 00004 00005 import org.junit.Test; 00006 00007 import ros.NodeHandle; 00008 import ros.Ros; 00009 import ros.RosException; 00010 import edu.wpi.hri.bml.XMLInterface; 00011 import edu.wpi.hri.comm.MasterSpinner; 00012 import edu.wpi.hri.gen.Generation; 00013 import edu.wpi.hri.gen.GenerationParams; 00014 import edu.wpi.hri.gen.comm.BMLRealizer; 00015 import edu.wpi.hri.gen.comm.GazeKnowledge; 00016 import edu.wpi.hri.log.Logger; 00017 00018 public class GlancePolicyTest extends TestCase { 00019 00020 private int called = 0; 00021 00022 @Test 00023 public void testPolicy() throws RosException, InterruptedException { 00024 GenerationParams.GLANCE_DELAY_FACTOR.setInt(15); 00025 GenerationParams.GLANCE_DURATION_MS.setInt(10); 00026 00027 Logger logger = Logger.createDefault(); 00028 XMLInterface xml = Generation.createXML(logger); 00029 NodeHandle handle = Ros.getInstance().createNodeHandle(); 00030 MasterSpinner spin = new MasterSpinner(logger, false); 00031 BMLRealizer realizer = new BMLRealizer(handle, spin, logger); 00032 GazeKnowledge gaze = new GazeKnowledge(handle, logger, xml, realizer) { 00033 @Override 00034 public boolean trySetGaze(String target) { 00035 called++; 00036 return true; 00037 } 00038 }; 00039 GlancePolicy policy = new GlancePolicy(handle, logger, gaze, gaze); 00040 00041 // just an object 00042 policy.gazeChanged("object-test", false, false); 00043 assertEquals(0, called); 00044 Thread.sleep(GenerationParams.GLANCE_DELAY_FACTOR.getInt() + 10); 00045 assertEquals(0, called); 00046 00047 // the first face detected 00048 policy.gazeChanged("face-test", true, false); 00049 assertEquals(0, called); 00050 Thread.sleep(GenerationParams.GLANCE_DELAY_FACTOR.getInt() + 10); 00051 assertEquals(0, called); 00052 00053 // a face right after an object 00054 policy.gazeChanged("object-test", false, false); 00055 policy.gazeChanged("face-test", true, false); 00056 Thread.sleep(GenerationParams.GLANCE_DELAY_FACTOR.getInt() + 10); 00057 assertEquals(0, called); 00058 00059 // had a face now object 00060 policy.gazeChanged("object-test", false, false); 00061 assertEquals(0, called); 00062 Thread.sleep(GenerationParams.GLANCE_DELAY_FACTOR.getInt() 00063 + GenerationParams.GLANCE_DURATION_MS.getInt() + 20); 00064 assertEquals(2, called); 00065 00066 policy.shutdown(); 00067 gaze.shutdown(); 00068 realizer.shutdown(); 00069 spin.stop(); 00070 spin.joinOldMasters(); 00071 handle.shutdown(); 00072 } 00073 } |