Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zcm loader prefix #1022

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plotjuggler_plugins/PluginsZcm/config_zcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ QString ConfigZCM::getLibraries() const
}
}

QString ConfigZCM::getDataPrefix() const
{
return ui->lineEditDataPrefix->text();
}

void ConfigZCM::on_radioEnvironmentLibrary_toggled(bool checked)
{
if (checked)
Expand Down
1 change: 1 addition & 0 deletions plotjuggler_plugins/PluginsZcm/config_zcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ConfigZCM : public QWidget
~ConfigZCM();

QString getLibraries() const;
QString getDataPrefix() const;

private slots:
void on_radioEnvironmentLibrary_toggled(bool checked);
Expand Down
56 changes: 48 additions & 8 deletions plotjuggler_plugins/PluginsZcm/config_zcm.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<x>0</x>
<y>0</y>
<width>553</width>
<height>264</height>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,1">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,0,1">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -26,6 +26,49 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;Data Prefix:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditDataPrefix">
<property name="minimumSize">
<size>
<width>200</width>
<height>26</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>28</height>
</size>
</property>
<property name="text">
<string></string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
Expand Down Expand Up @@ -78,6 +121,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidgetLibs">
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
Expand Down Expand Up @@ -137,12 +183,6 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
Expand Down
19 changes: 13 additions & 6 deletions plotjuggler_plugins/PluginsZcm/dataload_zcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ DataLoadZcm::DataLoadZcm()
_ui->setupUi(_dialog);

_config_widget = new ConfigZCM("DataLoadZcm", _dialog);
_config_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
_ui->mainLayout->insertWidget(0, _config_widget, 1);
_ui->mainLayout->setStretchFactor(_config_widget, 0);

_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

Expand Down Expand Up @@ -269,6 +271,8 @@ bool DataLoadZcm::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data
vector<pair<string, string>> strings;
ProcessUsr usr = { numerics, strings };

string prefix = _config_widget->getDataPrefix().toStdString() + "/";

auto processEvent = [&](const zcm::LogEvent* evt) {
if (_selected_channels.find(evt->channel) == _selected_channels.end())
{
Expand All @@ -277,9 +281,10 @@ bool DataLoadZcm::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data

if (evt->datalen == 0)
{
auto itr = plot_data.numeric.find(evt->channel);
string chan(prefix + evt->channel);
auto itr = plot_data.numeric.find(chan);
if (itr == plot_data.numeric.end())
itr = plot_data.addNumeric(evt->channel);
itr = plot_data.addNumeric(chan);
itr->second.pushBack({ (double)evt->timestamp / 1e6, 0 });
return;
}
Expand All @@ -288,16 +293,18 @@ bool DataLoadZcm::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data
types, processData, &usr);
for (auto& n : usr.numerics)
{
auto itr = plot_data.numeric.find(n.first);
string chan(prefix + n.first);
auto itr = plot_data.numeric.find(chan);
if (itr == plot_data.numeric.end())
itr = plot_data.addNumeric(n.first);
itr = plot_data.addNumeric(chan);
itr->second.pushBack({ (double)evt->timestamp / 1e6, n.second });
}
for (auto& s : usr.strings)
{
auto itr = plot_data.strings.find(s.first);
string chan(prefix + s.first);
auto itr = plot_data.strings.find(chan);
if (itr == plot_data.strings.end())
itr = plot_data.addStringSeries(s.first);
itr = plot_data.addStringSeries(chan);
itr->second.pushBack({ (double)evt->timestamp / 1e6, s.second });
}

Expand Down
12 changes: 8 additions & 4 deletions plotjuggler_plugins/PluginsZcm/datastream_zcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ bool DataStreamZcm::start(QStringList*)
}
}

_prefix = _config_widget->getDataPrefix().toStdString() + "/";
_zcm->start();
_running = true;
return true;
Expand Down Expand Up @@ -227,24 +228,27 @@ void DataStreamZcm::handler(const zcm::ReceiveBuffer* rbuf, const string& channe
{
zcm::Introspection::processEncodedType(channel, rbuf->data, rbuf->data_size, "/",
*_types.get(), processData, this);

{
std::lock_guard<std::mutex> lock(mutex());

for (auto& n : _numerics)
{
auto itr = dataMap().numeric.find(n.first);
auto chan = _prefix + n.first;
auto itr = dataMap().numeric.find(chan);
if (itr == dataMap().numeric.end())
{
itr = dataMap().addNumeric(n.first);
itr = dataMap().addNumeric(chan);
}
itr->second.pushBack({ double(rbuf->recv_utime) / 1e6, n.second });
}
for (auto& s : _strings)
{
auto itr = dataMap().strings.find(s.first);
auto chan = _prefix + s.first;
auto itr = dataMap().strings.find(chan);
if (itr == dataMap().strings.end())
{
itr = dataMap().addStringSeries(s.first);
itr = dataMap().addStringSeries(chan);
}
itr->second.pushBack({ double(rbuf->recv_utime) / 1e6, s.second });
}
Expand Down
1 change: 1 addition & 0 deletions plotjuggler_plugins/PluginsZcm/datastream_zcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private slots:

void handler(const zcm::ReceiveBuffer* rbuf, const std::string& channel);

std::string _prefix;
bool _running;
QString _types_library;
QString _subscribe_string;
Expand Down
Loading