Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/test/edu/wpi/hri/gen/policy/ref/GestureStateTest.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.comm.MasterSpinner; 00020 import edu.wpi.hri.gen.comm.BMLRealizer; 00021 import edu.wpi.hri.gen.comm.GazeKnowledge; 00022 import edu.wpi.hri.gen.comm.SituationKnowledge; 00023 import edu.wpi.hri.log.Logger; 00024 import edu.wpi.hri.log.Logger.LoggerLevel; 00025 00026 public class GestureStateTest extends TestCase { 00027 00028 @Test 00029 public void testGestureState() throws RosException { 00030 GestureState state = new GestureState(new Point(1, 1, 1), new Point(2, 00031 3, 4), new Point(5, 6, 7)); 00032 assertEquals(new Point(1, 1, 1), state.getGazePoint()); 00033 assertEquals(new Point(2, 3, 4), state.getRobotLeftHand()); 00034 assertEquals(new Point(5, 6, 7), state.getRobotRightHand()); 00035 00036 GestureState next = state.nextState(null, new Point(.1, .2, .3), null); 00037 assertEquals(state.getGazePoint(), next.getGazePoint()); 00038 assertEquals(new Point(.1, .2, .3), next.getRobotLeftHand()); 00039 assertEquals(state.getRobotRightHand(), next.getRobotRightHand()); 00040 00041 GestureState third = next.nextState(new Point(1.1, 2.2, 3.3), null, 00042 new Point(1.1, 2.2, 3.3)); 00043 assertEquals(new Point(1.1, 2.2, 3.3), third.getGazePoint()); 00044 assertEquals(next.getRobotLeftHand(), third.getRobotLeftHand()); 00045 assertEquals(new Point(1.1, 2.2, 3.3), third.getRobotRightHand()); 00046 00047 Logger logger = Logger.createDefault(); 00048 logger.info("CREATE STUFF HERE"); 00049 00050 NodeHandle handle = Ros.getInstance().createNodeHandle(); 00051 XMLInterface xml = new XMLInterface(logger, new File("ebml.xsd")); 00052 MasterSpinner spin = new MasterSpinner(logger, false); 00053 logger.debug(LoggerLevel.ALL, "setup ..."); 00054 BMLRealizer realizer = new BMLRealizer(handle, spin, logger); 00055 logger.debug(LoggerLevel.ALL, "setup ..."); 00056 GazeKnowledge gaze = new GazeKnowledge(handle, logger, xml, realizer); 00057 SituationKnowledge world = new SituationKnowledge(logger, handle); 00058 00059 logger.info("CREATED lots of STUFF HERE"); 00060 00061 EntityPosition pos = new EntityPosition(); 00062 pos.entity.id = "target"; 00063 pos.entity.type = Entity.OBJECT; 00064 pos.rotation = 0; 00065 pos.x = 1.1f; 00066 pos.y = 2.2f; 00067 pos.z = 3.3f; 00068 world.call(pos); 00069 00070 pos = new EntityPosition(); 00071 pos.entity.id = "ROBOT"; 00072 pos.entity.type = Entity.UNKNOWN; 00073 pos.rotation = 0; 00074 pos.x = 80f; 00075 pos.y = 90f; 00076 pos.z = 100f; 00077 world.call(pos); 00078 00079 Performance perf = new Performance(); 00080 perf.actor.id = ActorID.ROBOT; 00081 perf.begin.value = Flag.TRUE; 00082 perf.objects = new ArrayList<Entity>(); 00083 perf.objects.add(new Entity()); 00084 perf.objects.get(0).id = "target"; 00085 perf.objects.get(0).type = Entity.OBJECT; 00086 perf.prob = new float[1]; 00087 perf.prob[0] = 1.0f; 00088 00089 gaze.call(perf); 00090 GestureState inputState = new GestureState(gaze, world); 00091 assertTrue(world.get("target").equals(inputState.getGazePoint())); 00092 assertTrue(world.getRobotLeftHand().equals( 00093 inputState.getRobotLeftHand())); 00094 assertTrue(world.getRobotRightHand().equals( 00095 inputState.getRobotRightHand())); 00096 00097 world.shutdown(); 00098 gaze.shutdown(); 00099 realizer.shutdown(); 00100 spin.stop(); 00101 spin.joinOldMasters(); 00102 handle.shutdown(); 00103 } 00104 } |