Skip to content

Commit 811c099

Browse files
maxime-clemmkquda
authored andcommitted
feat(planning_validator): add yaw deviation metric (autowarefoundation#10258)
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent e3a4a0f commit 811c099

File tree

8 files changed

+58
-1
lines changed

8 files changed

+58
-1
lines changed

planning/autoware_planning_validator/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following features are supported for trajectory validation and can have thre
2020
- **Distance deviation** : invalid if the ego is too far from the trajectory
2121
- **Longitudinal distance deviation** : invalid if the trajectory is too far from ego in longitudinal direction
2222
- **Forward trajectory length** : invalid if the trajectory length is not enough to stop within a given deceleration
23+
- **Yaw difference** : invalid if the difference between the ego yaw and closest trajectory yaw is too large
2324

2425
The following features are to be implemented.
2526

@@ -77,6 +78,7 @@ The input trajectory is detected as invalid if the index exceeds the following t
7778
| `thresholds.steering_rate` | double | invalid threshold of the steering angle rate in each trajectory point [rad/s] | 10.0 |
7879
| `thresholds.velocity_deviation` | double | invalid threshold of the velocity deviation between the ego velocity and the trajectory point closest to ego [m/s] | 100.0 |
7980
| `thresholds.distance_deviation` | double | invalid threshold of the distance deviation between the ego position and the trajectory point closest to ego [m] | 100.0 |
81+
| `thresholds.yaw_deviation` | double | invalid threshold of the difference between the ego yaw and the closest trajectory yaw [rad] | 1.5708 |
8082
| `parameters.longitudinal_distance_deviation` | double | invalid threshold of the longitudinal distance deviation between the ego position and the trajectory [m] | 2.0 |
8183

8284
#### Parameters

planning/autoware_planning_validator/config/planning_validator.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
distance_deviation: 100.0
2929
longitudinal_distance_deviation: 1.0
3030
nominal_latency: 1.0
31+
yaw_deviation: 1.5708 # (= 90 degrees)
3132

3233
parameters:
3334
# The required trajectory length is calculated as the distance needed

planning/autoware_planning_validator/include/autoware/planning_validator/planning_validator.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct ValidationParams
6060
double distance_deviation_threshold;
6161
double longitudinal_distance_deviation_threshold;
6262
double nominal_latency_threshold;
63+
double yaw_deviation_threshold;
6364

6465
// parameters
6566
double forward_trajectory_length_acceleration;
@@ -88,6 +89,7 @@ class PlanningValidator : public rclcpp::Node
8889
bool checkValidLongitudinalDistanceDeviation(const Trajectory & trajectory);
8990
bool checkValidForwardTrajectoryLength(const Trajectory & trajectory);
9091
bool checkValidLatency(const Trajectory & trajectory);
92+
bool checkValidYawDeviation(const Trajectory & trajectory);
9193

9294
private:
9395
void setupDiag();

planning/autoware_planning_validator/msg/PlanningValidatorStatus.msg

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bool is_valid_distance_deviation
1616
bool is_valid_longitudinal_distance_deviation
1717
bool is_valid_forward_trajectory_length
1818
bool is_valid_latency
19+
bool is_valid_yaw_deviation
1920

2021
# values
2122
int64 trajectory_size
@@ -33,5 +34,6 @@ float64 longitudinal_distance_deviation
3334
float64 forward_trajectory_length_required
3435
float64 forward_trajectory_length_measured
3536
float64 latency
37+
float64 yaw_deviation
3638

3739
int64 invalid_count

planning/autoware_planning_validator/src/planning_validator.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
#include "autoware/planning_validator/utils.hpp"
1818

19+
#include <autoware/motion_utils/trajectory/interpolation.hpp>
1920
#include <autoware/motion_utils/trajectory/trajectory.hpp>
2021
#include <autoware_utils/geometry/geometry.hpp>
2122

23+
#include <angles/angles/angles.h>
24+
#include <tf2/utils.h>
25+
2226
#include <memory>
2327
#include <string>
2428
#include <utility>
@@ -81,6 +85,7 @@ void PlanningValidator::setupParameters()
8185
p.longitudinal_distance_deviation_threshold =
8286
declare_parameter<double>(t + "longitudinal_distance_deviation");
8387
p.nominal_latency_threshold = declare_parameter<double>(t + "nominal_latency");
88+
p.yaw_deviation_threshold = declare_parameter<double>(t + "yaw_deviation");
8489

8590
const std::string ps = "parameters.";
8691
p.forward_trajectory_length_acceleration =
@@ -172,6 +177,11 @@ void PlanningValidator::setupDiag()
172177
d->add(ns + "latency", [&](auto & stat) {
173178
setStatus(stat, validation_status_.is_valid_latency, "latency is larger than expected value.");
174179
});
180+
d->add(ns + "yaw_deviation", [&](auto & stat) {
181+
setStatus(
182+
stat, validation_status_.is_valid_yaw_deviation,
183+
"difference between vehicle yaw and closest trajectory yaw is too large.");
184+
});
175185
}
176186

