Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/test/edu/wpi/hri/gen/policy/ref/ReferencePolicyTest.javaGo to the documentation of this file.00001 package edu.wpi.hri.gen.policy.ref; 00002 00003 import java.io.File; 00004 import java.util.ArrayList; 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.engagement_msgs.msg.ActorID; 00014 import ros.pkg.bml_msgs.msg.Entity; 00015 import ros.pkg.bml_msgs.msg.EntityPosition; 00016 import ros.pkg.bml_msgs.msg.Flag; 00017 import ros.pkg.engagement_msgs.msg.Performance; 00018 import edu.wpi.hri.bml.XMLInterface; 00019 import edu.wpi.hri.bml.behavior.SpeechBehavior; 00020 import edu.wpi.hri.bml.behavior.SyncRef; 00021 import edu.wpi.hri.bml.behavior.ConstraintBehavior.SyncBlock; 00022 import edu.wpi.hri.comm.MasterSpinner; 00023 import edu.wpi.hri.gen.comm.BMLEmitListener; 00024 import edu.wpi.hri.gen.comm.BMLRealizer; 00025 import edu.wpi.hri.gen.comm.GazeKnowledge; 00026 import edu.wpi.hri.gen.comm.SituationKnowledge; 00027 import edu.wpi.hri.gen.ebml.EBMLList; 00028 import edu.wpi.hri.gen.ebml.EBMLListTest; 00029 import edu.wpi.hri.log.Logger; 00030 00031 public class ReferencePolicyTest extends TestCase { 00032 00033 @Test 00034 public void testPolicy() throws RosException { 00035 Logger logger = Logger.createDefault(); 00036 NodeHandle handle = Ros.getInstance().createNodeHandle(); 00037 XMLInterface xml = new XMLInterface(logger, new File("ebml.xsd")); 00038 MasterSpinner spin = new MasterSpinner(logger, false); 00039 BMLRealizer realizer = new BMLRealizer(handle, spin, logger); 00040 GazeKnowledge knowledge = new GazeKnowledge(handle, logger, xml, 00041 realizer); 00042 SituationKnowledge world = new SituationKnowledge(logger, handle); 00043 BMLEmitListener emit = new BMLEmitListener(handle, logger); 00044 00045 // add in all of the needed positions 00046 EntityPosition pos = new EntityPosition(); 00047 pos.entity.id = "object-1"; 00048 pos.entity.type = Entity.OBJECT; 00049 pos.x = -1; 00050 pos.y = -2; 00051 pos.z = -3; 00052 pos.rotation = 0; 00053 world.call(pos); 00054 00055 pos = new EntityPosition(); 00056 pos.entity.id = "object-2"; 00057 pos.entity.type = Entity.OBJECT; 00058 pos.x = 1; 00059 pos.y = 2; 00060 pos.z = 3; 00061 pos.rotation = 0; 00062 world.call(pos); 00063 00064 pos = new EntityPosition(); 00065 pos.entity.id = "human-face"; 00066 pos.entity.type = Entity.OBJECT; 00067 pos.x = 20; 00068 pos.y = 50; 00069 pos.z = 100; 00070 pos.rotation = 0; 00071 world.call(pos); 00072 00073 Performance perf = new Performance(); 00074 perf.actor.id = ActorID.ROBOT; 00075 perf.begin.value = Flag.TRUE; 00076 perf.objects = new ArrayList<Entity>(); 00077 perf.objects.add(new Entity()); 00078 perf.objects.get(0).id = "human-face"; 00079 perf.objects.get(0).type = Entity.FACE; 00080 perf.prob = new float[1]; 00081 perf.prob[0] = 1.0f; 00082 knowledge.call(perf); 00083 00084 pos = new EntityPosition(); 00085 pos.entity.id = "ROBOT"; 00086 pos.entity.type = Entity.UNKNOWN; 00087 pos.x = -20; 00088 pos.y = -30; 00089 pos.z = 0; 00090 pos.rotation = 0; 00091 world.call(pos); 00092 00093 EBMLList list = new EBMLList(logger, xml, "ref-test"); 00094 list.getReferences().add( 00095 EBMLListTest.createReference(logger, xml, "ref-1", "object-1", 00096 0.85)); 00097 list.getReferences().add( 00098 EBMLListTest.createReference(logger, xml, "ref-2", "object-2", 00099 0.65)); 00100 00101 SyncBlock block = new SyncBlock(new SyncRef("ref-1:end")); 00102 block.addRef(new SyncRef("ref-2:start")); 00103 list.getOptionalConstraints().addSynchronized(block); 00104 00105 list.getSpeeches().add( 00106 new SpeechBehavior(logger, "speech", "hi", null, true)); 00107 block = new SyncBlock(new SyncRef("speech:end")); 00108 block.addRef(new SyncRef("ref-1:start")); 00109 list.getRequiredConstraints().addSynchronized(block); 00110 00111 ReferencePolicy policy = new ReferencePolicy(logger, emit, 00112 new NoPointZone(logger, world, knowledge)); 00113 assertTrue(policy.apply(list, knowledge, world, "face0")); 00114 assertEquals(0, list.getReferences().size()); 00115 00116 world.shutdown(); 00117 knowledge.shutdown(); 00118 realizer.shutdown(); 00119 spin.stop(); 00120 spin.joinOldMasters(); 00121 handle.shutdown(); 00122 } 00123 } |