Skip to content

Commit

Permalink
DataLoadMCAP: add support to mcap logTime
Browse files Browse the repository at this point in the history
The DataLoadMCAP plugin support only the publishTime of the mcap
message. Add a checkbox in the load dialog to enable the logTime.

Signed-off-by: Luca Bartoli <[email protected]>
  • Loading branch information
lucabart97 committed Jan 23, 2025
1 parent 4aa9074 commit 0782e04
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plotjuggler_plugins/DataLoadMCAP/dataload_mcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool DataLoadMCAP::xmlSaveState(QDomDocument& doc, QDomElement& parent_element)
QDomElement elem = doc.createElement("parameters");
const auto& params = *_dialog_parameters;
elem.setAttribute("use_timestamp", int(params.use_timestamp));
elem.setAttribute("use_log_time", int(params.use_log_time));
elem.setAttribute("clamp_large_arrays", int(params.clamp_large_arrays));
elem.setAttribute("max_array_size", params.max_array_size);
elem.setAttribute("selected_topics", params.selected_topics.join(';'));
Expand All @@ -55,6 +56,7 @@ bool DataLoadMCAP::xmlLoadState(const QDomElement& parent_element)
}
mcap::LoadParams params;
params.use_timestamp = bool(elem.attribute("use_timestamp").toInt());
params.use_log_time = bool(elem.attribute("use_log_time").toInt());
params.clamp_large_arrays = bool(elem.attribute("clamp_large_arrays").toInt());
params.max_array_size = elem.attribute("max_array_size").toInt();
params.selected_topics = elem.attribute("selected_topics").split(';');
Expand Down Expand Up @@ -227,6 +229,10 @@ bool DataLoadMCAP::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_dat

// MCAP always represents publishTime in nanoseconds
double timestamp_sec = double(msg_view.message.publishTime) * 1e-9;
if(_dialog_parameters->use_log_time)
{
timestamp_sec = double(msg_view.message.logTime) * 1e-9;
}
auto parser_it = parsers_by_channel.find(msg_view.channel->id);
if (parser_it == parsers_by_channel.end())
{
Expand Down
1 change: 1 addition & 0 deletions plotjuggler_plugins/DataLoadMCAP/dataload_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct LoadParams
unsigned max_array_size;
bool clamp_large_arrays;
bool use_timestamp = false;
bool use_log_time = false;
};

} // namespace mcap
6 changes: 6 additions & 0 deletions plotjuggler_plugins/DataLoadMCAP/dialog_mcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ DialogMCAP::DialogMCAP(const std::unordered_map<int, mcap::ChannelPtr>& channels
params.clamp_large_arrays = settings.value(prefix + "clamp", true).toBool();
params.max_array_size = settings.value(prefix + "max_array", 500).toInt();
params.use_timestamp = settings.value(prefix + "use_timestamp", false).toBool();
params.use_log_time = settings.value(prefix + "use_log_time", false).toBool();
}
else
{
Expand All @@ -50,6 +51,7 @@ DialogMCAP::DialogMCAP(const std::unordered_map<int, mcap::ChannelPtr>& channels
}
ui->spinBox->setValue(params.max_array_size);
ui->checkBoxUseTimestamp->setChecked(params.use_timestamp);
ui->checkBoxUseLogTimestamp->setChecked(params.use_log_time);

int row = 0;
for (const auto& [id, channel] : channels)
Expand Down Expand Up @@ -83,6 +85,7 @@ mcap::LoadParams DialogMCAP::getParams() const
params.max_array_size = ui->spinBox->value();
params.clamp_large_arrays = ui->radioClamp->isChecked();
params.use_timestamp = ui->checkBoxUseTimestamp->isChecked();
params.use_log_time = ui->checkBoxUseLogTimestamp->isChecked();

QItemSelectionModel* select = ui->tableWidget->selectionModel();
QStringList selected_topics;
Expand All @@ -107,10 +110,13 @@ void DialogMCAP::accept()
bool clamp_checked = ui->radioClamp->isChecked();
int max_array = ui->spinBox->value();
bool use_timestamp = ui->checkBoxUseTimestamp->isChecked();
bool use_log_time = ui->checkBoxUseLogTimestamp->isChecked();


settings.setValue(prefix + "clamp", clamp_checked);
settings.setValue(prefix + "max_array", max_array);
settings.setValue(prefix + "use_timestamp", use_timestamp);
settings.setValue(prefix + "use_log_time", use_log_time);

QItemSelectionModel* select = ui->tableWidget->selectionModel();
QStringList selected_topics;
Expand Down
7 changes: 7 additions & 0 deletions plotjuggler_plugins/DataLoadMCAP/dialog_mcap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUseLogTimestamp">
<property name="text">
<string>Use the mcap log time (default publish time)</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
Expand Down

0 comments on commit 0782e04

Please sign in to comment.