Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
interact_with_knowrob_via_ros [2013/01/09 21:13] – [Client libraries] tenorth | interact_with_knowrob_via_ros [2013/04/22 08:36] – admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Use KnowRob from your program ====== | + | #REDIRECT doc:interact_with_knowrob_via_ros |
- | + | ||
- | The interactive Prolog shell that [[http:// | + | |
- | + | ||
- | You can run the // | + | |
- | < | + | |
- | rosrun json_prolog json_prolog ias_semantic_map | + | |
- | </ | + | |
- | + | ||
- | ===== Client libraries ===== | + | |
- | The communication with the // | + | |
- | + | ||
- | + | ||
- | ==== Python client ==== | + | |
- | + | ||
- | <code python> | + | |
- | + | ||
- | #!/ | + | |
- | + | ||
- | import roslib; roslib.load_manifest(' | + | |
- | + | ||
- | import rospy | + | |
- | import json_prolog | + | |
- | + | ||
- | if __name__ == ' | + | |
- | rospy.init_node(' | + | |
- | prolog = json_prolog.Prolog() | + | |
- | query = prolog.query(" | + | |
- | for solution in query.solutions(): | + | |
- | print 'Found solution. A = %s, B = %s' % (solution[' | + | |
- | query.finish() | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | ==== C++ client ==== | + | |
- | + | ||
- | <code c++> | + | |
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | using namespace std; | + | |
- | using namespace json_prolog; | + | |
- | + | ||
- | int main(int argc, char *argv[]) | + | |
- | { | + | |
- | ros:: | + | |
- | + | ||
- | Prolog pl; | + | |
- | + | ||
- | PrologQueryProxy bdgs = pl.query(" | + | |
- | + | ||
- | for(PrologQueryProxy:: | + | |
- | it != bdgs.end(); it++) | + | |
- | { | + | |
- | PrologBindings bdg = *it; | + | |
- | cout << "Found solution: " << (bool)(it == bdgs.end()) << endl; | + | |
- | cout << "A = "<< | + | |
- | cout << "B = " << bdg[" | + | |
- | cout << "C = " << bdg[" | + | |
- | } | + | |
- | return 0; | + | |
- | } | + | |
- | + | ||
- | </ | + |