Adding inputs/outputs
To send data between components, Pacpus uses input/output system based on signals/slots.
We will try to add to our component called MyComponent
:
- an output named
"scan"
of type
LidarScan
,
- an input named
"pose"
of type
GeoPose2D
.
So, add virtual methods overriden from ComponentBase
:
addInputs()
and
addOutputs()
to the component:
// MyComponent.h class My Component // ... { // ... protected: virtual void addInputs() /* override */; virtual void addOutputs() /* override */; };
// MyComponent.cpp void MyComponent::addInputs() { // inputs go here } void MyComponent::addOutputs() { // outputs go here }
Adding an output
To add an output, you have to use template method ComponentBase::addOutput<class OutputType, class ComponentType>(const char* outputName)
:
// MyComponent.cpp void MyComponent::addOutputs() { // outputs go here addOutput<LidarScan, MyComponent>("scan"); }
Adding an input
To add an input, you have to have a method in your class that will process it. It should take as the only argument, a constant reference to the type of the input. In our example, we suppose to have a function declared as follows:
void processPose(GeoPose2D const& pose);
You have to use template method ComponentBase::addInput<class OutputType, class ComponentType, typename ProcessingFunction>(const char* outputName, ProcessingFunction inputProcessingFunction)
:
// MyComponent.cpp void MyComponent::addInputs() { // inputs go here addInput<GeoPose2D, MyComponent>("pose", &MyComponent::processPose); }
The second argument is the address (&
) of our processing method.
You can also use a free function or a functor object, as well as any other callable object, e.g.
std::function
,
boost::function
, etc.