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

feat(tier4_state_rviz_plugin): check for abrupt deceleration #9474

Merged
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
1 change: 1 addition & 0 deletions common/tier4_state_rviz_plugin/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<depend>ament_index_cpp</depend>
<depend>autoware_adapi_v1_msgs</depend>
<depend>autoware_motion_utils</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>libqt5-core</depend>
<depend>libqt5-gui</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
#ifndef VELOCITY_STEERING_FACTORS_PANEL_HPP_
#define VELOCITY_STEERING_FACTORS_PANEL_HPP_

#include <QDoubleSpinBox>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
#include <QPushButton>
#include <QSpinBox>
#include <QTableWidget>
#include <rclcpp/rclcpp.hpp>
#include <rviz_common/panel.hpp>

#include <autoware_adapi_v1_msgs/msg/planning_behavior.hpp>
#include <autoware_adapi_v1_msgs/msg/steering_factor_array.hpp>
#include <autoware_adapi_v1_msgs/msg/velocity_factor_array.hpp>
#include <geometry_msgs/msg/accel_with_covariance_stamped.hpp>
#include <nav_msgs/msg/odometry.hpp>

#include <memory>

Expand All @@ -49,6 +50,11 @@ class VelocitySteeringFactorsPanel : public rviz_common::Panel
void onInitialize() override;

protected:
static constexpr double JERK_DEFAULT = 1.0;
static constexpr double DECEL_LIMIT_DEFAULT = 1.0;

static constexpr QColor COLOR_FREAK_PINK = {255, 0, 108};

// Layout
QGroupBox * makeVelocityFactorsGroup();
QGroupBox * makeSteeringFactorsGroup();
Expand All @@ -58,7 +64,14 @@ class VelocitySteeringFactorsPanel : public rviz_common::Panel
// Planning
QTableWidget * velocity_factors_table_{nullptr};
QTableWidget * steering_factors_table_{nullptr};
QDoubleSpinBox * jerk_input_{nullptr};
QDoubleSpinBox * decel_limit_input_{nullptr};

nav_msgs::msg::Odometry::ConstSharedPtr kinematic_state_;
geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr acceleration_;

rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr sub_kinematic_state_;
rclcpp::Subscription<geometry_msgs::msg::AccelWithCovarianceStamped>::SharedPtr sub_acceleration_;
rclcpp::Subscription<VelocityFactorArray>::SharedPtr sub_velocity_factors_;
rclcpp::Subscription<SteeringFactorArray>::SharedPtr sub_steering_factors_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QHeaderView>
#include <QString>
#include <QVBoxLayout>
#include <autoware/motion_utils/distance/distance.hpp>
#include <rviz_common/display_context.hpp>

#include <memory>
Expand All @@ -46,15 +47,36 @@
auto vertical_header = new QHeaderView(Qt::Vertical);
vertical_header->hide();
auto horizontal_header = new QHeaderView(Qt::Horizontal);
horizontal_header->setSectionResizeMode(QHeaderView::Stretch);
horizontal_header->setSectionResizeMode(QHeaderView::ResizeToContents);
horizontal_header->setStretchLastSection(true);

Check warning on line 51 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L50-L51

Added lines #L50 - L51 were not covered by tests

auto header_labels = QStringList({"Type", "Status", "Distance [m]", "Detail"});
velocity_factors_table_ = new QTableWidget();
velocity_factors_table_->setColumnCount(header_labels.size());
velocity_factors_table_->setHorizontalHeaderLabels(header_labels);
velocity_factors_table_->setVerticalHeader(vertical_header);
velocity_factors_table_->setHorizontalHeader(horizontal_header);
grid->addWidget(velocity_factors_table_, 0, 0);
grid->addWidget(velocity_factors_table_, 0, 0, 4, 1);

Check warning on line 59 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L59

Added line #L59 was not covered by tests

auto * jerk_label = new QLabel("Jerk");
grid->addWidget(jerk_label, 0, 1);

Check warning on line 62 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L61-L62

Added lines #L61 - L62 were not covered by tests

