Skip to content

Commit 7cc17df

Browse files
yuki-takagi-66Ariiees
authored andcommitted
feat(control_validator)!: add velocity check (autowarefoundation#7806)
* add velocity check --------- Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
1 parent b448478 commit 7cc17df

File tree

5 files changed

+65
-11
lines changed

5 files changed

+65
-11
lines changed

control/autoware_control_validator/README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ The `control_validator` is a module that checks the validity of the output of th
66

77
## Supported features
88

9-
The following features are supported for the validation and can have thresholds set by parameters:
9+
The following features are supported for the validation and can have thresholds set by parameters.
10+
The listed features below does not always correspond to the latest implementation.
11+
| Description | Arguments | Diagnostic equation | Implemented function name |
12+
| ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | :--------------------------------: | ------------------------------- |
13+
| Inverse velocity: Measured velocity has a different sign from the target velocity. | measured velocity $v$, target velocity $\hat{v}$, and threshold velocity parameter $k$ | $v\hat{v}<0,~\|v\|>k $ | `checkValidVelocityDeviation()` |
14+
| Overspeed: Measured speed exceeds target speed significantly. | measured velocity $v$, target velocity $\hat{v}$, and threshold ratio parameter $r$ | $\| v \| > (1 + r) \| \hat{v} \| $ | `checkValidVelocityDeviation()` |
1015

1116
- **Deviation check between reference trajectory and predicted trajectory** : invalid when the largest deviation between the predicted trajectory and reference trajectory is greater than the given threshold.
1217

1318
![trajectory_deviation](./image/trajectory_deviation.drawio.svg)
1419

15-
Other features are to be implemented.
16-
1720
## Inputs/Outputs
1821

1922
### Inputs
@@ -53,6 +56,8 @@ The following parameters can be set for the `control_validator`:
5356

5457
The input trajectory is detected as invalid if the index exceeds the following thresholds.
5558

56-
| Name | Type | Description | Default value |
57-
| :---------------------------------- | :----- | :---------------------------------------------------------------------------------------------------------- | :------------ |
58-
| `thresholds.max_distance_deviation` | double | invalid threshold of the max distance deviation between the predicted path and the reference trajectory [m] | 1.0 |
59+
| Name | Type | Description | Default value |
60+
| :----------------------------------- | :----- | :---------------------------------------------------------------------------------------------------------- | :------------ |
61+
| `thresholds.max_distance_deviation` | double | invalid threshold of the max distance deviation between the predicted path and the reference trajectory [m] | 1.0 |
62+
| `thresholds.max_reverse_velocity` | double | threshold velocity to valid the vehicle velocity [m/s] | WIP |
63+
| `thresholds.max_over_velocity_ratio` | double | threshold ratio to valid the vehicle velocity [*] | WIP |

control/autoware_control_validator/config/control_validator.param.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**:
22
ros__parameters:
3-
43
# If the number of consecutive invalid trajectory exceeds this threshold, the Diag will be set to ERROR.
54
# (For example, threshold = 1 means, even if the trajectory is invalid, Diag will not be ERROR if
65
# the next trajectory is valid.)
@@ -10,3 +9,5 @@
109

1110
thresholds:
1211
max_distance_deviation: 1.0
12+
max_reverse_velocity: 0.2
13+
max_over_velocity_ratio: 0.1

control/autoware_control_validator/include/autoware/control_validator/control_validator.hpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ using nav_msgs::msg::Odometry;
4242
struct ValidationParams
4343
{
4444
double max_distance_deviation_threshold;
45+
double max_reverse_velocity_threshold;
46+
double max_over_velocity_ratio_threshold;
4547
};
4648

4749
class ControlValidator : public rclcpp::Node
@@ -52,6 +54,8 @@ class ControlValidator : public rclcpp::Node
5254
void onPredictedTrajectory(const Trajectory::ConstSharedPtr msg);
5355

5456
bool checkValidMaxDistanceDeviation(const Trajectory & predicted_trajectory);
57+
bool checkValidVelocityDeviation(
58+
const Trajectory & reference_trajectory, const Odometry & kinematics);
5559

5660
private:
5761
void setupDiag();
@@ -60,7 +64,9 @@ class ControlValidator : public rclcpp::Node
6064

6165
bool isDataReady();
6266

63-
void validate(const Trajectory & trajectory);
67+
void validate(
68+
const Trajectory & predicted_trajectory, const Trajectory & reference_trajectory,
69+
const Odometry & kinematics);
6470

6571
void publishPredictedTrajectory();
6672
void publishDebugInfo();
@@ -85,6 +91,10 @@ class ControlValidator : public rclcpp::Node
8591
ControlValidatorStatus validation_status_;
8692
ValidationParams validation_params_; // for thresholds
8793

94+
// ego nearest index search
95+
double ego_nearest_dist_threshold_;
96+
double ego_nearest_yaw_threshold_;
97+
8898
autoware::vehicle_info_utils::VehicleInfo vehicle_info_;
8999

90100
bool isAllValid(const ControlValidatorStatus & status);

control/autoware_control_validator/msg/ControlValidatorStatus.msg

+3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ builtin_interfaces/Time stamp
22

33
# states
44
bool is_valid_max_distance_deviation
5+
bool is_valid_velocity_deviation
56

67
# values
78
float64 max_distance_deviation
9+
float64 desired_velocity
10+
float64 current_velocity
811

912
int64 invalid_count

control/autoware_control_validator/src/control_validator.cpp

+38-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "autoware/control_validator/control_validator.hpp"
1616

1717
#include "autoware/control_validator/utils.hpp"
18+
#include "autoware/motion_utils/trajectory/interpolation.hpp"
19+
#include "autoware/motion_utils/trajectory/trajectory.hpp"
1820

1921
#include <memory>
2022
#include <string>
@@ -51,6 +53,8 @@ void ControlValidator::setupParameters()
5153
auto & p = validation_params_;
5254
const std::string t = "thresholds.";
5355
p.max_distance_deviation_threshold = declare_parameter<double>(t + "max_distance_deviation");
56+
p.max_reverse_velocity_threshold = declare_parameter<double>(t + "reverse_velocity");
57+
p.max_over_velocity_ratio_threshold = declare_parameter<double>(t + "over_velocity_ratio");
5458
}
5559

