We will first write a program that will create an ontology for Anne and an ontology for Sally.
Create a main file and paste the following inside it:
#include<iostream>
#include<string>
#include"ontologenius/OntologiesManipulator.h"
intmain(intargc, char**argv)
{
ros::init(argc, argv, "multiple_ontologies");
onto::OntologiesManipulatoronto;
onto.waitInit();
onto.add("sally");
onto.add("anne");
onto["sally"]->close();
onto["anne"]->close();
std::vector<std::string> result = onto["sally"]->individuals.getOn("ball_1", "isIn");
std::cout << "for sally, ball_1 is in:" << std::endl;
for(auto&in : result)
std::cout << "- " << in << std::endl;
result = onto["anne"]->individuals.getOn("ball_1", "isIn");
std::cout << "for anne, ball_1 is in:" << std::endl;
for(auto&in : result)
std::cout << "- " << in << std::endl;
return0;
}
#include<iostream>
#include<string>
#include"ontologenius/OntologiesManipulator.h"
intmain(intargc, char**argv)
{
rclcpp::init(argc, argv);
onto::OntologiesManipulatoronto;
onto.waitInit();
onto.add("sally");
onto.add("anne");
onto["sally"]->close();
onto["anne"]->close();
std::vector<std::string> result = onto["sally"]->individuals.getOn("ball_1", "isIn");
std::cout << "for sally, ball_1 is in:" << std::endl;
for(auto&in : result)
std::cout << "- " << in << std::endl;
result = onto["anne"]->individuals.getOn("ball_1", "isIn");
std::cout << "for anne, ball_1 is in:" << std::endl;
for(auto&in : result)
std::cout << "- " << in << std::endl;
return0;
}
Now, let's break the code down.
#include"ontologenius/OntologiesManipulator.h"
In previous tutorials, we included the OntologyManipulator header. This time, we need to handle several
ontologies and that's why we include the OntologiesManipulator header this time. This object allows us to
dynamically create an OntologyManipulator per agent.
onto::OntologiesManipulatoronto;
onto.waitInit();
We start by creating an OntologiesManipulator. At the difference of the OntologyManipulator, this one needs a pointer to our NodeHandle.
In addition, we simply call waitInit to make sure that all ROS services have been connected before starting.
onto.add("sally");
onto.add("anne");
We create here two ontologies, one for Sally and one for Anne. For the rest of the program,
we will use these identifiers to get the specific ontology we want to work on.
onto["sally"]->close();
onto["anne"]->close();
As usual, we must close the ontology before exploring it. Here we use the [] operator that returns an OntologyManipulator
object for a specific instance. If you prefer, you can also use the get function.
std::vector<std::string> result = onto["sally"]->individuals.getOn("ball_1", "isIn");
From there, you can use Ontologenius as usual.
Compile this and start the program. You should have the result that the ball is in the first container for Sally and Anne.