Skip to content

Commit

Permalink
feat(tier4_system_rviz_plugin): add parameter of max_line_text_num
Browse files Browse the repository at this point in the history
Signed-off-by: Takayuki Murooka <[email protected]>
  • Loading branch information
takayuki5168 committed Nov 19, 2024
1 parent b4603fd commit 1380f79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion common/tier4_system_rviz_plugin/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<package format="3">
<name>tier4_system_rviz_plugin</name>
<version>0.38.0</version>
<description>The tier4_vehicle_rviz_plugin package</description>
<description>The tier4_system_rviz_plugin package</description>
<maintainer email="[email protected]">Koji Minoda</maintainer>
<maintainer email="[email protected]">Takayuki Murooka</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,28 @@

namespace rviz_plugins
{
void insertNewlines(std::string & str, const size_t max_line_length)
void insertNewlines(std::string & str, const size_t max_line_text_num)

Check warning on line 65 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L65

Added line #L65 was not covered by tests
{
size_t index = max_line_length;
size_t index = max_line_text_num;

while (index < str.size()) {
str.insert(index, "\n");
index = index + max_line_length + 1;
index = index + max_line_text_num + 1;

Check warning on line 71 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L71

Added line #L71 was not covered by tests
}
}

std::optional<std::string> generateMrmMessage(diagnostic_msgs::msg::DiagnosticStatus diag_status)
std::optional<std::string> generateMrmMessage(

Check warning on line 75 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L75

Added line #L75 was not covered by tests
const diagnostic_msgs::msg::DiagnosticStatus & diag_status, const int max_line_text_num)
{
if (diag_status.hardware_id == "") {
return std::nullopt;
} else if (diag_status.level == diagnostic_msgs::msg::DiagnosticStatus::ERROR) {
std::string msg = "- ERROR: " + diag_status.name + " (" + diag_status.message + ")";
insertNewlines(msg, 100);
insertNewlines(msg, max_line_text_num);

Check warning on line 82 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L82

Added line #L82 was not covered by tests
return msg;
} else if (diag_status.level == diagnostic_msgs::msg::DiagnosticStatus::WARN) {
std::string msg = "- WARN: " + diag_status.name + " (" + diag_status.message + ")";
insertNewlines(msg, 100);
insertNewlines(msg, max_line_text_num);

Check warning on line 86 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L86

Added line #L86 was not covered by tests
return msg;
}
return std::nullopt;
Expand Down Expand Up @@ -114,7 +115,11 @@ MrmSummaryOverlayDisplay::MrmSummaryOverlayDisplay()
property_font_size_->setMin(1);
property_max_letter_num_ = new rviz_common::properties::IntProperty(
"Max Letter Num", 100, "Max Letter Num", this, SLOT(updateVisualization()), this);
property_max_line_text_num_ = new rviz_common::properties::IntProperty(
"Max Line Text Num", 100, "Max Line Text Num", this, SLOT(updateVisualization()), this);

Check warning on line 119 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L118-L119

Added lines #L118 - L119 were not covered by tests

property_max_letter_num_->setMin(10);
property_max_line_text_num_->setMin(10);

Check warning on line 122 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L122

Added line #L122 was not covered by tests
}

MrmSummaryOverlayDisplay::~MrmSummaryOverlayDisplay()
Expand Down Expand Up @@ -159,6 +164,8 @@ void MrmSummaryOverlayDisplay::update(float wall_dt, float ros_dt)
(void)wall_dt;
(void)ros_dt;

const int max_line_text_num = property_max_line_text_num_->getInt();

Check warning on line 167 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L167

Added line #L167 was not covered by tests

// MRM summary
std::vector<std::string> mrm_comfortable_stop_summary_list = {};
std::vector<std::string> mrm_emergency_stop_summary_list = {};
Expand All @@ -168,13 +175,13 @@ void MrmSummaryOverlayDisplay::update(float wall_dt, float ros_dt)
if (last_msg_ptr_) {
hazard_level = last_msg_ptr_->status.level;
for (const auto & diag_status : last_msg_ptr_->status.diag_latent_fault) {
const std::optional<std::string> msg = generateMrmMessage(diag_status);
const std::optional<std::string> msg = generateMrmMessage(diag_status, max_line_text_num);

Check warning on line 178 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L178

Added line #L178 was not covered by tests
if (msg != std::nullopt) {
mrm_comfortable_stop_summary_list.push_back(msg.value());
}
}
for (const auto & diag_status : last_msg_ptr_->status.diag_single_point_fault) {
const std::optional<std::string> msg = generateMrmMessage(diag_status);
const std::optional<std::string> msg = generateMrmMessage(diag_status, max_line_text_num);

Check warning on line 184 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

MrmSummaryOverlayDisplay::update already has high cyclomatic complexity, and now it increases in Lines of Code from 72 to 73. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 184 in common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_system_rviz_plugin/src/mrm_summary_overlay_display.cpp#L184

Added line #L184 was not covered by tests
if (msg != std::nullopt) {
mrm_emergency_stop_summary_list.push_back(msg.value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private Q_SLOTS:
rviz_common::properties::FloatProperty * property_value_scale_;
rviz_common::properties::IntProperty * property_font_size_;
rviz_common::properties::IntProperty * property_max_letter_num_;
rviz_common::properties::IntProperty * property_max_line_text_num_;
// QImage hud_;

private:
Expand Down

0 comments on commit 1380f79

Please sign in to comment.