Esempio n. 1
0
TEST(ASPRepComp, ontology1)
{
  std::string path = ros::package::getPath("ice");
  bool result;

  auto oi = std::make_shared<ice::OntologyInterface>(path + "/java/lib/");
  oi->addIRIMapper(path + "/ontology/");

  ASSERT_FALSE(oi->errorOccurred());

  result = oi->addOntologyIRI("http://vs.uni-kassel.de/IceTest");

  ASSERT_FALSE(oi->errorOccurred());
  ASSERT_TRUE(result);

  result = oi->loadOntologies();

  ASSERT_FALSE(oi->errorOccurred());
  ASSERT_TRUE(result);

  result = oi->isConsistent();

  ASSERT_FALSE(oi->errorOccurred());
  ASSERT_TRUE(result);

  std::shared_ptr<ice::GContainerFactory> factory = std::make_shared<ice::GContainerFactory>();
  factory->setOntologyInterface(oi);
  factory->init();

  ice::ASPTransformationGeneration asp;

  asp.setOntology(oi);
  asp.setGContainerFactory(factory);

  asp.extractTransformations();

  // Test transformation
  std::string name = "autoTrans_o2_Position_o2_CoordinatePositionRep_o0_Pos3D";
  auto trans = factory->getTransformationByName(name);

  ASSERT_TRUE(trans != false);

  auto repIn = factory->getRepresentation("o2_CoordinatePositionRep");
  auto repOut = factory->getRepresentation("o0_Pos3D");

  ASSERT_TRUE(repIn != false);
  ASSERT_TRUE(repOut != false);

  auto inX = repIn->accessPath( {"o2_XCoordinate"});
  auto inY = repIn->accessPath( {"o2_YCoordinate"});
  auto inZ = repIn->accessPath( {"o2_ZCoordinate"});

  auto outX = repOut->accessPath( {"o2_XCoordinate"});
  auto outY = repOut->accessPath( {"o2_YCoordinate"});
  auto outZ = repOut->accessPath( {"o2_ZCoordinate"});

  ASSERT_TRUE(inX != nullptr);
  ASSERT_TRUE(inY != nullptr);
  ASSERT_TRUE(inZ != nullptr);

  ASSERT_TRUE(outX != nullptr);
  ASSERT_TRUE(outY != nullptr);
  ASSERT_TRUE(outZ != nullptr);

  auto in = factory->makeInstance(repIn);

  double x = 4.44;
  double y = 5.55;
  double z = 6.66;

  in->set(inX, &x);
  in->set(inY, &y);
  in->set(inZ, &z);

  auto out = trans->transform(&in);

  EXPECT_EQ(out->getValue<double>(outX), x);
  EXPECT_EQ(out->getValue<double>(outY), y);
  EXPECT_EQ(out->getValue<double>(outZ), z);
}
TEST(TBKnowledgeBase, twoBots)
{
  auto leonardo = std::make_shared<ice::TBKnowledgeBase>("Leonardo");
  auto raphael = std::make_shared<ice::TBKnowledgeBase>("Raphael");

  leonardo->init();
  raphael->init();

  ASSERT_TRUE((leonardo->positionLandmarks ? true : false));
  ASSERT_TRUE((raphael->positionLandmarks ? true : false));

  leonardo->start();
  raphael->start();

  auto streamStore = leonardo->getKnowlegeBase()->streamStore;
  auto setStore = leonardo->getKnowlegeBase()->setStore;
  auto factory = leonardo->getGContainerFactory();

  // wait some time to enable the engines to find each other
  std::this_thread::sleep_for(std::chrono::milliseconds {8000});

  // test processing
  ASSERT_TRUE((leonardo->positionOwn ? true : false));
  ASSERT_TRUE((leonardo->positionRobots ? true : false));
  ASSERT_TRUE((leonardo->positionVictims ? true : false));
  ASSERT_TRUE((leonardo->positionLandmarks ? true : false));
  ASSERT_TRUE((leonardo->dangerZones ? true : false));
  ASSERT_TRUE((raphael->positionOwn ? true : false));
  ASSERT_TRUE((raphael->positionRobots ? true : false));
  ASSERT_TRUE((raphael->positionVictims ? true : false));
  ASSERT_TRUE((raphael->positionLandmarks ? true : false));
  ASSERT_TRUE((raphael->dangerZones ? true : false));


  std::cout << std::endl << "---------------------------------------------------------------" << std::endl;


  // get sets and streams
  //own pos
  auto specPosLeonardo = ice::InformationSpecification("http://vs.uni-kassel.de/TurtleBot#Leonardo",
                                               "http://vs.uni-kassel.de/TurtleBot#TurtleBot",
                                               "http://vs.uni-kassel.de/Ice#Position",
                                               "http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");
  auto posLeornardo = streamStore->getStream<ice::PositionOrientation3D>(&specPosLeonardo,
                                                                         "http://vs.uni-kassel.de/TurtleBot#LocalizeLeonardo",
                                                                         "http://vs.uni-kassel.de/TurtleBot#Leonardo");
  ASSERT_TRUE((posLeornardo ? true : false));

  auto specPosLeonardo2 = ice::InformationSpecification("http://vs.uni-kassel.de/TurtleBot#Leonardo",
                                               "http://vs.uni-kassel.de/TurtleBot#TurtleBot",
                                               "http://vs.uni-kassel.de/Ice#Position",
                                               "http://vs.uni-kassel.de/Ice#CoordinatePositionRep");
  auto posLeornardo2 = streamStore->getStream<ice::Pos3D>(&specPosLeonardo2);
  ASSERT_TRUE((posLeornardo2 ? true : false));

  auto specPosLeonardo3 = ice::InformationSpecification("http://vs.uni-kassel.de/TurtleBot#Leonardo",
                                               "http://vs.uni-kassel.de/TurtleBot#TurtleBot",
                                               "http://vs.uni-kassel.de/Ice#Position",
                                               "http://vs.uni-kassel.de/TurtleBot#RelativeToLandmark");
  auto posLeornardo3 = streamStore->getStream<ice::RTLandmark>(&specPosLeonardo3);
  ASSERT_TRUE((posLeornardo3 ? true : false));

  auto specPosRaphael = ice::InformationSpecification("http://vs.uni-kassel.de/TurtleBot#Raphael",
                                                      "http://vs.uni-kassel.de/TurtleBot#TurtleBot",
                                                      "http://vs.uni-kassel.de/Ice#Position",
                                                      "http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");
  auto posRaphael = raphael->getKnowlegeBase()->streamStore->getStream<ice::PositionOrientation3D>(&specPosRaphael);
  ASSERT_TRUE((posRaphael ? true : false));

  // landmarks
  auto landmarksSpec = ice::InformationSpecification("",
                                               "http://vs.uni-kassel.de/TurtleBot#Landmark",
                                               "http://vs.uni-kassel.de/Ice#Position",
                                               "http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");
  auto landmarks = setStore->getSet<ice::PositionOrientation3D>(&landmarksSpec,
                                                                         "http://vs.uni-kassel.de/TurtleBot#DetectLandmarks",
                                                                         "http://vs.uni-kassel.de/TurtleBot#Leonardo");
  ASSERT_TRUE((landmarks ? true : false));

  // victims
  auto victimsSpec = ice::InformationSpecification("",
                                               "http://vs.uni-kassel.de/TurtleBot#Victim",
                                               "http://vs.uni-kassel.de/Ice#Position",
                                               "http://vs.uni-kassel.de/Ice#CoordinatePositionRep");
  auto victims = setStore->getSet<ice::Pos3D>(&victimsSpec);
  ASSERT_TRUE((victims ? true : false));

  // contaminated areas
  auto radioactiveAreasSpec = ice::InformationSpecification("",
                                               "http://vs.uni-kassel.de/TurtleBot#RadioactiveArea",
                                               "http://vs.uni-kassel.de/TurtleBot#Area",
                                               "http://vs.uni-kassel.de/TurtleBot#ContaminatedArea");
  auto radioactiveAreas = raphael->getKnowlegeBase()->setStore->getSet<ice::GContainer>(&radioactiveAreasSpec);
  ASSERT_TRUE((radioactiveAreas ? true : false));

  // create landmarks
  auto landmark1 = factory->makeInstance<ice::PositionOrientation3D>("http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");
  auto landmark2 = factory->makeInstance<ice::PositionOrientation3D>("http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");

  landmark1->alpha = M_PI;
  landmark1->x = 100;
  landmark1->y = 100;
  landmark1->z = 0;

  landmark2->alpha = M_PI / 2.0;
  landmark2->x = 1000;
  landmark2->y = 1000;
  landmark2->z = 0;

  landmarks->add("Landmark1", landmark1);
  landmarks->add("Landmark2", landmark2);
  raphael->positionLandmarks->add("Landmark1", landmark1);
  raphael->positionLandmarks->add("Landmark2", landmark2);

  // generate position
  auto element = factory->makeInstance<ice::PositionOrientation3D>("http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");

  element->alpha = 0;
  element->x = 100;
  element->y = 200;
  element->z = 0;

  posLeornardo->add(element);

  auto element2 = factory->makeInstance<ice::PositionOrientation3D>("http://vs.uni-kassel.de/TurtleBot#PositionOrientation3D");

  element2->alpha = 0;
  element2->x = 200;
  element2->y = 300;
  element2->z = 0;

  posRaphael->add(element2);

  // generate victim
  auto victim = factory->makeInstance<ice::Pos3D>("http://vs.uni-kassel.de/Ice#CoordinatePositionRep");

  victim->x = 1500;
  victim->y = 1200;
  victim->z = 0;

  victims->add("victim1", victim);


  // generate radioactive area
  auto representation = raphael->getGContainerFactory()->getRepresentation("http://vs.uni-kassel.de/TurtleBot#ContaminatedArea");
  ASSERT_TRUE((representation ? true : false));

  auto pathX = representation->accessPath(POS_X);
  auto pathY = representation->accessPath(POS_Y);
  auto pathZ = representation->accessPath(POS_Z);
  auto pathLandmark = representation->accessPath(POS_LANDMARK);
  auto pathRadius = representation->accessPath(SUR_RADIUS);

  ASSERT_TRUE((pathX ? true : false));
  ASSERT_TRUE((pathY ? true : false));
  ASSERT_TRUE((pathZ ? true : false));
  ASSERT_TRUE((pathLandmark ? true : false));
  ASSERT_TRUE((pathRadius ? true : false));

  auto area = raphael->getGContainerFactory()->makeInstance(representation);

  double x = 10;
  double y = 15;
  double z = 20;
  double r = 25;
  std::string landmark = "Landmark1";

  area->set(pathX, &x);
  area->set(pathY, &y);
  area->set(pathZ, &z);
  area->set(pathLandmark, &landmark);
  area->set(pathRadius, &r);

  radioactiveAreas->add("area", area);

  // wait for processing
  std::this_thread::sleep_for(std::chrono::milliseconds {100});

  // check
  ASSERT_EQ(1, posLeornardo->getSize());
  ASSERT_EQ(1, posLeornardo2->getSize());
  ASSERT_EQ(1, posLeornardo3->getSize());
  ASSERT_EQ(1, leonardo->positionOwn->getSize());
  ASSERT_EQ(3, leonardo->positionLandmarks->getSize());
  ASSERT_EQ(2, leonardo->positionRobots->getSize());
  ASSERT_EQ(1, leonardo->positionVictims->getSize());
  ASSERT_EQ(1, leonardo->dangerZones->getSize());
  ASSERT_EQ(3, raphael->positionLandmarks->getSize());
  ASSERT_EQ(1, raphael->positionVictims->getSize());

  // check own pos
  auto pos = leonardo->positionOwn->getLast();

  ASSERT_TRUE((pos ? true : false));
  EXPECT_EQ(element->alpha, pos->getInformation()->alpha);
  EXPECT_EQ(element->x, pos->getInformation()->x);
  EXPECT_EQ(element->y, pos->getInformation()->y);
  EXPECT_EQ(element->z, pos->getInformation()->z);

  // check pos raphael
  auto pos2 = leonardo->positionRobots->get("http://vs.uni-kassel.de/TurtleBot#Raphael");

  ASSERT_TRUE((pos2 ? true : false));

  // check pos in set
  auto posSet = leonardo->positionRobots->get("http://vs.uni-kassel.de/TurtleBot#Leonardo");

  ASSERT_TRUE((posSet ? true : false));
  EXPECT_EQ("Landmark1", posSet->getInformation()->landmark);
  EXPECT_NEAR(0.0, posSet->getInformation()->x, 0.00000001);
  EXPECT_NEAR(-100.0, posSet->getInformation()->y, 0.00000001);
  EXPECT_NEAR(0.0, posSet->getInformation()->z, 0.00000001);

//  posSet = raphael->positionRobots->get("http://vs.uni-kassel.de/TurtleBot#Leonardo");
//
//  ASSERT_TRUE((posSet ? true : false));
//  EXPECT_EQ("Landmark1", posSet->getInformation()->landmark);
//  EXPECT_NEAR(0.0, posSet->getInformation()->x, 0.00000001);
//  EXPECT_NEAR(-100.0, posSet->getInformation()->y, 0.00000001);
//  EXPECT_NEAR(0.0, posSet->getInformation()->z, 0.00000001);

  // check victim
  auto posVictim = leonardo->positionVictims->get("victim1");

  ASSERT_TRUE((posVictim ? true : false));
  EXPECT_EQ("Landmark2", posVictim->getInformation()->landmark);
  EXPECT_NEAR(-200.0, posVictim->getInformation()->x, 0.00000001);
  EXPECT_NEAR(500.0, posVictim->getInformation()->y, 0.00000001);
  EXPECT_NEAR(0.0, posVictim->getInformation()->z, 0.00000001);

  posVictim = raphael->positionVictims->get("victim1");

  ASSERT_TRUE((posVictim ? true : false));
  EXPECT_EQ("Landmark2", posVictim->getInformation()->landmark);
  EXPECT_NEAR(-200.0, posVictim->getInformation()->x, 0.00000001);
  EXPECT_NEAR(500.0, posVictim->getInformation()->y, 0.00000001);
  EXPECT_NEAR(0.0, posVictim->getInformation()->z, 0.00000001);

  auto dangerZone = leonardo->dangerZones->get("area");

  ASSERT_TRUE((dangerZone ? true : false));
  EXPECT_EQ("Landmark1", dangerZone->getInformation()->getValue<std::string>(pathLandmark));
  EXPECT_EQ(x, dangerZone->getInformation()->getValue<double>(pathX));
  EXPECT_EQ(y, dangerZone->getInformation()->getValue<double>(pathY));
  EXPECT_EQ(z, dangerZone->getInformation()->getValue<double>(pathZ));
  EXPECT_EQ(r, dangerZone->getInformation()->getValue<double>(pathRadius));

  leonardo->cleanUp();
  leonardo.reset();
  raphael->cleanUp();
  raphael.reset();
}
Esempio n. 3
0
TEST(ASPRepComp, ontology2)
{
  std::string path = ros::package::getPath("ice");
  bool result;

  auto oi = std::make_shared<ice::OntologyInterface>(path + "/java/lib/");
  oi->addIRIMapper(path + "/ontology/");

  ASSERT_FALSE(oi->errorOccurred());

  result = oi->addOntologyIRI("http://vs.uni-kassel.de/IceTest");

  ASSERT_FALSE(oi->errorOccurred());
  ASSERT_TRUE(result);

  result = oi->loadOntologies();

  ASSERT_FALSE(oi->errorOccurred());
  ASSERT_TRUE(result);

  result = oi->isConsistent();

  ASSERT_FALSE(oi->errorOccurred());
  ASSERT_TRUE(result);

  std::shared_ptr<ice::GContainerFactory> factory = std::make_shared<ice::GContainerFactory>();
  factory->setOntologyInterface(oi);
  factory->init();

  ice::ASPTransformationGeneration asp;

  asp.setOntology(oi);
  asp.setGContainerFactory(factory);

  asp.extractTransformations();

  // Test transformation
  std::string name = "autoTrans_o0_TestScope1_o0_TestTransformation1_o0_TestTransformation2";
  auto trans = factory->getTransformationByName(name);

  ASSERT_TRUE(trans != false);

  auto repIn = factory->getRepresentation("o0_TestTransformation1");
  auto repOut = factory->getRepresentation("o0_TestTransformation2");

  ASSERT_TRUE(repIn != false);
  ASSERT_TRUE(repOut != false);

  auto inO = repIn->accessPath( {"o2_Orientation"});
  auto inP = repIn->accessPath( {"o2_Position"});
  auto inX = repIn->accessPath( {"o2_Position", "o2_XCoordinate"});
  auto inY = repIn->accessPath( {"o2_Position", "o2_YCoordinate"});
  auto inZ = repIn->accessPath( {"o2_Position", "o2_ZCoordinate"});

  auto inOa = repIn->accessPath( {"o2_Orientation", "o2_Alpha"});
  auto inOb = repIn->accessPath( {"o2_Orientation", "o2_Beta"});
  auto inOc = repIn->accessPath( {"o2_Orientation", "o2_Gamma"});

  ASSERT_TRUE(inO != nullptr);
  ASSERT_TRUE(inP != nullptr);
  ASSERT_TRUE(inX != nullptr);
  ASSERT_TRUE(inY != nullptr);
  ASSERT_TRUE(inZ != nullptr);

  ASSERT_TRUE(inOa != nullptr);
  ASSERT_TRUE(inOb != nullptr);
  ASSERT_TRUE(inOc != nullptr);

  auto outO = repIn->accessPath( {"o2_Orientation"});
  auto outP = repIn->accessPath( {"o2_Position"});
  auto outX = repIn->accessPath( {"o2_Position", "o2_XCoordinate"});
  auto outY = repIn->accessPath( {"o2_Position", "o2_YCoordinate"});
  auto outZ = repIn->accessPath( {"o2_Position", "o2_ZCoordinate"});

  auto outOa = repIn->accessPath( {"o2_Orientation", "o2_Alpha"});
  auto outOb = repIn->accessPath( {"o2_Orientation", "o2_Beta"});
  auto outOc = repIn->accessPath( {"o2_Orientation", "o2_Gamma"});

  ASSERT_TRUE(outO != nullptr);
  ASSERT_TRUE(outP != nullptr);
  ASSERT_TRUE(outX != nullptr);
  ASSERT_TRUE(outY != nullptr);
  ASSERT_TRUE(outZ != nullptr);

  ASSERT_TRUE(outOa != nullptr);
  ASSERT_TRUE(outOb != nullptr);
  ASSERT_TRUE(outOc != nullptr);

  auto in = factory->makeInstance(repIn);

  double x = 4.44;
  double y = 5.55;
  double z = 6.66;

  double a = 14.44;
  double b = 15.55;
  double c = 16.66;

  in->set(inX, &x);
  in->set(inY, &y);
  in->set(inZ, &z);

  in->set(inOa, &a);
  in->set(inOb, &b);
  in->set(inOc, &c);

  auto out = trans->transform(&in);

  EXPECT_EQ(out->getValue<double>(outX), x);
  EXPECT_EQ(out->getValue<double>(outY), y);
  EXPECT_EQ(out->getValue<double>(outZ), z);

  EXPECT_EQ(out->getValue<double>(outOa), a);
  EXPECT_EQ(out->getValue<double>(outOb), b);
  EXPECT_EQ(out->getValue<double>(outOc), c);

  auto aspStr = trans->getASPRepreentation("system");
  for (auto s : *aspStr)
  {
    if (s == "iro(system,autoTrans_o0_TestScope1_o0_TestTransformation1_o0_TestTransformation2,any,none).")
    {
      // fine
    }
    else if (s
        == "output(system,autoTrans_o0_TestScope1_o0_TestTransformation1_o0_TestTransformation2,o0_TestScope1,o0_TestTransformation1,none).")
    {
      // fine
    }
    else if (s
        == "input(system,autoTrans_o0_TestScope1_o0_TestTransformation1_o0_TestTransformation2,o0_TestScope1,o0_TestTransformation1,none,1,1) :- iro(system,autoTrans_o0_TestScope1_o0_TestTransformation1_o0_TestTransformation2,any,none).")
    {
      // fine
    }
    else
    {
      ASSERT_ANY_THROW("Unknown string " + s);
    }
  }

}