Tutorial: Creating a Unit that Subscribes to Data
#include <deque>
namespace tutorials {
{
public:
MeanCalculator();
template<typename Reflector>
{
}
protected:
virtual void initialize();
private:
private:
std::deque<float> mQueue;
};
MeanCalculator::MeanCalculator()
{
}
void MeanCalculator::initialize()
{
subscribe<float>("FloatChannel", &MeanCalculator::onNewData);
mMeanChannel = publish<float>("MeanChannel");
}
{
mQueue.push_back(data->value());
if (mQueue.size() > 10)
mQueue.pop_front();
float sum = 0.0;
foreach(float f, mQueue)
sum += f;
float mean = sum / mQueue.size();
std::cout << "MeanCalculator: " << mean << std::endl;
w->value() = mean;
}
}