19
19
#include " autoware/motion_utils/trajectory/trajectory.hpp"
20
20
#include " autoware_vehicle_info_utils/vehicle_info_utils.hpp"
21
21
22
- #include < nav_msgs/msg/odometry.hpp>
23
-
24
22
#include < algorithm>
25
23
#include < cstdint>
26
24
#include < memory>
@@ -31,6 +29,31 @@ namespace autoware::control_validator
31
29
{
32
30
using diagnostic_msgs::msg::DiagnosticStatus;
33
31
32
+ void AccelerationValidator::validate (
33
+ ControlValidatorStatus & res, const Odometry & kinematic_state, const Control & control_cmd,
34
+ const AccelWithCovarianceStamped & loc_acc)
35
+ {
36
+ desired_acc_lpf.filter (
37
+ control_cmd.longitudinal .acceleration +
38
+ 9.8 * autoware_utils::get_rpy (kinematic_state.pose .pose ).y );
39
+ measured_acc_lpf.filter (loc_acc.accel .accel .linear .x );
40
+ if (std::abs (kinematic_state.twist .twist .linear .x ) < 1e-3 ) {
41
+ desired_acc_lpf.reset (0.0 );
42
+ measured_acc_lpf.reset (0.0 );
43
+ }
44
+
45
+ res.desired_acc = desired_acc_lpf.getValue ().value ();
46
+ res.measured_acc = measured_acc_lpf.getValue ().value ();
47
+ res.is_valid_acc = [this ]() {
48
+ const double des = desired_acc_lpf.getValue ().value ();
49
+ const double mes = measured_acc_lpf.getValue ().value ();
50
+ const int8_t des_sign = std::signbit (des) ? 1 : -1 ;
51
+
52
+ return mes <= des * (1 + des_sign * e_scale) + e_offset &&
53
+ mes >= des * (1 - des_sign * e_scale) + e_offset;
54
+ }();
55
+ }
56
+
34
57
ControlValidator::ControlValidator (const rclcpp::NodeOptions & options)
35
58
: Node(" control_validator" , options), validation_params_(), vehicle_info_()
36
59
{
@@ -47,6 +70,9 @@ ControlValidator::ControlValidator(const rclcpp::NodeOptions & options)
47
70
sub_reference_traj_ =
48
71
autoware_utils::InterProcessPollingSubscriber<Trajectory>::create_subscription (
49
72
this , " ~/input/reference_trajectory" , 1 );
73
+ sub_measured_acc_ =
74
+ autoware_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped>::create_subscription (
75
+ this , " ~/input/measured_acceleration" , 1 );
50
76
51
77
pub_status_ = create_publisher<ControlValidatorStatus>(" ~/output/validation_status" , 1 );
52
78
@@ -77,9 +103,10 @@ void ControlValidator::setup_parameters()
77
103
p.overrun_stop_point_dist = declare_parameter<double >(t + " overrun_stop_point_dist" );
78
104
p.nominal_latency_threshold = declare_parameter<double >(t + " nominal_latency" );
79
105
}
80
- const auto lpf_gain = declare_parameter<double >(" vel_lpf_gain" );
81
- vehicle_vel_.setGain (lpf_gain);
82
- target_vel_.setGain (lpf_gain);
106
+
107
+ const auto vel_lpf_gain = declare_parameter<double >(" vel_lpf_gain" );
108
+ vehicle_vel_.setGain (vel_lpf_gain);
109
+ target_vel_.setGain (vel_lpf_gain);
83
110
84
111
hold_velocity_error_until_stop_ = declare_parameter<bool >(" hold_velocity_error_until_stop" );
85
112
@@ -122,6 +149,11 @@ void ControlValidator::setup_diag()
122
149
stat, validation_status_.is_valid_max_distance_deviation ,
123
150
" control output is deviated from trajectory" );
124
151
});
152
+ d.add (ns + " acceleration_error" , [&](auto & stat) {
153
+ set_status (
154
+ stat, validation_status_.is_valid_acc ,
155
+ " Measured acceleration and desired acceleration is deviated" );
156
+ });
125
157
d.add (ns + " rolling_back" , [&](auto & stat) {
126
158
set_status (
127
159
stat, !validation_status_.is_rolling_back ,
@@ -159,14 +191,23 @@ bool ControlValidator::is_data_ready()
159
191
if (!current_predicted_trajectory_) {
160
192
return waiting (sub_predicted_traj_->get_topic_name ());
161
193
}
194
+ if (!acceleration_msg_) {
195
+ return waiting (sub_measured_acc_->subscriber ()->get_topic_name ());
196
+ }
197
+ if (!control_cmd_msg_) {
198
+ return waiting (sub_control_cmd_->get_topic_name ());
199
+ }
162
200
return true ;
163
201
}
164
202
165
203
void ControlValidator::on_control_cmd (const Control::ConstSharedPtr msg)
166
204
{
205
+ control_cmd_msg_ = msg;
206
+
167
207
validation_status_.latency = (this ->now () - msg->stamp ).seconds ();
168
208
validation_status_.is_valid_latency =
169
209
validation_status_.latency < validation_params_.nominal_latency_threshold ;
210
+
170
211
validation_status_.invalid_count =
171
212
is_all_valid (validation_status_) ? 0 : validation_status_.invalid_count + 1 ;
172
213
}
@@ -178,12 +219,15 @@ void ControlValidator::on_predicted_trajectory(const Trajectory::ConstSharedPtr
178
219
current_predicted_trajectory_ = msg;
179
220
current_reference_trajectory_ = sub_reference_traj_->take_data ();
180
221
current_kinematics_ = sub_kinematics_->take_data ();
222
+ acceleration_msg_ = sub_measured_acc_->take_data ();
181
223
182
224
if (!is_data_ready ()) return ;
183
225
184
226
debug_pose_publisher_->clear_markers ();
185
227
186
- validate (*current_predicted_trajectory_, *current_reference_trajectory_, *current_kinematics_);
228
+ validate (
229
+ *current_predicted_trajectory_, *current_reference_trajectory_, *current_kinematics_,
230
+ *control_cmd_msg_, *acceleration_msg_);
187
231
188
232
diag_updater_.force_update ();
189
233
@@ -213,7 +257,8 @@ void ControlValidator::publish_debug_info()
213
257
214
258
void ControlValidator::validate (
215
259
const Trajectory & predicted_trajectory, const Trajectory & reference_trajectory,
216
- const Odometry & kinematics)
260
+ const Odometry & kinematics, const Control & control_cmd,
261
+ const AccelWithCovarianceStamped & measured_acc)
217
262
{
218
263
if (predicted_trajectory.points .size () < 2 ) {
219
264
RCLCPP_DEBUG (get_logger (), " predicted_trajectory size is less than 2. Cannot validate." );
@@ -232,7 +277,7 @@ void ControlValidator::validate(
232
277
std::tie (
233
278
validation_status_.max_distance_deviation , validation_status_.is_valid_max_distance_deviation ) =
234
279
calc_lateral_deviation_status (predicted_trajectory, *current_reference_trajectory_);
235
-
280
+ acceleration_validator. validate (validation_status_, kinematics, control_cmd, measured_acc);
236
281
calc_velocity_deviation_status (*current_reference_trajectory_, kinematics);
237
282
calc_stop_point_overrun_status (*current_reference_trajectory_, kinematics);
238
283
@@ -310,8 +355,8 @@ void ControlValidator::calc_stop_point_overrun_status(
310
355
311
356
bool ControlValidator::is_all_valid (const ControlValidatorStatus & s)
312
357
{
313
- return s.is_valid_max_distance_deviation && !s. is_rolling_back && !s.is_over_velocity &&
314
- !s.has_overrun_stop_point ;
358
+ return s.is_valid_max_distance_deviation && s. is_valid_acc && !s.is_rolling_back &&
359
+ !s.is_over_velocity && !s. has_overrun_stop_point ;
315
360
}
316
361
317
362
void ControlValidator::display_status ()
0 commit comments