5660
try {
@@ -88,6 +92,11 @@ void ControlValidator::setupDiag()
8892
stat, validation_status_.is_valid_max_distance_deviation,
8993
"control output is deviated from trajectory");
9094
});
95+
d.add(ns + "velocity_deviation", [&](auto & stat) {
96+
setStatus(
97+
stat, validation_status_.is_valid_velocity_deviation,
98+
"current velocity is deviated from the desired velocity");
99+
});
91100
}
92101

93102
bool ControlValidator::isDataReady()
@@ -119,7 +128,7 @@ void ControlValidator::onPredictedTrajectory(const Trajectory::ConstSharedPtr ms
119128

120129
debug_pose_publisher_->clearMarkers();
121130

122-
validate(*current_predicted_trajectory_);
131+
validate(*current_predicted_trajectory_, *current_reference_trajectory_, *current_kinematics_);
123132

124133
diag_updater_.force_update();
125134

@@ -142,7 +151,9 @@ void ControlValidator::publishDebugInfo()
142151
debug_pose_publisher_->publish();
143152
}
144153

145-
void ControlValidator::validate(const Trajectory & predicted_trajectory)
154+
void ControlValidator::validate(
155+
const Trajectory & predicted_trajectory, const Trajectory & reference_trajectory,
156+
const Odometry & kinematics)
146157
{
147158
if (predicted_trajectory.points.size() < 2) {
148159
RCLCPP_ERROR_THROTTLE(
@@ -154,6 +165,7 @@ void ControlValidator::validate(const Trajectory & predicted_trajectory)
154165
auto & s = validation_status_;
155166

156167
s.is_valid_max_distance_deviation = checkValidMaxDistanceDeviation(predicted_trajectory);
168+
s.is_valid_velocity_deviation = checkValidVelocityDeviation(reference_trajectory, kinematics);
157169

158170
s.invalid_count = isAllValid(s) ? 0 : s.invalid_count + 1;
159171
}
@@ -170,9 +182,32 @@ bool ControlValidator::checkValidMaxDistanceDeviation(const Trajectory & predict
170182
return true;
171183
}
172184

185+
bool ControlValidator::checkValidVelocityDeviation(
186+
const Trajectory & reference_trajectory, const Odometry & kinematics)
187+
{
188+
const double current_vel = kinematics.twist.twist.linear.x;
189+
if (reference_trajectory.points.size() < 2) return true;
190+
const double desired_vel =
191+
autoware::motion_utils::calcInterpolatedPoint(reference_trajectory, kinematics.pose.pose)
192+
.longitudinal_velocity_mps;
193+
194+
validation_status_.current_velocity = current_vel;
195+
validation_status_.desired_velocity = desired_vel;
196+
197+
const bool is_over_velocity =
198+
std::abs(current_vel) >
199+
std::abs(desired_vel) * (1.0 + validation_params_.max_over_velocity_ratio_threshold) +
200+
validation_params_.max_reverse_velocity_threshold;
201+
const bool is_reverse_velocity =
202+
std::signbit(current_vel * desired_vel) &&
203+
std::abs(current_vel) > validation_params_.max_reverse_velocity_threshold;
204+
205+
return !(is_over_velocity || is_reverse_velocity);
206+
}
207+
173208
bool ControlValidator::isAllValid(const ControlValidatorStatus & s)
174209
{
175-
return s.is_valid_max_distance_deviation;
210+
return s.is_valid_max_distance_deviation && s.is_valid_velocity_deviation;
176211
}
177212

178213
void ControlValidator::displayStatus()

0 commit comments

Comments
 (0)