Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
doc:writing_an_interface_to_your_perception_system [2014/11/27 12:33] – [Publisher] admin | doc:writing_an_interface_to_your_perception_system [2014/11/27 14:54] – [Perception service] admin | ||
---|---|---|---|
Line 15: | Line 15: | ||
The knowrob_perception tutorial is part of the knowrob_tutorials repository. You need to check it out into your catkin workspace and compile it using catkin_make: | The knowrob_perception tutorial is part of the knowrob_tutorials repository. You need to check it out into your catkin workspace and compile it using catkin_make: | ||
- | < | + | < |
cd / | cd / | ||
git clone https:// | git clone https:// | ||
Line 22: | Line 22: | ||
</ | </ | ||
+ | Since a large part of the tutorial is written in Java, it is recommended to set up an Eclipse project and to inspect and edit the Java files from there. You can generate the Eclipse project files using the following command and then only need to create a new "Java Project" | ||
+ | <code bash> | ||
+ | ./gradlew eclipse | ||
+ | </ | ||
====== Interfacing topic-based perception systems ====== | ====== Interfacing topic-based perception systems ====== | ||
Line 58: | Line 62: | ||
===== Subscriber ===== | ===== Subscriber ===== | ||
- | The counterpart on the client side that consumes the object detections is implemented in the file '' | + | The counterpart on the client side that consumes the object detections is implemented in the file '' |
- | The following code snippet is the main part of the '' | + | The following code snippet is the main part of the '' |
- | < | + | < |
- | while (n.isValid()) { | + | node.executeCancellableLoop(new CancellableLoop() { |
+ | |||
+ | @Override | ||
+ | protected void loop() throws InterruptedException | ||
- | obj = callback.pop(); | + | |
- | Matrix4d p = quaternionToMatrix(obj.pose.pose); | + | Matrix4d p = quaternionToMatrix(obj.getPose().getPose()); |
String q = " | String q = " | ||
- | | + | |
- | + p.m00 + "," | + | + p.m00 + "," |
- | + p.m10 + "," | + | + p.m10 + "," |
- | + p.m20 + "," | + | + p.m20 + "," |
- | + p.m30 + "," | + | + p.m30 + "," |
- | "], [' | + | "], [' |
PrologInterface.executeQuery(q); | PrologInterface.executeQuery(q); | ||
- | n.spinOnce(); | ||
} | } | ||
+ | }); | ||
</ | </ | ||
+ | This predicate from the knowrob_perception package is defined as below. It creates a new object instance for the given object type ('' | ||
- | This predicate, defined in the knowrob_perception package, is defined as below. It creates a new object instance for the given object type ('' | + | < |
- | + | ||
- | < | + | |
create_object_perception(ObjClass, | create_object_perception(ObjClass, | ||
rdf_instance_from_class(ObjClass, | rdf_instance_from_class(ObjClass, | ||
Line 96: | Line 102: | ||
Whenever the subscriber is started, it creates the KnowRob-internal representations for all object detections that are received via the topic. It can be run from Prolog via the [[http:// | Whenever the subscriber is started, it creates the KnowRob-internal representations for all object detections that are received via the topic. It can be run from Prolog via the [[http:// | ||
- | < | + | < |
obj_detections_listener(Listener) :- | obj_detections_listener(Listener) :- | ||
- | jpl_new(' | + | jpl_new(' |
- | jpl_call(Listener, | + | jpl_list_to_array(['org.knowrob.tutorials.DummySubscriber' |
+ | jpl_call(' | ||
</ | </ | ||
- | If the dummy publisher | + | To start a rosjava node from KnowRob, you first need to instantiate the class containing the node definition, create an array with the fully-qualified class name, and pass it to the '' |
- | < | + | < |
?- obj_detections_listener(L). | ?- obj_detections_listener(L). | ||
- | L = @'J#00000000000173056232'. | + | L = @'J#00000000000034668496' |
- | Attaching 0x8afd1010 | + | % ... several rosjava INFO messages ... |
- | <wait for a few seconds...> | + | % wait for a few seconds... |
?- owl_individual_of(A, | ?- owl_individual_of(A, | ||
- | A = ' | + | A = knowrob:' |
- | A = ' | + | A = knowrob:' |
- | A = 'http:// | + | A = knowrob:' |
+ | A = knowrob:' | ||
- | ?- current_object_pose(' | + | ?- current_object_pose(knowrob:' |
P = [1.0, | P = [1.0, | ||
</ | </ | ||
Line 124: | Line 132: | ||
===== Perception service ===== | ===== Perception service ===== | ||
- | The dummy perception service is very similar to the dummy publisher. Whenever a request for an object detection is received, it responds with a simulated detection of a random object type at a random pose. In real scenarios, the request will probably not be empty, but specify properties of the perception method to be used. The code of the dummy service can be found in the file src/ | + | The dummy perception service is very similar to the dummy publisher. Whenever a request for an object detection is received, it responds with a simulated detection of a random object type at a random pose. In the example, the ' |
< | < | ||
rosrun knowrob_perception_tutorial dummy_service | rosrun knowrob_perception_tutorial dummy_service |