177187
bool PlanningValidator::isDataReady()
@@ -324,6 +334,7 @@ void PlanningValidator::validate(const Trajectory & trajectory)
324334
s.is_valid_steering = checkValidSteering(resampled);
325335
s.is_valid_steering_rate = checkValidSteeringRate(resampled);
326336
s.is_valid_latency = checkValidLatency(trajectory);
337+
s.is_valid_yaw_deviation = checkValidYawDeviation(trajectory);
327338

328339
s.invalid_count = isAllValid(s) ? 0 : s.invalid_count + 1;
329340
}
@@ -555,14 +566,24 @@ bool PlanningValidator::checkValidLatency(const Trajectory & trajectory)
555566
return validation_status_.latency < validation_params_.nominal_latency_threshold;
556567
}
557568

569+
bool PlanningValidator::checkValidYawDeviation(const Trajectory & trajectory)
570+
{
571+
const auto interpolated_trajectory_point =
572+
motion_utils::calcInterpolatedPoint(trajectory, current_kinematics_->pose.pose);
573+
validation_status_.yaw_deviation = std::abs(angles::shortest_angular_distance(
574+
tf2::getYaw(interpolated_trajectory_point.pose.orientation),
575+
tf2::getYaw(current_kinematics_->pose.pose.orientation)));
576+
return validation_status_.yaw_deviation <= validation_params_.yaw_deviation_threshold;
577+
}
578+
558579
bool PlanningValidator::isAllValid(const PlanningValidatorStatus & s) const
559580
{
560581
return s.is_valid_size && s.is_valid_finite_value && s.is_valid_interval &&
561582
s.is_valid_relative_angle && s.is_valid_curvature && s.is_valid_lateral_acc &&
562583
s.is_valid_longitudinal_max_acc && s.is_valid_longitudinal_min_acc &&
563584
s.is_valid_steering && s.is_valid_steering_rate && s.is_valid_velocity_deviation &&
564585
s.is_valid_distance_deviation && s.is_valid_longitudinal_distance_deviation &&
565-
s.is_valid_forward_trajectory_length && s.is_valid_latency;
586+
s.is_valid_forward_trajectory_length && s.is_valid_latency && s.is_valid_yaw_deviation;
566587
}
567588

568589
void PlanningValidator::displayStatus()
@@ -594,6 +615,7 @@ void PlanningValidator::displayStatus()
594615
"planning trajectory is too far from ego in longitudinal direction!!");
595616
warn(s.is_valid_forward_trajectory_length, "planning trajectory forward length is not enough!!");
596617
warn(s.is_valid_latency, "planning component latency is larger than threshold!!");
618+
warn(s.is_valid_yaw_deviation, "planning trajectory yaw difference from ego yaw is too large!!");
597619
}
598620

