Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
Signed-off-by: xtk8532704 <[email protected]>
  • Loading branch information
xtk8532704 committed Jan 23, 2025
1 parent 96c7798 commit 02cc270
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ControlEvaluatorNode : public rclcpp::Node
void AddLaneletInfoMsg(const Pose & ego_pose);
void AddKinematicStateMetricMsg(
const Odometry & odom, const AccelWithCovarianceStamped & accel_stamped);
void AddSteeringMetricMsg(const SteeringReport & steering_report);

void onTimer();

Expand All @@ -97,7 +98,7 @@ class ControlEvaluatorNode : public rclcpp::Node
autoware::universe_utils::InterProcessPollingSubscriber<PathWithLaneId> behavior_path_subscriber_{
this, "~/input/behavior_path"};
autoware::universe_utils::InterProcessPollingSubscriber<SteeringReport> steering_sub_{
this, "~/input/steering_report"};
this, "~/input/steering_status"};

rclcpp::Publisher<autoware_internal_debug_msgs::msg::Float64Stamped>::SharedPtr
processing_time_pub_;
Expand All @@ -112,8 +113,16 @@ class ControlEvaluatorNode : public rclcpp::Node
// Metric
const std::vector<Metric> metrics_ = {
// collect all metrics
Metric::lateral_deviation, Metric::yaw_deviation, Metric::goal_longitudinal_deviation,
Metric::goal_lateral_deviation, Metric::goal_yaw_deviation,
Metric::lateral_deviation,
Metric::yaw_deviation,
Metric::goal_longitudinal_deviation,
Metric::goal_lateral_deviation,
Metric::goal_yaw_deviation,
Metric::left_boundary_distance,
Metric::right_boundary_distance,
Metric::steering_angle,
Metric::steering_rate,
Metric::steering_acceleration,
};

std::array<Accumulator<double>, static_cast<size_t>(Metric::SIZE)>
Expand All @@ -124,6 +133,9 @@ class ControlEvaluatorNode : public rclcpp::Node
autoware::route_handler::RouteHandler route_handler_;
rclcpp::TimerBase::SharedPtr timer_;
std::optional<AccelWithCovarianceStamped> prev_acc_stamped_{std::nullopt};
std::optional<double> prev_steering_angle_{std::nullopt};
std::optional<double> prev_steering_rate_{std::nullopt};
std::optional<double> prev_steering_angle_timestamp_{std::nullopt};
};
} // namespace control_diagnostics

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ enum class Metric {
goal_yaw_deviation,
left_boundary_distance,
right_boundary_distance,
steering_angle,
steering_rate,
steering_acceleration,
SIZE,
};

Expand All @@ -44,6 +47,9 @@ static const std::unordered_map<std::string, Metric> str_to_metric = {
{"goal_yaw_deviation", Metric::goal_yaw_deviation},
{"left_boundary_distance", Metric::left_boundary_distance},
{"right_boundary_distance", Metric::right_boundary_distance},
{"steering_angle", Metric::steering_angle},
{"steering_rate", Metric::steering_rate},
{"steering_acceleration", Metric::steering_acceleration},
};

