Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
doc:writing_an_interface_to_your_perception_system [2014/11/27 14:54] – [Perception service] admindoc:writing_an_interface_to_your_perception_system [2014/11/27 15:24] (current) – [KnowRob integration] admin
Line 145: Line 145:
 ===== KnowRob integration ===== ===== KnowRob integration =====
  
-While the service client is much simpler than the topic listener, the integration with KnowRob is a bit more complex. The reason is that the service call needs to be actively triggered, while the topic listener just runs in the background in a separate thread. This means that the inference needs to be aware of the possibility of acquiring information about object detections by calling this service. Such functionality can be realized using [[doc/defining_computables|computables]] that describe for an OWL class or property how individuals of this class or values of this property can be computed. To better understand the following steps, it is recommended to have completed the [[doc/defining_computables|tutorial on defining computables]]. +While the Java side of the service client is much simpler than the topic listener, the integration with KnowRob is a bit more complex. The reason is that the service call needs to be actively triggered, while the topic listener just runs in the background in a separate thread. This means that the inference needs to be aware of the possibility of acquiring information about object detections by calling this service. Such functionality can be realized using [[doc/defining_computables|computables]] that describe for an OWL class or property how individuals of this class or values of this property can be computed. To better understand the following steps, it is recommended to have completed the [[doc/defining_computables|tutorial on defining computables]]. 
  
 In a first step, we need to implement a Prolog predicate that performs the service call, processes the returned information, adds it to the knowledge base, and returns the identifiers of the detected object instances. This predicate is implemented in prolog/perception_tutorial.pl. In contrast to topic-based example above, which performed most processing in Java, this example shows how more of the processing can be done in Prolog: In a first step, we need to implement a Prolog predicate that performs the service call, processes the returned information, adds it to the knowledge base, and returns the identifiers of the detected object instances. This predicate is implemented in prolog/perception_tutorial.pl. In contrast to topic-based example above, which performed most processing in Java, this example shows how more of the processing can be done in Prolog:
  
-<code>+<code prolog>
 comp_object_detection(ObjInst, _ObjClass) :- comp_object_detection(ObjInst, _ObjClass) :-
  
   % Call the DetectObject service for retrieving a new object detection.   % Call the DetectObject service for retrieving a new object detection.
   % The method returns a reference to the Java ObjectDetection message object   % The method returns a reference to the Java ObjectDetection message object
-  jpl_call('edu.tum.cs.ias.knowrob.tutorial.DummyClient', 'callObjDetectionService', [], ObjectDetection),+  jpl_new('org.knowrob.tutorials.DummyClient', [], Client), 
 +  jpl_list_to_array(['org.knowrob.tutorials.DummyClient']Arr), 
 +  jpl_call('org.knowrob.utils.ros.RosUtilities', runRosjavaNode, [Client, Arr], _),
  
- +  jpl_call(Client, 'callObjDetectionService', [], ObjectDetection),
-  % Read information from the ObjectDetection object+
  
   % Read type -> simple string; combine with KnowRob namespace   % Read type -> simple string; combine with KnowRob namespace
-  jpl_get(ObjectDetection, 'type', T), +  jpl_call(ObjectDetection, 'getType', [], T), 
-  atom_concat('http://ias.cs.tum.edu/kb/knowrob.owl#', T, Type), +  atom_concat('http://knowrob.org/kb/knowrob.owl#', T, Type),
- +
- +
-  % Read pose -> convert from quaternion to pose list +
-  jpl_get(ObjectDetection, 'pose', PoseStamped), +
-  jpl_get(PoseStamped, 'pose', PoseQuat),+
  
-  jpl_call('edu.tum.cs.ias.knowrob.tutorial.DummyClient', 'quaternionToMatrix', [PoseQuat], PoseMatrix),+  % Convert the pose into a rotation matrix 
 +  jpl_call(ObjectDetection, 'getPose', [], PoseMatrix),
   knowrob_coordinates:matrix4d_to_list(PoseMatrix,PoseList),   knowrob_coordinates:matrix4d_to_list(PoseMatrix,PoseList),
  
Line 178: Line 175:
 </code> </code>
  
-The predicate first calls the static ''callObjDetectionService'' method in the ''DummyClient'' class and receives an ''ObjectDetection'' object as result. It then reads its member variables (type, pose) and converts them from a quaternion into a pose matrix and into a Prolog list as row-based matrix representation. In the end, it calls the same ''create_object_perception'' predicate that was also used in the previous example.+The predicate first calls the static ''callObjDetectionService'' method in the ''DummyClient'' class and receives an ''ObjectDetection'' object as result. It then reads its member variables (type, pose) and converts them from a quaternion into a pose matrix and into a Prolog list as row-based matrix representation. In the end, it calls the same ''create_object_perception'' predicate that was also used in the previous example. This predicate can be used to manually query the perception service from Prolog (assuming the perception service is running in another terminal):
  
-This predicate can be used to manually query the perception service from Prolog (assuming the perception service is running in another terminal): +<code prolog>
-<code>+
 rosrun rosprolog rosprolog knowrob_perception_tutorial rosrun rosprolog rosprolog knowrob_perception_tutorial
 ?- comp_object_detection(Obj, _). ?- comp_object_detection(Obj, _).
Line 187: Line 183:
 </code> </code>
  
-Such a manual query requires that the user is aware of the existence of this service. It also requires adaptation of the query whenever the context changes, e.g. when different or multiple recognition systems are used. We can avoid these problems by wrapping the predicate into a computable; with this definition, the predicate will automatically be called whenever the user asks for an object pose and when the service interface is available. The following OWL code defines a computable Prolog class for the example predicate:+Such a manual query however requires the user to know of the existence of this service. It also requires adaptation of the query whenever the context changes, e.g. when different or multiple recognition systems are used. We can avoid these problems by wrapping the predicate into a //computable//. With this definition, the predicate will automatically be called whenever the user asks for an object pose as long as the service interface is available. The following OWL code defines a computable Prolog class for the example predicate:
  
-<code>+<code xml>
 <computable:PrologClass rdf:about="#computeObjectDetections"> <computable:PrologClass rdf:about="#computeObjectDetections">
     <computable:command rdf:datatype="&xsd;string">comp_object_detection</computable:command>     <computable:command rdf:datatype="&xsd;string">comp_object_detection</computable:command>
Line 198: Line 194:
 </code> </code>
  
-Instead of calling the service directly, we can now query for object poses and obtain -- in addition to already known poses from e.g. a semantic map -- the poses generated by our service:+Instead of calling the service directly, we can now query for object poses and obtain the poses generated by our service in addition to other object poses that have already been in the knowledge base, e.g. in a semantic map:
 <code> <code>
 ?- rdfs_instance_of(A, knowrob:'HumanScaleObject'). ?- rdfs_instance_of(A, knowrob:'HumanScaleObject').
-A = 'http://ias.cs.tum.edu/kb/knowrob.owl#TableKnife_vUXiHMJy'.+A = knowrob:'TableKnife_vUXiHMJy'.
 </code> </code>