Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:interact_with_knowrob_via_ros [2014/08/11 15:57] – [Use KnowRob from your program] admindoc:interact_with_knowrob_via_ros [2014/08/12 15:23] (current) – [Java client] admin
Line 5: Line 5:
 ^ This page describes the 'catkinized' version of KnowRob that has been converted to the [[http://wiki.ros.org/catkin/|catkin buildsystem]] and the new [[http://wiki.ros.org/rosjava|rosjava]]. The documentation for older versions can be found [[/doc/interact_with_knowrob_via_ros?rev=1401968328|here]].^ ^ This page describes the 'catkinized' version of KnowRob that has been converted to the [[http://wiki.ros.org/catkin/|catkin buildsystem]] and the new [[http://wiki.ros.org/rosjava|rosjava]]. The documentation for older versions can be found [[/doc/interact_with_knowrob_via_ros?rev=1401968328|here]].^
 \\ \\
- +The interactive Prolog shell that [[http://ros.org/wiki/rosprolog|rosprolog]] provides is good for exploring KnowRob, visualizing knowledge, developing new functions and debugging Prolog code. However, if you would like to use KnowRob in your robot's control program, you need a way to send queries from your program. This functionality is provided by the [[http://ros.org/wiki/json_prolog|json_prolog]] package. It provides a service that exposes a Prolog shell via ROS. You can run the //json_prolog// service using a launch file such as the following (which can be found in //knowrob_map_data/launch/ccrl2_semantic_map.launch//).
-The interactive Prolog shell that [[http://ros.org/wiki/rosprolog|rosprolog]] provides is good for exploring KnowRob, visualizing knowledge, developing new functions and debugging Prolog code. However, if you would like to use KnowRob in your robot's control program, you need a way to send queries from your program. This functionality is provided by the [[http://ros.org/wiki/json_prolog|json_prolog]] package. It provides a service that exposes a Prolog shell via ROS. You can run the //json_prolog// service using a launch file such as the following. The //json_prolog_node// reads two optional ROS parameters for the initial package to be loaded (that you also give as argument when starting //rosprolog//) and a command to be executed at startup, for example for parsing an OWL file.+
 <code xml> <code xml>
 <launch> <launch>
Line 15: Line 14:
 </launch> </launch>
 </code> </code>
 +The //json_prolog_node// reads two optional ROS parameters for the initial package to be loaded (that you also give as argument when starting //rosprolog//) and a command to be executed at startup, for example for parsing an OWL file.
 ===== Client libraries ===== ===== Client libraries =====
 The communication with the //json_prolog// service uses a [[http://json.org/|JSON-encoded]] format for representing the Prolog terms that form the query. While you can construct these terms manually and call the service directly, it is usally much easier to use one of the provided client libraries. There are libraries for Python, C++, Java and Lisp. Example clients are available in the //json_prolog/examples// folder; below is the code for sending KnowRob queries from Python via //json_prolog//. The communication with the //json_prolog// service uses a [[http://json.org/|JSON-encoded]] format for representing the Prolog terms that form the query. While you can construct these terms manually and call the service directly, it is usally much easier to use one of the provided client libraries. There are libraries for Python, C++, Java and Lisp. Example clients are available in the //json_prolog/examples// folder; below is the code for sending KnowRob queries from Python via //json_prolog//.
Line 78: Line 77:
  
 <code java>  <code java> 
-import edu.tum.cs.ias.knowrob.json_prolog.Prolog; +package org.knowrob.json_prolog;
-import edu.tum.cs.ias.knowrob.json_prolog.PrologBindings; +
-import edu.tum.cs.ias.knowrob.json_prolog.PrologQueryProxy;+
  
 +import org.knowrob.json_prolog.Prolog;
 +import org.knowrob.json_prolog.PrologBindings;
 +import org.knowrob.json_prolog.PrologQueryProxy;
 +import org.knowrob.utils.ros.RosUtilities;
  
-public class JSONPrologTestClient { 
  
- public static void main(String args[]) {+public class JSONPrologTestClient {
  
- Prolog pl = new Prolog(); +    public static void main(String args[]) {
- PrologQueryProxy bdgs = pl.query("member(A, [1, 2, 3, 4]), B = ['x', A], C = foo(bar, A, B)");+
  
 +        Prolog pl = new Prolog();
 +        RosUtilities.runRosjavaNode(pl, new String[]{"org.knowrob.json_prolog.Prolog"});
      
- for(PrologBindings bdg : bdgs) {+        PrologQueryProxy bdgs = pl.query("member(A, [1, 2, 3, 4]), B = ['x', A], C = foo(bar, A, B)");
  
-      System.out.println("Found solution: "); +        for(PrologBindings bdg : bdgs) { 
-      System.out.println("A = " + bdg.getBdgs_().get("A") ); +            System.out.println("Found solution: "); 
-      System.out.println("B = " + bdg.getBdgs_().get("B") ); +            System.out.println("A = " + bdg.getBdgs_().get("A") ); 
-      System.out.println("C = " + bdg.getBdgs_().get("C") ); +            System.out.println("B = " + bdg.getBdgs_().get("B") ); 
-    }+            System.out.println("C = " + bdg.getBdgs_().get("C") ); 
 +        }
   }   }
 } }
 </code> </code>