Changes between Initial Version and Version 1 of TutorialAddingInputsOutputs


Ignore:
Timestamp:
Nov 21, 2013, 5:56:56 PM (11 years ago)
Author:
Marek Kurdej
Comment:

Created

Legend:

Unmodified
Added
Removed
Modified
  • TutorialAddingInputsOutputs

    v1 v1  
     1= Adding inputs/outputs =
     2
     3To send data between components, Pacpus uses input/output system based on signals/slots.
     4
     5We will try to add to our component called ```MyComponent```:
     61. an output named ```"scan"``` of type ```LidarScan```,
     72. an input named ```"pose"``` of type ```GeoPose2D``` .
     8
     9So, add virtual methods overriden from ```ComponentBase```: ```addInputs()``` and ```addOutputs()``` to the component:
     10
     11{{{#!c++
     12// MyComponent.h
     13
     14class My Component // ...
     15{
     16// ...
     17protected:
     18    virtual void addInputs() /* override */;
     19    virtual void addOutputs() /* override */;
     20};
     21}}}
     22
     23{{{#!c++
     24// MyComponent.cpp
     25
     26void MyComponent::addInputs()
     27{
     28    // inputs go here
     29}
     30
     31void MyComponent::addOutputs()
     32{
     33    // outputs go here
     34}
     35
     36}}}
     37
     38== Adding an output ==
     39
     40To add an output, you have to use template method ```ComponentBase::addOutput<class OutputType, class ComponentType>(const char* outputName)```:
     41
     42{{{#!c++
     43// MyComponent.cpp
     44
     45void MyComponent::addOutputs()
     46{
     47    // outputs go here
     48    addOutput<LidarScan, MyComponent>("scan");
     49}
     50}}}
     51
     52== Adding an input ==
     53
     54To add an input, you have to have a method in your class that will process it.
     55It should take as the only argument, a constant reference to the type of the input.
     56In our example, we suppose to have a function declared as follows:
     57
     58{{{#!c++
     59void processPose(GeoPose2D const& pose);
     60}}}
     61
     62You have to use template method ```ComponentBase::addInput<class OutputType, class ComponentType, typename ProcessingFunction>(const char* outputName, ProcessingFunction inputProcessingFunction)```:
     63
     64{{{#!c++
     65// MyComponent.cpp
     66
     67void MyComponent::addInputs()
     68{
     69    // inputs go here
     70    addInput<GeoPose2D, MyComponent>("pose", &MyComponent::processPose);
     71}
     72}}}
     73
     74The second argument is the address (```&```) of our processing method.
     75You can also use a free function or a functor object, as well as any other callable object, e.g. ```std::function```, ```boost::function```, etc.
     76