This is an old revision of the document!


KnowRob basics

Installing and launching the system

If you would just like to try KnowRob, you can use the binary packages, but if you would like to experiment more and adapt the packages, you should install the source distribution. Please refer to the installation guide for instructions.

You can now launch the system using the rosprolog script which takes the name of the package to be launched as parameter. When calling a package with rosprolog, the init.pl file is loaded, and all init.pl of referenced packages as well. That procedure ensures that all packages are initialized when being loaded. For more information on how to load your own packages, have a look at the rosprolog documentation or into one of the init.pl files.

 rosrun rosprolog rosprolog mod_vis

You should now see the Prolog console.

Querying the KnowRob ontology

The KnowRob taxonomy is loaded by default since mod_vis, the module we loaded, depends on ias_knowledge_base which contains the taxonomy. So you can start exploring the available classes, e.g. with

 ?- owl_subclass_of(A, knowrob:'FoodOrDrink'). <ENTER>
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#FoodOrDrink' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Drink' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Coffee-Beverage' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#InfusionDrink' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Tea-Beverage' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Tea-Iced' 
 Yes.

Some notes on the query syntax: Predicates in a query can be linked with a comma, denoting the logical AND, or a semicolon for the logical OR. Each query is finished with a full stop. You can step through the results with the semicolon or just hit <ENTER> again. For more information on query predicates, have a look at the Semweb library documentation.

Before continuing with the tutorial, try to get familiar with the taxonomy and its main classes and properties, either by exploring the hierarchy from Prolog or, more convenient, by loading knowrob.owl into the Protege editor.

Loading and querying environment information

So far, we only performed reasoning on the class level. For robotic applications, it is also important to reason about instances of these classes, for example observed objects or actions.

An example set of instances are the semantic maps, contained as OWL file in the ias_semantic_map package. We can simply load them with the command

 register_ros_package(ias_semantic_map).

The package ias_semantic_map loads the file ccrl2_semantic_map.owl automatically. If you would like to load your own OWL files, you can use the following command:

 owl_parser:owl_parse('../owl/my_semantic_map.owl', false, false, true).

Instances are queried using the rdf_has(S,P,O) or owl_has(S,P,O) predicates, which retrieve all triples with matching Subject, Predicate, or Object from the knowledge base. The following query, for example, asks for all objects of type knowrob:'Drawer'.

 ?- owl_has(A, rdf:type, knowrob:'Drawer').
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Drawer1' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Drawer103' ;
 A = 'http://ias.cs.tum.edu/kb/knowrob.owl#Drawer109' ;
 true.

For getting an overview of the information that is available about one object instance, we can query for all triples where the respective instance fills the Subject slot:

 ?- owl_has('http://ias.cs.tum.edu/kb/knowrob.owl#Drawer1', P, O).
 P = 'http://ias.cs.tum.edu/kb/knowrob.owl#describedInMap',
 O = 'http://ias.cs.tum.edu/kb/ccrl2_semantic_map.owl#SemanticEnvironmentMap0' ;
 P = 'http://ias.cs.tum.edu/kb/knowrob.owl#properPhysicalParts',
 O = 'http://ias.cs.tum.edu/kb/knowrob.owl#Door4' ;
 P = 'http://ias.cs.tum.edu/kb/knowrob.owl#properPhysicalParts',
 O = 'http://ias.cs.tum.edu/kb/knowrob.owl#Handle127' ;
 P = 'http://ias.cs.tum.edu/kb/knowrob.owl#depthOfObject',
 O = literal(type('http://www.w3.org/2001/XMLSchema#float', '0.574538')) ;
 P = 'http://ias.cs.tum.edu/kb/knowrob.owl#heightOfObject',
 O = literal(type('http://www.w3.org/2001/XMLSchema#float', '0.338121')) ;
 P = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
 O = 'http://www.w3.org/2002/07/owl#NamedIndividual' ;
 P = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
 O = 'http://ias.cs.tum.edu/kb/knowrob.owl#Drawer' ;
 P = 'http://ias.cs.tum.edu/kb/knowrob.owl#widthOfObject',
 O = literal(type('http://www.w3.org/2001/XMLSchema#float', '0.58045006')) ;
 false.

Visualizing objects

A visualization often helps to find problems with information in the knowledge base, and is also useful to demonstrate what the robot knows about the world. Therefore, we created a visualization canvas that accepts object instances and allows to visualize them, highlight some objects, and retrieve information by clicking on the items.

For launching the launch visualization module, type the following into the Prolog console:

 visualisation_canvas(C).

By default, the system loads the kitchen background. We will now clear the canvas, manually select some objects from the map, and push them to the visualization.

 clear_canvas($C). 

Note: $C refers to the last binding of the top-level variable C, in this case the handle identifying the canvas. To select and visualize object instances, we call

 owl_has(A, rdf:type, knowrob:'Drawer'), add_object(A, $C).

When skipping through the results with the semicolon ;, you'll see the cupboards appear on the canvas. You will notice that they do not have any handles - when pushing just the object itself, the canvas does not draw its children. You can, however, tell it to do so by using the add_object_with_children predicate:

 owl_has(A, rdf:type, knowrob:'Drawer'), add_object_with_children(A, $C).