16 _dummy_notification =
new QAction(
this);
18 connect(_dummy_notification, &QAction::triggered,
this, [
this]() {
19 QMessageBox::warning(
nullptr,
"Dummy Notifications",
20 QString(
"%1 notifications").
arg(_notifications_count),
23 if (_notifications_count > 0)
25 _notifications_count = 0;
26 emit notificationsChanged(_notifications_count);
30 _notifications_count = 0;
31 for (
int i = 0; i < 150; i++)
33 auto str = QString(
"data_vect/%1").arg(i).toStdString();
35 param.
A = 6 * ((double)rand() / (double)RAND_MAX) - 3;
36 param.
B = 3 * ((double)rand() / (double)RAND_MAX);
37 param.
C = 3 * ((double)rand() / (double)RAND_MAX);
38 param.
D = 20 * ((double)rand() / (double)RAND_MAX);
39 _parameters.insert({ str, param });
40 auto& plotdata = dataMap().addNumeric(str)->second;
43 dataMap().addStringSeries(
"color");
46 auto tcGroup = std::make_shared<PJ::PlotGroup>(
"tc");
47 tcGroup->setAttribute(
TEXT_COLOR, QColor(Qt::blue));
49 auto& tc_default = dataMap().addNumeric(
"tc/default")->second;
50 auto& tc_red = dataMap().addNumeric(
"tc/red")->second;
52 tc_red.setAttribute(
TEXT_COLOR, QColor(Qt::red));
59 _thread = std::thread([
this]() { this->loop(); });
66 if (_thread.joinable())
95 std::lock_guard<std::mutex> lock(mutex());
97 using namespace std::chrono;
98 static auto initial_time = high_resolution_clock::now();
100 duration_cast<duration<double>>(initial_time.time_since_epoch()).count();
102 auto now = high_resolution_clock::now();
103 std::string colors[] = {
"RED",
"BLUE",
"GREEN" };
106 duration_cast<duration<double>>(now - initial_time).count() + offset;
108 for (
auto& it : _parameters)
110 auto& plot = dataMap().numeric.find(it.first)->second;
113 double val = param.
A * sin(param.
B * stamp + param.
C) + param.
D;
117 auto& col_series = dataMap().strings.find(
"color")->second;
118 col_series.pushBack({ stamp, colors[(count / 10) % 3] });
120 auto& tc_default = dataMap().numeric.find(
"tc/default")->second;
121 tc_default.pushBack({ stamp, double(count) });
123 auto& tc_red = dataMap().numeric.find(
"tc/red")->second;
124 tc_red.pushBack({ stamp, double(count) });
135 auto prev = std::chrono::high_resolution_clock::now();
138 if (count++ % 200 == 0)
140 _notifications_count++;
141 emit notificationsChanged(_notifications_count);
143 std::this_thread::sleep_until(prev + std::chrono::milliseconds(20));
virtual bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
virtual ~DataStreamSample() override
virtual bool start(QStringList *) override
start streaming.
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
virtual void shutdown() override
shutdown Stop streaming
constexpr auto count() -> size_t
virtual bool isRunning() const override
isRunning
virtual bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
typename PlotDataBase< double, Value >::Point Point
ROSCONSOLE_DECL void shutdown()