599621
} // namespace autoware::planning_validator

planning/autoware_planning_validator/test/src/test_parameter.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ constexpr double THRESHOLD_VELOCITY_DEVIATION = 15.0 * kmph2mps;
3333
constexpr double THRESHOLD_DISTANCE_DEVIATION = 3.0;
3434
constexpr double THRESHOLD_LONGITUDINAL_DISTANCE_DEVIATION = 2.0;
3535
constexpr double THRESHOLD_NOMINAL_LATENCY = 1.0;
36+
constexpr double THRESHOLD_YAW_DEVIATION = 1.5708;
3637
constexpr double PARAMETER_FORWARD_TRAJECTORY_LENGTH_ACCELERATION = -5.0;
3738
constexpr double PARAMETER_FORWARD_TRAJECTORY_LENGTH_MARGIN = 2.0;
3839

planning/autoware_planning_validator/test/src/test_planning_validator_helper.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ rclcpp::NodeOptions getNodeOptionsWithDefaultParams()
211211
node_options.append_parameter_override(
212212
"thresholds.longitudinal_distance_deviation", THRESHOLD_LONGITUDINAL_DISTANCE_DEVIATION);
213213
node_options.append_parameter_override("thresholds.nominal_latency", THRESHOLD_NOMINAL_LATENCY);
214+
node_options.append_parameter_override("thresholds.yaw_deviation", THRESHOLD_YAW_DEVIATION);
214215
node_options.append_parameter_override(
215216
"parameters.forward_trajectory_length_acceleration",
216217
PARAMETER_FORWARD_TRAJECTORY_LENGTH_ACCELERATION);

planning/autoware_planning_validator/test/src/test_planning_validator_pubsub.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "test_parameter.hpp"
1717
#include "test_planning_validator_helper.hpp"
1818

19+
#include <autoware_utils/geometry/geometry.hpp>
1920
#include <rclcpp/rclcpp.hpp>
2021

2122
#include <nav_msgs/msg/odometry.hpp>
@@ -514,3 +515,28 @@ TEST(PlanningValidator, DiagCheckForwardTrajectoryLength)
514515
runWithBadTrajectory(bad_trajectory, ego_odom, diag_name);
515516
}
516517
}
518+
519+
TEST(PlanningValidator, DiagCheckYawDeviation)
520+
{
521+
const auto diag_name = "planning_validator: trajectory_validation_yaw_deviation";
522+
const auto straight_trajectory = generateTrajectory(1.0, 0.0, 0.0, 10);
523+
524+
// Ego with yaw deviation smaller than threshold -> must be OK
525+
{
526+
auto ego_odom = generateDefaultOdometry(0.0, 0.0, 0.0);
527+
for (auto yaw = 0.0; yaw <= THRESHOLD_YAW_DEVIATION; yaw += 0.1) {
528+
ego_odom.pose.pose.orientation = autoware_utils::create_quaternion_from_yaw(yaw);
529+
runWithOKTrajectory(straight_trajectory, ego_odom, diag_name);
530+
}
531+
}
532+
// Ego with yaw deviation larger than threshold -> must be NG
533+
{
534+
auto ego_odom = generateDefaultOdometry(0.0, 0.0, 0.0);
535+
for (auto yaw = THRESHOLD_YAW_DEVIATION + 1e-3; yaw < M_PI; yaw += 0.1) {
536+
ego_odom.pose.pose.orientation = autoware_utils::create_quaternion_from_yaw(yaw);
537+
runWithBadTrajectory(straight_trajectory, ego_odom, diag_name);
538+
ego_odom.pose.pose.orientation = autoware_utils::create_quaternion_from_yaw(-yaw);
539+
runWithBadTrajectory(straight_trajectory, ego_odom, diag_name);
540+
}
541+
}
542+
}

0 commit comments

Comments
 (0)