-
Notifications
You must be signed in to change notification settings - Fork 682
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(planning_validator): add validation for trajectory length and related tests #6195
Changes from 9 commits
a360bd0
07c2171
25100bb
5c2aca6
0b931d1
9fe4e8c
081109d
7a10058
720abf3
465fbe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,14 @@ | |
p.steering_rate_threshold = declare_parameter<double>(t + "steering_rate"); | ||
p.velocity_deviation_threshold = declare_parameter<double>(t + "velocity_deviation"); | ||
p.distance_deviation_threshold = declare_parameter<double>(t + "distance_deviation"); | ||
p.longitudinal_distance_deviation_threshold = | ||
declare_parameter<double>(t + "longitudinal_distance_deviation"); | ||
|
||
const std::string ps = "parameters."; | ||
p.forward_trajectory_length_acceleration = | ||
declare_parameter<double>(ps + "forward_trajectory_length_acceleration"); | ||
p.forward_trajectory_length_margin = | ||
declare_parameter<double>(ps + "forward_trajectory_length_margin"); | ||
} | ||
|
||
try { | ||
|
@@ -148,6 +156,20 @@ | |
setStatus( | ||
stat, validation_status_.is_valid_velocity_deviation, "velocity deviation is too large"); | ||
}); | ||
d->add(ns + "distance_deviation", [&](auto & stat) { | ||
setStatus( | ||
stat, validation_status_.is_valid_distance_deviation, "distance deviation is too large"); | ||
}); | ||
d->add(ns + "longitudinal_distance_deviation", [&](auto & stat) { | ||
setStatus( | ||
stat, validation_status_.is_valid_longitudinal_distance_deviation, | ||
"longitudinal distance deviation is too large"); | ||
}); | ||
d->add(ns + "forward_trajectory_length", [&](auto & stat) { | ||
setStatus( | ||
stat, validation_status_.is_valid_forward_trajectory_length, | ||
"trajectory length is too short"); | ||
}); | ||
} | ||
|
||
bool PlanningValidator::isDataReady() | ||
|
@@ -280,6 +302,8 @@ | |
s.is_valid_longitudinal_min_acc = checkValidMinLongitudinalAcceleration(trajectory); | ||
s.is_valid_velocity_deviation = checkValidVelocityDeviation(trajectory); | ||
s.is_valid_distance_deviation = checkValidDistanceDeviation(trajectory); | ||
s.is_valid_longitudinal_distance_deviation = checkValidLongitudinalDistanceDeviation(trajectory); | ||
s.is_valid_forward_trajectory_length = checkValidForwardTrajectoryLength(trajectory); | ||
|
||
// use resampled trajectory because the following metrics can not be evaluated for closed points. | ||
// Note: do not interpolate to keep original trajectory shape. | ||
|
@@ -294,8 +318,9 @@ | |
s.invalid_count = isAllValid(s) ? 0 : s.invalid_count + 1; | ||
} | ||
|
||
bool PlanningValidator::checkValidSize(const Trajectory & trajectory) const | ||
bool PlanningValidator::checkValidSize(const Trajectory & trajectory) | ||
{ | ||
validation_status_.trajectory_size = trajectory.points.size(); | ||
return trajectory.points.size() >= 2; | ||
} | ||
|
||
|
@@ -447,13 +472,84 @@ | |
return true; | ||
} | ||
|
||
bool PlanningValidator::checkValidLongitudinalDistanceDeviation(const Trajectory & trajectory) | ||
{ | ||
if (trajectory.points.size() < 2) { | ||
RCLCPP_ERROR(get_logger(), "Trajectory size is invalid to calculate distance deviation."); | ||
return false; | ||
} | ||
|
||
const auto ego_pose = current_kinematics_->pose.pose; | ||
const size_t idx = | ||
motion_utils::findFirstNearestIndexWithSoftConstraints(trajectory.points, ego_pose); | ||
|
||
if (0 < idx && idx < trajectory.points.size() - 1) { | ||
return true; // ego-nearest point exists between trajectory points. | ||
} | ||
|
||
// Check if the valid longitudinal deviation for given segment index | ||
const auto HasValidLongitudinalDeviation = [&](const size_t seg_idx, const bool is_last) { | ||
auto long_offset = | ||
motion_utils::calcLongitudinalOffsetToSegment(trajectory.points, seg_idx, ego_pose.position); | ||
|
||
// for last, need to remove distance for the last segment. | ||
if (is_last) { | ||
const auto size = trajectory.points.size(); | ||
long_offset -= tier4_autoware_utils::calcDistance2d( | ||
trajectory.points.at(size - 1), trajectory.points.at(size - 2)); | ||
} | ||
|
||
validation_status_.longitudinal_distance_deviation = long_offset; | ||
return std::abs(validation_status_.longitudinal_distance_deviation) < | ||
validation_params_.longitudinal_distance_deviation_threshold; | ||
}; | ||
|
||
// Make sure the trajectory is far AHEAD from ego. | ||
if (idx == 0) { | ||
const auto seg_idx = 0; | ||
return HasValidLongitudinalDeviation(seg_idx, false); | ||
} | ||
|
||
// Make sure the trajectory is far BEHIND from ego. | ||
if (idx == trajectory.points.size() - 1) { | ||
const auto seg_idx = trajectory.points.size() - 2; | ||
return HasValidLongitudinalDeviation(seg_idx, true); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool PlanningValidator::checkValidForwardTrajectoryLength(const Trajectory & trajectory) | ||
{ | ||
const auto ego_speed = std::abs(current_kinematics_->twist.twist.linear.x); | ||
if (ego_speed < 1.0 / 3.6) { | ||
return true; // Ego is almost stopped. | ||
} | ||
|
||
const auto forward_length = motion_utils::calcSignedArcLength( | ||
trajectory.points, current_kinematics_->pose.pose.position, trajectory.points.size() - 1); | ||
|
||
const auto acc = validation_params_.forward_trajectory_length_acceleration; | ||
const auto forward_length_required = ego_speed * ego_speed / (2.0 * std::abs(acc)) - | ||
validation_params_.forward_trajectory_length_margin; | ||
|
||
std::cerr << "forward_length_required = " << forward_length_required | ||
<< ", forward_length = " << forward_length << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I removed it. |
||
|
||
validation_status_.forward_trajectory_length_required = forward_length_required; | ||
validation_status_.forward_trajectory_length_measured = forward_length; | ||
|
||
return forward_length > forward_length_required; | ||
} | ||
|
||
bool PlanningValidator::isAllValid(const PlanningValidatorStatus & s) const | ||
{ | ||
return s.is_valid_size && s.is_valid_finite_value && s.is_valid_interval && | ||
s.is_valid_relative_angle && s.is_valid_curvature && s.is_valid_lateral_acc && | ||
s.is_valid_longitudinal_max_acc && s.is_valid_longitudinal_min_acc && | ||
s.is_valid_steering && s.is_valid_steering_rate && s.is_valid_velocity_deviation && | ||
s.is_valid_distance_deviation; | ||
s.is_valid_distance_deviation && s.is_valid_longitudinal_distance_deviation && | ||
s.is_valid_forward_trajectory_length; | ||
Check warning on line 552 in planning/planning_validator/src/planning_validator.cpp
|
||
} | ||
|
||
void PlanningValidator::displayStatus() | ||
|
@@ -470,7 +566,6 @@ | |
|
||
warn(s.is_valid_size, "planning trajectory size is invalid, too small."); | ||
warn(s.is_valid_curvature, "planning trajectory curvature is too large!!"); | ||
warn(s.is_valid_distance_deviation, "planning trajectory is too far from ego!!"); | ||
warn(s.is_valid_finite_value, "planning trajectory has invalid value!!"); | ||
warn(s.is_valid_interval, "planning trajectory interval is too long!!"); | ||
warn(s.is_valid_lateral_acc, "planning trajectory lateral acceleration is too high!!"); | ||
|
@@ -480,6 +575,11 @@ | |
warn(s.is_valid_steering, "planning trajectory expected steering angle is too high!!"); | ||
warn(s.is_valid_steering_rate, "planning trajectory expected steering angle rate is too high!!"); | ||
warn(s.is_valid_velocity_deviation, "planning trajectory velocity deviation is too high!!"); | ||
warn(s.is_valid_distance_deviation, "planning trajectory is too far from ego!!"); | ||
warn( | ||
s.is_valid_longitudinal_distance_deviation, | ||
"planning trajectory is too far from ego in longitudinal direction!!"); | ||
warn(s.is_valid_forward_trajectory_length, "planning trajectory forward length is not enough!!"); | ||
} | ||
|
||
} // namespace planning_validator | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,7 +296,7 @@ std::pair<double, size_t> calcMaxSteeringRates( | |
const auto steer_next = steering_array.at(i + 1); | ||
|
||
const auto steer_rate = (steer_next - steer_prev) / dt; | ||
takeBigger(max_steering_rate, max_index, steer_rate, i); | ||
takeBigger(max_steering_rate, max_index, std::abs(steer_rate), i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix bug. |
||
} | ||
|
||
return {max_steering_rate, max_index}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef TEST_PARAMETER_HPP_ | ||
#define TEST_PARAMETER_HPP_ | ||
|
||
constexpr double deg2rad = 3.14159265 / 180.0; | ||
constexpr double kmph2mps = 1.0 / 3.6; | ||
|
||
constexpr double WHEELBASE = 3.5; | ||
|
||
constexpr double THRESHOLD_INTERVAL = 1.0; | ||
constexpr double THRESHOLD_RELATIVE_ANGLE = 115.0 * deg2rad; | ||
constexpr double THRESHOLD_CURVATURE = 0.3; | ||
constexpr double THRESHOLD_LATERAL_ACC = 5.0; | ||
constexpr double THRESHOLD_LONGITUDINAL_MAX_ACC = 3.0; | ||
constexpr double THRESHOLD_LONGITUDINAL_MIN_ACC = -6.0; | ||
constexpr double THRESHOLD_STEERING = 35.0 * deg2rad; | ||
constexpr double THRESHOLD_STEERING_RATE = 7.0 * deg2rad; | ||
constexpr double THRESHOLD_VELOCITY_DEVIATION = 15.0 * kmph2mps; | ||
constexpr double THRESHOLD_DISTANCE_DEVIATION = 3.0; | ||
constexpr double THRESHOLD_LONGITUDINAL_DISTANCE_DEVIATION = 2.0; | ||
constexpr double PARAMETER_FORWARD_TRAJECTORY_LENGTH_ACCELERATION = -5.0; | ||
constexpr double PARAMETER_FORWARD_TRAJECTORY_LENGTH_MARGIN = 2.0; | ||
|
||
#endif // TEST_PARAMETER_HPP_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add missing diagnostic