Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
doc:logging:tutorials-cpp [2014/09/08 05:25] – Textual enhancements, format corrections winkler | doc:logging:tutorials-cpp [2014/09/19 15:13] – Added info on registering custom OWL namespaces winkler | ||
---|---|---|---|
Line 36: | Line 36: | ||
wstool set beliefstate_client --git https:// | wstool set beliefstate_client --git https:// | ||
- | After doing a wstool update to make sure all library checkouts are up | + | After doing a '' |
to date, make sure that everything compiles just fine: | to date, make sure that everything compiles just fine: | ||
Line 62: | Line 62: | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include < | + | #include < |
+ | #include <beliefstate_client/Context.h> | ||
+ | |||
+ | using namespace beliefstate_client; | ||
int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||
Line 98: | Line 102: | ||
| | ||
// Open a top-level context (level 0) | // Open a top-level context (level 0) | ||
- | | + | |
| | ||
// Open a sub-context (level 1) | // Open a sub-context (level 1) | ||
- | | + | |
- | // End the sub-context from level 1 | + | |
- | bscl-> | + | |
- | | + | |
// Open another sub-context (level 1) | // Open another sub-context (level 1) | ||
- | | + | |
+ | |||
+ | // Close the first sub-context | ||
+ | ctxCupOnTable-> | ||
| | ||
- | // Open yet another sub-context (level 2) | + | // Close the second |
- | int nContextID_3 = bscl-> | + | |
- | // End the sub-context from level 2 | + | |
- | bscl-> | + | |
- | + | ||
- | // End the sub-context | + | |
- | | + | |
| | ||
// End the top-level context | // End the top-level context | ||
- | | + | |
| | ||
// Actual logging ends here. | // Actual logging ends here. | ||
Line 123: | Line 123: | ||
The logging result of this program is a nested tree with two branches | The logging result of this program is a nested tree with two branches | ||
- | from the top-level node, one with depth 1, and one with depth 2. | + | from the top-level node. The logged circumstances here could be that a cup that formerly sat on a table in a room was first removed from the table (ending the '' |
+ | |||
+ | Contexts can be hierarchically nested, or can be concatenated concurrently. A good practice is to always have one main context from which all other contexts derive. Don't create multiple contexts using '' | ||
To export the logged tree now, we add another call from inside the | To export the logged tree now, we add another call from inside the | ||
Line 142: | Line 144: | ||
generation. | generation. | ||
+ | A resulting PDF could then look like this: | ||
+ | {{ : | ||
==== Non-Default Contexts ==== | ==== Non-Default Contexts ==== | ||
- | To override default-parameters, | + | To override default-parameters, |
* the start and end timestamps for the context timepoints, and | * the start and end timestamps for the context timepoints, and | ||
Line 153: | Line 156: | ||
<code pseudo> | <code pseudo> | ||
- | int startContext(context-name, | + | Context* Context::startContext(context-name, |
</ | </ | ||
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 '' | + | The same accounts for the '' |
<code pseudo> | <code pseudo> | ||
- | int endContext(context-name, | + | void Context:: |
</ | </ | ||
The success flag is by default set to '' | The success flag is by default set to '' | ||
Line 169: | Line 172: | ||
<code pseudo> | <code pseudo> | ||
- | int startContext(context-name, | + | Context* Context::startContext(context-name, |
</ | </ | ||
Line 184: | Line 187: | ||
In you C++-program, | In you C++-program, | ||
<code cpp> | <code cpp> | ||
- | int nCtx = bscl-> | + | Context* ctxContext |
- | bscl-> | + | ctxContext-> |
</ | </ | ||
- | Of course, for real-time purposes (or if you don't care about the timestamps), | + | Of course, for real-time purposes (or if you don't care about the timestamps), |
=== 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 |
<code pseudo> | <code pseudo> | ||
- | int discreteEvent(event-name, | + | void Context::discreteEvent(event-name, |
</ | </ | ||
Line 210: | 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-> | + | ctxContext-> |
- | bscl-> | + | ctxContext-> |
</ | </ | ||
The resulting '' | The resulting '' | ||
Line 244: | Line 247: | ||
</ | </ | ||
is a reference to the designator published via the ROS topic ''/ | is a reference to the designator published via the ROS topic ''/ | ||
+ | |||
+ | |||
+ | === Adding Object References === | ||
+ | In some situations, it is useful to manually annotate objects that are part of the current scene, and maybe play a significant role for the current task. Object references to the currently active task can be annotated in a convenient way, producing output like this: | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | This is achieved by using the following, simple code: | ||
+ | <code cpp> | ||
+ | Context* ctxInCtct = ctxMain-> | ||
+ | |||
+ | Object* objCup = new Object("& | ||
+ | ctxInCtct-> | ||
+ | |||
+ | Object* objTable = new Object("& | ||
+ | ctxInCtct-> | ||
+ | |||
+ | delete objCup; | ||
+ | delete objTable; | ||
+ | |||
+ | ctxInCtct-> | ||
+ | </ | ||
+ | Additionally, | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | The '' | ||
+ | <code pseudo> | ||
+ | new Object(string object-class-namespace, | ||
+ | </ | ||
+ | If they are left out, the object will be of type ''& | ||
+ | <code pseudo> | ||
+ | void Context:: | ||
+ | </ | ||
+ | produces the actual addition of the object reference to the current context (and creation of the object individual). The optional '' | ||
+ | |||
+ | |||
+ | === Registering custom OWL namespaces === | ||
+ | |||
+ | When using custom namespaces in the entity class definitions, | ||
+ | <code cpp> | ||
+ | bscl-> | ||
+ | </ | ||
+ | with both parameters representing your use-case, of course. | ||
+ | |||
+ | Custom namespaces can therefore be registered by calling | ||
+ | `void BeliefstateClient:: | ||
+ | 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 '' |