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 radiobutton in the load dialog to enable the logTime.

Signed-off-by: Luca Bartoli <[email protected]>
  • Loading branch information
lucabart97 committed Jan 24, 2025
1 parent 4aa9074 commit d8bf606
Show file tree
Hide file tree
Showing 4 changed files with 58 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_mcap_log_time", int(params.use_mcap_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_mcap_log_time = bool(elem.attribute("use_mcap_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_mcap_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_mcap_log_time;
};

} // namespace mcap
13 changes: 13 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_mcap_log_time = settings.value(prefix + "use_mcap_log_time", false).toBool();
}
else
{
Expand All @@ -50,6 +51,14 @@ DialogMCAP::DialogMCAP(const std::unordered_map<int, mcap::ChannelPtr>& channels
}
ui->spinBox->setValue(params.max_array_size);
ui->checkBoxUseTimestamp->setChecked(params.use_timestamp);
if (params.use_mcap_log_time)
{
ui->radioLogTime->setChecked(true);
}
else
{
ui->radioPubTime->setChecked(true);
}

int row = 0;
for (const auto& [id, channel] : channels)
Expand Down Expand Up @@ -83,6 +92,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_mcap_log_time = ui->radioLogTime->isChecked();

QItemSelectionModel* select = ui->tableWidget->selectionModel();
QStringList selected_topics;
Expand All @@ -107,10 +117,13 @@ void DialogMCAP::accept()
bool clamp_checked = ui->radioClamp->isChecked();
int max_array = ui->spinBox->value();
bool use_timestamp = ui->checkBoxUseTimestamp->isChecked();
bool use_mcap_log_time = ui->radioLogTime->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_mcap_log_time", use_mcap_log_time);

QItemSelectionModel* select = ui->tableWidget->selectionModel();
QStringList selected_topics;
Expand Down
38 changes: 38 additions & 0 deletions plotjuggler_plugins/DataLoadMCAP/dialog_mcap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Select the MCAP timestamping mode:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioPubTime">
<property name="text">
<string>publish time</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioLogTime">
<property name="text">
<string>log time</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
Expand All @@ -86,6 +120,7 @@
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
Expand Down Expand Up @@ -178,4 +213,7 @@
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

0 comments on commit d8bf606

Please sign in to comment.