Skip to content

Commit a5a4328

Browse files
fix(control validator): combine callback functions to fix error count increment bug (autowarefoundation#10355)
Signed-off-by: yuki-takagi-66 <yuki.takagi@tier4.jp>
1 parent 5fec240 commit a5a4328

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ class ControlValidator : public rclcpp::Node
190190

191191
// Subscribers and publishers
192192
rclcpp::Subscription<Control>::SharedPtr sub_control_cmd_;
193-
rclcpp::Subscription<Trajectory>::SharedPtr sub_predicted_traj_;
194193
autoware_utils::InterProcessPollingSubscriber<Odometry>::SharedPtr sub_kinematics_;
195194
autoware_utils::InterProcessPollingSubscriber<Trajectory>::SharedPtr sub_reference_traj_;
195+
autoware_utils::InterProcessPollingSubscriber<Trajectory>::SharedPtr sub_predicted_traj_;
196196
autoware_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped>::SharedPtr
197197
sub_measured_acc_;
198198
rclcpp::Publisher<ControlValidatorStatus>::SharedPtr pub_status_;

control/autoware_control_validator/src/control_validator.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ ControlValidator::ControlValidator(const rclcpp::NodeOptions & options)
6363

6464
sub_control_cmd_ = create_subscription<Control>(
6565
"~/input/control_cmd", 1, std::bind(&ControlValidator::on_control_cmd, this, _1));
66-
sub_predicted_traj_ = create_subscription<Trajectory>(
67-
"~/input/predicted_trajectory", 1,
68-
std::bind(&ControlValidator::on_predicted_trajectory, this, _1));
6966
sub_kinematics_ =
7067
autoware_utils::InterProcessPollingSubscriber<nav_msgs::msg::Odometry>::create_subscription(
7168
this, "~/input/kinematics", 1);
7269
sub_reference_traj_ =
7370
autoware_utils::InterProcessPollingSubscriber<Trajectory>::create_subscription(
7471
this, "~/input/reference_trajectory", 1);
72+
sub_predicted_traj_ =
73+
autoware_utils::InterProcessPollingSubscriber<Trajectory>::create_subscription(
74+
this, "~/input/predicted_trajectory", 1);
7575
sub_measured_acc_ =
7676
autoware_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped>::create_subscription(
7777
this, "~/input/measured_acceleration", 1);
@@ -191,7 +191,7 @@ bool ControlValidator::is_data_ready()
191191
return waiting(sub_reference_traj_->subscriber()->get_topic_name());
192192
}
193193
if (!current_predicted_trajectory_) {
194-
return waiting(sub_predicted_traj_->get_topic_name());
194+
return waiting(sub_reference_traj_->subscriber()->get_topic_name());
195195
}
196196
if (!acceleration_msg_) {
197197
return waiting(sub_measured_acc_->subscriber()->get_topic_name());
@@ -203,22 +203,11 @@ bool ControlValidator::is_data_ready()
203203
}
204204

205205
void ControlValidator::on_control_cmd(const Control::ConstSharedPtr msg)
206-
{
207-
control_cmd_msg_ = msg;
208-
209-
validation_status_.latency = (this->now() - msg->stamp).seconds();
210-
validation_status_.is_valid_latency =
211-
validation_status_.latency < validation_params_.nominal_latency_threshold;
212-
213-
validation_status_.invalid_count =
214-
is_all_valid(validation_status_) ? 0 : validation_status_.invalid_count + 1;
215-
}
216-
217-
void ControlValidator::on_predicted_trajectory(const Trajectory::ConstSharedPtr msg)
218206
{
219207
stop_watch.tic();
220208

221-
current_predicted_trajectory_ = msg;
209+
control_cmd_msg_ = msg;
210+
current_predicted_trajectory_ = sub_predicted_traj_->take_data();
222211
current_reference_trajectory_ = sub_reference_traj_->take_data();
223212
current_kinematics_ = sub_kinematics_->take_data();
224213
acceleration_msg_ = sub_measured_acc_->take_data();
@@ -227,6 +216,10 @@ void ControlValidator::on_predicted_trajectory(const Trajectory::ConstSharedPtr
227216

228217
debug_pose_publisher_->clear_markers();
229218

219+
validation_status_.latency = (this->now() - msg->stamp).seconds();
220+
validation_status_.is_valid_latency =
221+
validation_status_.latency < validation_params_.nominal_latency_threshold;
222+
230223
validate(
231224
*current_predicted_trajectory_, *current_reference_trajectory_, *current_kinematics_,
232225
*control_cmd_msg_, *acceleration_msg_);

0 commit comments

Comments
 (0)