jerk_input_ = new QDoubleSpinBox;
jerk_input_->setMinimum(0.0);
jerk_input_->setValue(JERK_DEFAULT);
jerk_input_->setSingleStep(0.1);
jerk_input_->setSuffix(" [m/s\u00B3]");
grid->addWidget(jerk_input_, 1, 1);

Check warning on line 69 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L64-L69

Added lines #L64 - L69 were not covered by tests

auto * decel_limit_label = new QLabel("Decel limit");
grid->addWidget(decel_limit_label, 2, 1);

Check warning on line 72 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L71-L72

Added lines #L71 - L72 were not covered by tests

decel_limit_input_ = new QDoubleSpinBox;
decel_limit_input_->setMinimum(0.0);
decel_limit_input_->setValue(DECEL_LIMIT_DEFAULT);
decel_limit_input_->setSingleStep(0.1);
decel_limit_input_->setSuffix(" [m/s\u00B2]");
grid->addWidget(decel_limit_input_, 3, 1);

Check warning on line 79 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L74-L79

Added lines #L74 - L79 were not covered by tests

group->setLayout(grid);
return group;
Expand Down Expand Up @@ -90,6 +112,17 @@
raw_node_ = this->getDisplayContext()->getRosNodeAbstraction().lock()->get_raw_node();

// Planning
sub_kinematic_state_ = raw_node_->create_subscription<nav_msgs::msg::Odometry>(

Check warning on line 115 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L115

Added line #L115 was not covered by tests
"/localization/kinematic_state", 10,
[this](const nav_msgs::msg::Odometry::ConstSharedPtr msg) { kinematic_state_ = msg; });

Check warning on line 117 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L117

Added line #L117 was not covered by tests

sub_acceleration_ =
raw_node_->create_subscription<geometry_msgs::msg::AccelWithCovarianceStamped>(

Check warning on line 120 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L120

Added line #L120 was not covered by tests
"/localization/acceleration", 10,
[this](const geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr msg) {

Check warning on line 122 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L122

Added line #L122 was not covered by tests
acceleration_ = msg;
});

sub_velocity_factors_ = raw_node_->create_subscription<VelocityFactorArray>(
"/api/planning/velocity_factors", 10,
std::bind(&VelocitySteeringFactorsPanel::onVelocityFactors, this, _1));
Expand Down Expand Up @@ -155,6 +188,26 @@
label->setAlignment(Qt::AlignCenter);
velocity_factors_table_->setCellWidget(i, 3, label);
}

const auto row_background = [&]() -> QBrush {

Check warning on line 192 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L192

Added line #L192 was not covered by tests
if (!kinematic_state_ || !acceleration_) {
return {};

Check warning on line 194 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L194

Added line #L194 was not covered by tests
}
const auto & current_vel = kinematic_state_->twist.twist.linear.x;
const auto & current_acc = acceleration_->accel.accel.linear.x;
const auto acc_min = -decel_limit_input_->value();
const auto jerk_acc = jerk_input_->value();
const auto decel_dist = autoware::motion_utils::calcDecelDistWithJerkAndAccConstraints(

Check warning on line 200 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L198-L200

Added lines #L198 - L200 were not covered by tests
current_vel, 0., current_acc, acc_min, jerk_acc, -jerk_acc);
if (decel_dist > e.distance && e.distance >= 0 && e.status == VelocityFactor::APPROACHING) {

Check warning on line 202 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

VelocitySteeringFactorsPanel::onVelocityFactors has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
return COLOR_FREAK_PINK;

Check warning on line 203 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L203

Added line #L203 was not covered by tests
}
return {};
}();

Check warning on line 206 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L205-L206

Added lines #L205 - L206 were not covered by tests
for (int j = 0; j < velocity_factors_table_->columnCount(); j++) {
velocity_factors_table_->setItem(i, j, new QTableWidgetItem);
velocity_factors_table_->item(i, j)->setBackground(row_background);

Check warning on line 209 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp#L208-L209

Added lines #L208 - L209 were not covered by tests
}

Check warning on line 210 in common/tier4_state_rviz_plugin/src/velocity_steering_factors_panel.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

VelocitySteeringFactorsPanel::onVelocityFactors has a cyclomatic complexity of 12, threshold = 9. 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.
}
velocity_factors_table_->update();
}
Expand Down
Loading