static const std::unordered_map<Metric, std::string> metric_to_str = {
Expand All @@ -54,6 +60,9 @@ static const std::unordered_map<Metric, std::string> metric_to_str = {
{Metric::goal_yaw_deviation, "goal_yaw_deviation"},
{Metric::left_boundary_distance, "left_boundary_distance"},
{Metric::right_boundary_distance, "right_boundary_distance"},
{Metric::steering_angle, "steering_angle"},
{Metric::steering_rate, "steering_rate"},
{Metric::steering_acceleration, "steering_acceleration"},
};

// Metrics descriptions
Expand All @@ -65,6 +74,9 @@ static const std::unordered_map<Metric, std::string> metric_descriptions = {
{Metric::goal_yaw_deviation, "Yaw deviation from the goal point[rad]"},
{Metric::left_boundary_distance, "Signed distance to the left boundary[m]"},
{Metric::right_boundary_distance, "Signed distance to the right boundary[m]"},
{Metric::steering_angle, "Steering angle[rad]"},
{Metric::steering_rate, "Steering angle rate[rad/s]"},
{Metric::steering_acceleration, "Steering angle acceleration[rad/s^2]"},
};

namespace details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

#ifndef AUTOWARE__CONTROL_EVALUATOR__METRICS__METRICS_UTILS_HPP_
#define AUTOWARE__CONTROL_EVALUATOR__METRICS__METRICS_UTILS_HPP_

#include <autoware/route_handler/route_handler.hpp>
#include <autoware/universe_utils/geometry/boost_geometry.hpp>

#include <vector>

namespace control_diagnostics
{
namespace metrics
Expand Down
2 changes: 1 addition & 1 deletion evaluator/autoware_control_evaluator/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<depend>autoware_test_utils</depend>
<depend>autoware_universe_utils</depend>
<depend>autoware_vehicle_info_utils</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>nav_msgs</depend>
<depend>nlohmann-json-dev</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>tier4_metric_msgs</depend>
<depend>tier4_planning_msgs</depend>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,47 @@ void ControlEvaluatorNode::AddKinematicStateMetricMsg(
return;
}

void ControlEvaluatorNode::AddSteeringMetricMsg(const SteeringReport & steering_status)

Check warning on line 247 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L247

Added line #L247 was not covered by tests
{
// steering angle
double cur_steering_angle = steering_status.steering_tire_angle;
const double cur_t = static_cast<double>(steering_status.stamp.sec) +
static_cast<double>(steering_status.stamp.nanosec) * 1e-9;

Check warning on line 252 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L250-L252

Added lines #L250 - L252 were not covered by tests
AddMetricMsg(Metric::steering_angle, cur_steering_angle);

if (!prev_steering_angle_timestamp_.has_value()) {
prev_steering_angle_timestamp_ = cur_t;
prev_steering_angle_ = cur_steering_angle;
return;

Check warning on line 258 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L256-L258

Added lines #L256 - L258 were not covered by tests
}

// d_t
const double dt = cur_t - prev_steering_angle_timestamp_.value();

Check warning on line 262 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L262

Added line #L262 was not covered by tests
if (dt < std::numeric_limits<double>::epsilon()) {
prev_steering_angle_timestamp_ = cur_t;
prev_steering_angle_ = cur_steering_angle;
return;

Check warning on line 266 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L264-L266

Added lines #L264 - L266 were not covered by tests
}

// steering rate
const double steering_rate = (cur_steering_angle - prev_steering_angle_.value()) / dt;
AddMetricMsg(Metric::steering_rate, steering_rate);

// steering acceleration
if (!prev_steering_rate_.has_value()) {
prev_steering_angle_timestamp_ = cur_t;
prev_steering_angle_ = cur_steering_angle;
prev_steering_rate_ = steering_rate;
return;

Check warning on line 278 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L275-L278

Added lines #L275 - L278 were not covered by tests
}
const double steering_acceleration = (steering_rate - prev_steering_rate_.value()) / dt;
AddMetricMsg(Metric::steering_acceleration, steering_acceleration);

Check warning on line 281 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L280-L281

Added lines #L280 - L281 were not covered by tests

prev_steering_angle_timestamp_ = cur_t;
prev_steering_angle_ = cur_steering_angle;
prev_steering_rate_ = steering_rate;

Check warning on line 285 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L283-L285

Added lines #L283 - L285 were not covered by tests
}

void ControlEvaluatorNode::AddLateralDeviationMetricMsg(
const Trajectory & traj, const Point & ego_point)
{
Expand Down Expand Up @@ -294,7 +335,7 @@ void ControlEvaluatorNode::onTimer()
const auto odom = odometry_sub_.takeData();
const auto acc = accel_sub_.takeData();
const auto behavior_path = behavior_path_subscriber_.takeData();
const auto steering_ = steering_sub_.takeData();
const auto steering_status = steering_sub_.takeData();

// calculate deviation metrics
if (odom && traj && !traj->points.empty()) {
Expand All @@ -320,8 +361,8 @@ void ControlEvaluatorNode::onTimer()
const Pose ego_pose = odom->pose.pose;

Check warning on line 361 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

Codecov / codecov/patch

evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp#L361

Added line #L361 was not covered by tests
AddBoundaryDistanceMetricMsg(*behavior_path, ego_pose);
}
if (steering_) {
//TODO think and add metric(steering_angle, the difference between the steering angle and the previous steering angle,etc)
if (steering_status) {
AddSteeringMetricMsg(*steering_status);
}

Check warning on line 366 in evaluator/autoware_control_evaluator/src/control_evaluator_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

ControlEvaluatorNode::onTimer has a cyclomatic complexity of 11, 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.
// Publish metrics
metrics_msg_.stamp = now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <lanelet2_core/Forward.h>

#include <cstddef>
#include <vector>
namespace control_diagnostics
{
namespace metrics
Expand Down

0 comments on commit 02cc270

Please sign in to comment.