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:logging:tutorials-cpp [2014/09/19 07:33] – [Using the client library] winklerdoc:logging:tutorials-cpp [2014/09/19 15:19] (current) – [Non-Default Contexts] winkler
Line 63: Line 63:
 #include <ros/ros.h> #include <ros/ros.h>
 #include <beliefstate_client/BeliefstateClient.h> #include <beliefstate_client/BeliefstateClient.h>
 +#include <beliefstate_client/Context.h>
  
 using namespace beliefstate_client; using namespace beliefstate_client;
Line 143: Line 144:
 generation. generation.
  
 +A resulting PDF could then look like this: 
 +{{ :doc:logging:concurrentlogging.png?800 |}}
 ==== Non-Default Contexts ==== ==== Non-Default Contexts ====
  
-To override default-parameters, the function calls startContext and endContext allow optional parameters for changing+To override default-parameters, the function calls ''startContext'' and ''end'' allow optional parameters for changing
  
   * the start and end timestamps for the context timepoints, and   * the start and end timestamps for the context timepoints, and
Line 154: Line 156:
  
 <code pseudo> <code pseudo>
-int startContext(context-name, optional start-timestamp)+Context* Context::startContext(context-name, optional start-timestamp)
 </code> </code>
 So the time point noted in the resulting log-tree can be annotated with a custom timepoint (for non-realtime logging uses). If this parameter is omitted, the current Unix time on the system running the Beliefstate logging system is used. So the time point noted in the resulting log-tree can be annotated with a custom timepoint (for non-realtime logging uses). If this parameter is omitted, the current Unix time on the system running the Beliefstate logging system is used.
  
-The same accounts for the ''endContext'' call:+The same accounts for the ''end'' call:
 <code pseudo> <code pseudo>
-int endContext(context-name, optional success-flag, optional end-timestamp)+void Context::end(optional success-flag, optional end-timestamp)
 </code> </code>
 The success flag is by default set to ''true''. For the ''endTime'' timestamp, the same rules apply as for the ''startTime'' timestamp. The success flag is by default set to ''true''. For the ''endTime'' timestamp, the same rules apply as for the ''startTime'' timestamp.
Line 170: Line 172:
  
 <code pseudo> <code pseudo>
-int startContext(context-name, optional class-namespace, optional class-name, optional start-timestamp)+Context* Context::startContext(context-name, optional class-namespace, optional class-name, optional start-timestamp)
 </code> </code>
  
Line 185: Line 187:
 In you C++-program, you would just call: In you C++-program, you would just call:
 <code cpp> <code cpp>
-int nCtx bscl->startContext("Task-Ctx-1", "&knowrob;", "CustomClass", 0); +Context* ctxContext ctxMain->startContext("Task-Ctx-1", "&knowrob;", "CustomClass", 0); 
-bscl->endContext(nCtx, 10)+ctxContext->end(true, 10)
 </code> </code>
  
-Of course, for real-time purposes (or if you don't care about the timestamps), you can leave the numerical last parameters of each call out.+Of course, for real-time purposes (or if you don't care about the timestamps), you can leave out the numerical last parameters of each call.
  
  
 === Issueing Discrete Events === === Issueing Discrete Events ===
  
-When your application requires the issuance of discrete, momentarily events you can use the convenience function discreteEvent:+When your application requires the issuance of discrete, momentarily events you can use the convenience function ''discreteEvent'':
 <code pseudo> <code pseudo>
-int discreteEvent(event-name, optional class-namespace, optional class-name, optional success-flag, optional timestamp)+void Context::discreteEvent(event-name, optional class-namespace, optional class-name, optional success-flag, optional timestamp)
 </code> </code>
  
Line 211: Line 213:
 should be added to the current context. To achieve this, in your program, call these lines while you are in the appropriate context: should be added to the current context. To achieve this, in your program, call these lines while you are in the appropriate context:
 <code cpp> <code cpp>
-bscl->annotateParameter("X", 5); +ctxContext->annotateParameter("X", 5); 
-bscl->annotateParameter("Room", "Kitchen");+ctxContext->annotateParameter("Room", "Kitchen");
 </code> </code>
 The resulting ''.owl''-file will now include information about the manually annotated parameters: The resulting ''.owl''-file will now include information about the manually annotated parameters:
Line 256: Line 258:
     <knowrob:startTime rdf:resource="&log;timepoint_1410254697"/>     <knowrob:startTime rdf:resource="&log;timepoint_1410254697"/>
     <knowrob:endTime rdf:resource="&log;timepoint_1410254697"/>     <knowrob:endTime rdf:resource="&log;timepoint_1410254697"/>
