Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorial:knowrob_basics [2012/12/01 10:11] – created tenorthtutorial:knowrob_basics [2014/06/05 11:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
-===== Getting started ===== +#REDIRECT doc:knowrob_basics
- +
-For effectively using the KnowRob system, some basic knowledge about its main techniques, OWL and Prolog, is helpful. It becomes crucial when extending and adapting the system. +
- +
-=== Learning OWL === +
-  * Download the Protege OWL editor (version 4.1) which makes exploring and editing OWL files much easier: http://protege.stanford.edu/download/protege/4.1/installanywhere/ +
- +
-  * Have a look at the documentation (http://protegewiki.stanford.edu/index.php/Protege4GettingStarted) and the tutorial (http://owl.cs.manchester.ac.uk/tutorials/protegeowltutorial/resources/ProtegeOWLTutorialP4_v1_2.pdf). Especially the latter one is not only a good introduction to the Protege program, but to modeling with OWL in general. +
- +
-  * Also look at the code you just created in Protege with a text editor to see how the relations you created using the GUI are represented in OWL. +
- +
-=== Learning PROLOG === +
-In the beginning, you probably won't need very sophisticated Prolog skills, but it will be good to have a rough understanding of how a Prolog program looks like and what the basic concepts are. +
- +
-It's a good start to have a look at the tutorials at http://www.learnprolognow.org/ - for instance until lesson 6. +
- +
-===== Setting up KnowRob ===== +
- +
-For experimenting with KnowRob, you should install the source distribution from code.in.tum.de. Please refer to http://www.ros.org/wiki/knowrob for installation instructions. After the installation, install system dependencies and build the KnowRob stack: +
- +
- rosdep satisfy knowrob +
- sudo apt-get install [[...]] only if something is missing +
- rosmake knowrob +
- +
-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 [[http://www.ros.org/wiki/rosprolog|rosprolog]] documentation or in 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  [[http://www.swi-prolog.org/pldoc/package/semweb.html|Semweb library documentation]]. +
- +
-Before continuing with the tutorial, try to get familiar with the taxonomy and its main [[KnowRob_Taxonomy|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 [[http://www.ros.org/wiki/ias_semantic_map|ias_semantic_map]] package. We can simply load them with the command +
- register_ros_package(ias_semantic_map). +
- +
-The package [[http://www.ros.org/wiki/ias_semantic_map|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 [[http://www.ros.org/wiki/mod_vis|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 +
- 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). +
- +
-The small window that has opened in addition to the visualization canvas contains some control routines that mainly interact with the right section of the canvas, which displays action sequences. In addition, it can show information about any kind of instance in the system, for instance the objects we just added to the canvas. One way of displaying this information is simply by clicking on the object, but you can also update the content from Prolog: +
- rdf_has(A, rdf:type, knowrob:'Drawer'), display_information_for(A, $C).+