Skip to content

Commit

Permalink
fix(obstacle_velocity_limiter): only show the 1st virtual wall
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime CLEMENT <[email protected]>
  • Loading branch information
maxime-clem committed Aug 15, 2024
1 parent a612530 commit c1fc313
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
namespace autoware::motion_velocity_planner::obstacle_velocity_limiter
{

double calculateSafeVelocity(
const TrajectoryPoint & trajectory_point, const double dist_to_collision,
const double time_buffer, const double min_adjusted_velocity)
{
return std::min(
static_cast<double>(trajectory_point.longitudinal_velocity_mps),
std::max(min_adjusted_velocity, dist_to_collision / time_buffer));
}

multi_polygon_t createPolygonMasks(
const autoware_perception_msgs::msg::PredictedObjects & dynamic_obstacles, const double buffer,
const double min_vel)
Expand Down Expand Up @@ -123,36 +114,35 @@ std::vector<autoware::motion_velocity_planner::SlowdownInterval> calculate_slowd
autoware::motion_utils::VirtualWalls & virtual_walls)
{
std::vector<autoware::motion_velocity_planner::SlowdownInterval> slowdown_intervals;
double time = 0.0;
size_t previous_slowdown_index = trajectory.size();
for (size_t i = 0; i < trajectory.size(); ++i) {
auto & trajectory_point = trajectory[i];
if (i > 0) {
const auto & prev_point = trajectory[i - 1];
time += static_cast<double>(
autoware::universe_utils::calcDistance2d(prev_point, trajectory_point) /
prev_point.longitudinal_velocity_mps);
}
// First linestring is used to calculate distance
if (projections[i].empty()) continue;
projection_params.update(trajectory_point);
const auto dist_to_collision = distanceToClosestCollision(
projections[i][0], footprints[i], collision_checker, projection_params);
if (dist_to_collision) {
const auto min_feasible_velocity =
velocity_params.current_ego_velocity - velocity_params.max_deceleration * time;

velocity_params.current_ego_velocity -
velocity_params.max_deceleration *

Check warning on line 128 in planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp

View check run for this annotation

Codecov / codecov/patch

planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp#L127-L128

Added lines #L127 - L128 were not covered by tests
rclcpp::Duration(trajectory_point.time_from_start).seconds();

const auto safe_velocity = std::max(
static_cast<double>(*dist_to_collision - projection_params.extra_length) /
static_cast<double>(projection_params.duration),

Check warning on line 133 in planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp

View check run for this annotation

Codecov / codecov/patch

planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp#L131-L133

Added lines #L131 - L133 were not covered by tests
velocity_params.min_velocity);
slowdown_intervals.emplace_back(
trajectory_point.pose.position, trajectory_point.pose.position,
std::max(
min_feasible_velocity,
calculateSafeVelocity(
trajectory_point,
static_cast<double>(*dist_to_collision - projection_params.extra_length),
static_cast<double>(projection_params.duration), velocity_params.min_velocity)));

autoware::motion_utils::VirtualWall wall;
wall.pose = trajectory_point.pose;
virtual_walls.push_back(wall);
std::max(min_feasible_velocity, safe_velocity));

// with consecutive slowdowns only add a virtual wall for the first one
if (previous_slowdown_index + 1 != i) {
autoware::motion_utils::VirtualWall wall;
wall.pose = trajectory_point.pose;

Check warning on line 142 in planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp

View check run for this annotation

Codecov / codecov/patch

planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp#L142

Added line #L142 was not covered by tests
virtual_walls.push_back(wall);
}
previous_slowdown_index = i;

Check warning on line 145 in planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/src/obstacle_velocity_limiter.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

calculate_slowdown_intervals has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
}
}
return slowdown_intervals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@
#include <autoware_perception_msgs/msg/predicted_objects.hpp>
#include <nav_msgs/msg/occupancy_grid.hpp>

#include <string>
#include <vector>

namespace autoware::motion_velocity_planner::obstacle_velocity_limiter
{

/// @brief calculate the apparent safe velocity
/// @param[in] trajectory_point trajectory point for which to calculate the apparent safe velocity
/// @param[in] dist_to_collision distance from the trajectory point to the apparent collision
/// @return apparent safe velocity
double calculateSafeVelocity(
const TrajectoryPoint & trajectory_point, const double dist_to_collision);

/// @brief calculate trajectory index that is ahead of the given index by the given distance
/// @param[in] trajectory trajectory
/// @param[in] ego_idx index closest to the current ego position in the trajectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "obstacle_velocity_limiter_module.hpp"

#include "debug.hpp"
#include "forward_projection.hpp"
#include "map_utils.hpp"
#include "obstacle_velocity_limiter.hpp"
#include "parameters.hpp"
Expand All @@ -32,7 +31,6 @@

#include <boost/geometry.hpp>

#include <algorithm>
#include <chrono>
#include <map>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool MotionVelocityPlannerNode::update_planner_data()
const auto check_with_log = [&](const auto ptr, const auto & log) {
constexpr auto throttle_duration = 3000; // [ms]
if (!ptr) {
RCLCPP_INFO_THROTTLE(get_logger(), clock, throttle_duration, log);
RCLCPP_INFO_THROTTLE(get_logger(), clock, throttle_duration, "%s", log);

Check warning on line 137 in planning/motion_velocity_planner/autoware_motion_velocity_planner_node/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

planning/motion_velocity_planner/autoware_motion_velocity_planner_node/src/node.cpp#L137

Added line #L137 was not covered by tests
is_ready = false;
return false;
}
Expand Down Expand Up @@ -324,8 +324,12 @@ void MotionVelocityPlannerNode::insert_slowdown(
const auto to_insert_idx =
autoware::motion_utils::insertTargetPoint(to_seg_idx, slowdown_interval.to, trajectory.points);
if (from_insert_idx && to_insert_idx) {
for (auto idx = *from_insert_idx; idx <= *to_insert_idx; ++idx)
trajectory.points[idx].longitudinal_velocity_mps = slowdown_interval.velocity;
for (auto idx = *from_insert_idx; idx <= *to_insert_idx; ++idx) {
trajectory.points[idx].longitudinal_velocity_mps =
std::min( // prevent the node from increasing the velocity

Check warning on line 329 in planning/motion_velocity_planner/autoware_motion_velocity_planner_node/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

planning/motion_velocity_planner/autoware_motion_velocity_planner_node/src/node.cpp#L328-L329

Added lines #L328 - L329 were not covered by tests
trajectory.points[idx].longitudinal_velocity_mps,
static_cast<float>(slowdown_interval.velocity));
}
} else {
RCLCPP_WARN(get_logger(), "Failed to insert slowdown point");
}
Expand Down

0 comments on commit c1fc313

Please sign in to comment.