Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/test/edu/wpi/hri/gen/policy/GazeInterestPolicyTest.javaGo to the documentation of this file.00001 package edu.wpi.hri.gen.policy; 00002 00003 import java.util.ArrayList; 00004 import java.util.List; 00005 00006 import junit.framework.TestCase; 00007 00008 import org.junit.Test; 00009 00010 import ros.NodeHandle; 00011 import ros.Ros; 00012 import ros.RosException; 00013 import ros.pkg.bml_msgs.msg.Entity; 00014 import ros.pkg.bml_msgs.msg.Flag; 00015 import ros.pkg.engagement_msgs.msg.Performance; 00016 import edu.wpi.hri.bml.XMLInterface; 00017 import edu.wpi.hri.comm.MasterSpinner; 00018 import edu.wpi.hri.gen.Generation; 00019 import edu.wpi.hri.gen.comm.BMLRealizer; 00020 import edu.wpi.hri.gen.comm.GazeKnowledge; 00021 import edu.wpi.hri.log.Logger; 00022 00023 public class GazeInterestPolicyTest extends TestCase { 00024 00025 private boolean called = false; 00026 00027 @Test 00028 public void testPolicy() throws RosException { 00029 Logger logger = Logger.createDefault(); 00030 XMLInterface xml = Generation.createXML(logger); 00031 NodeHandle handle = Ros.getInstance().createNodeHandle(); 00032 MasterSpinner spin = new MasterSpinner(logger, false); 00033 BMLRealizer realizer = new BMLRealizer(handle, spin, logger); 00034 GazeKnowledge gaze = new GazeKnowledge(handle, logger, xml, realizer) { 00035 @Override 00036 public boolean trySetGaze(String target) { 00037 called = true; 00038 return true; 00039 } 00040 }; 00041 GazeInterestPolicy policy = new GazeInterestPolicy(handle, logger, gaze, gaze); 00042 00043 ArrayList<Entity> targets = new ArrayList<Entity>(); 00044 Entity ent = new Entity(); 00045 ent.id = "target-1"; 00046 ent.type = Entity.UNKNOWN; 00047 targets.add(ent); 00048 00049 assertFalse(called); 00050 Performance request = new Performance(); 00051 request.actor.id = "actor-test"; 00052 request.begin.value = Flag.BEGIN; 00053 request.objects = targets; 00054 request.prob = new float[targets.size()]; 00055 for (int c = 0; c < request.prob.length; c++) 00056 request.prob[c] = 1.0f; 00057 00058 policy.call(request); 00059 assertTrue(called); 00060 00061 called = false; 00062 request.begin.value = Flag.END; 00063 policy.call(request); 00064 assertFalse(called); 00065 00066 policy.shutdown(); 00067 gaze.shutdown(); 00068 realizer.shutdown(); 00069 spin.stop(); 00070 spin.joinOldMasters(); 00071 handle.shutdown(); 00072 } 00073 } |