-    <knowrob:objectInContact rdf:resource="&sim;ObjectsInContact_unmkCtDP_Cup_0"/> +    <knowrob:objectInContact rdf:resource="&sim;Cup_object_s8hJIQ3L"/> 
-    <knowrob:objectInContact rdf:resource="&sim;ObjectsInContact_unmkCtDP_Table_0"/>+    <knowrob:objectInContact rdf:resource="&sim;Table_object_jfFU038A"/>
 </owl:namedIndividual> </owl:namedIndividual>
 </code> </code>
 This is achieved by using the following, simple code: This is achieved by using the following, simple code:
 <code cpp> <code cpp>
-int nID bscl->startContext("ObjectsInContact", "&sim;", "ObjectsInContact");+Context* ctxInCtct ctxMain->startContext("ObjectsInContact", "&sim;", "ObjectsInContact");
  
 Object* objCup = new Object("&sim;", "Cup"); Object* objCup = new Object("&sim;", "Cup");
-bscl->addObject(objCup, "knowrob:objectInContact");+ctxInCtct->addObject(objCup, "knowrob:objectInContact");
  
 Object* objTable = new Object("&sim;", "Table"); Object* objTable = new Object("&sim;", "Table");
-bscl->addObject(objTable, "knowrob:objectInContact");+ctxInCtct->addObject(objTable, "knowrob:objectInContact");
  
 delete objCup; delete objCup;
 delete objTable; delete objTable;
  
-bscl->endContext(nID);+ctxInCtct->end();
 </code> </code>
 Additionally, two object individuals will be created, reflecting the object's respective type: Additionally, two object individuals will be created, reflecting the object's respective type:
 <code xml> <code xml>
-<owl:namedIndividual rdf:about="&sim;ObjectsInContact_unmkCtDP_Cup_0">+<owl:namedIndividual rdf:about="&sim;Cup_object_s8hJIQ3L">
     <knowrob:designator rdf:resource="&log;object_syiJzh35HBm4Tf"/>     <knowrob:designator rdf:resource="&log;object_syiJzh35HBm4Tf"/>
     <rdf:type rdf:resource="&sim;Cup"/>     <rdf:type rdf:resource="&sim;Cup"/>
 </owl:namedIndividual> </owl:namedIndividual>
  
-<owl:namedIndividual rdf:about="&sim;ObjectsInContact_unmkCtDP_Table_0">+<owl:namedIndividual rdf:about="&sim;Table_object_jfFU038A">
     <knowrob:designator rdf:resource="&log;object_6ti909YZVsLifo"/>     <knowrob:designator rdf:resource="&log;object_6ti909YZVsLifo"/>
     <rdf:type rdf:resource="&sim;Table"/>     <rdf:type rdf:resource="&sim;Table"/>
Line 293: Line 295:
 If they are left out, the object will be of type ''&knowrob;HumanScaleObject''. When adding the object to the current context, the call If they are left out, the object will be of type ''&knowrob;HumanScaleObject''. When adding the object to the current context, the call
 <code pseudo> <code pseudo>
-addObject(object, optional string property)+void Context::addObject(object, optional string property)
 </code> </code>
 produces the actual addition of the object reference to the current context (and creation of the object individual). The optional ''property'' parameter specifies the property tag in the OWL context individual. If left out, it defaults to ''knowrob:objectActedOn''. You have to specify it along its namespace. produces the actual addition of the object reference to the current context (and creation of the object individual). The optional ''property'' parameter specifies the property tag in the OWL context individual. If left out, it defaults to ''knowrob:objectActedOn''. You have to specify it along its namespace.
 +
 +
 +=== Registering custom OWL namespaces ===
 +
 +When using custom namespaces in the entity class definitions, these namespaces need to be registered properly in the OWL file when exporting it. In order to do that, add this line to your program before exporting your logged data:
 +<code cpp>
 +bscl->registerOWLNamespace("sim", "http://some-namespace.org/#");
 +</code>
 +with both parameters representing your use-case, of course.
 +
 +Custom namespaces can therefore be registered by calling
 +''void BeliefstateClient::registerOWLNamespace(std::string strShortcut, std::string strIRI);''
 +where the shortcut is the short version of the namespace, i.e. ''sim'', and the IRI is the actual URL you want to have associated.
 +==== Sample Program ====
 +
 +A complete sample program depicting the ''beliefstate_client'' usage can be found [[doc:logging:tutorials-cpp:sample-program|here]].