Skip to content
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(object_merger): add diagnostics warning for timeout when merging #10283

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
remove_overlapped_unknown_objects: true
base_link_frame_id: base_link
priority_mode: 2 # PriorityMode::Confidence
message_timeout_sec: 0.15
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "autoware_utils/ros/published_time_publisher.hpp"
#include "autoware_utils/system/stop_watch.hpp"

#include <autoware_utils/ros/diagnostics_interface.hpp>
#include <rclcpp/rclcpp.hpp>

#include "autoware_perception_msgs/msg/detected_objects.hpp"
Expand Down Expand Up @@ -58,6 +59,8 @@ class ObjectAssociationMergerNode : public rclcpp::Node
const autoware_perception_msgs::msg::DetectedObjects::ConstSharedPtr & input_objects0_msg,
const autoware_perception_msgs::msg::DetectedObjects::ConstSharedPtr & input_objects1_msg);

void timeoutCallback();

tf2_ros::Buffer tf_buffer_;
tf2_ros::TransformListener tf_listener_;
rclcpp::Publisher<autoware_perception_msgs::msg::DetectedObjects>::SharedPtr merged_object_pub_;
Expand All @@ -73,6 +76,13 @@ class ObjectAssociationMergerNode : public rclcpp::Node
std::unique_ptr<DataAssociation> data_association_;
std::string base_link_frame_id_; // associated with the base_link frame

// Timeout Related
double message_timeout_sec_;
rclcpp::Time last_sync_time_;
bool timeout_sent_;
rclcpp::TimerBase::SharedPtr timeout_timer_;
std::unique_ptr<autoware_utils::DiagnosticsInterface> diagnostics_interface_ptr_;

PriorityMode priority_mode_;
bool remove_overlapped_unknown_objects_;
struct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"description": "Index for the priority_mode.",
"default": 3,
"enum": [0, 1, 2, 3]
},
"message_timeout_sec": {
"type": "number",
"description": "The warning timeout threshold for no synchronized messages received.",
"default": 0.15
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <type_traits>
#define EIGEN_MPL2_ONLY

#include "autoware/object_merger/object_association_merger_node.hpp"

#include "autoware/object_recognition_utils/object_recognition_utils.hpp"
#include "autoware_utils/geometry/geometry.hpp"

Expand Down Expand Up @@ -130,6 +130,15 @@
stop_watch_ptr_->tic("cyclic_time");
stop_watch_ptr_->tic("processing_time");
published_time_publisher_ = std::make_unique<autoware_utils::PublishedTimePublisher>(this);
// Timeout process initialization
message_timeout_sec_ = this->declare_parameter<double>("message_timeout_sec");
last_sync_time_ = this->now();
timeout_sent_ = false;
timeout_timer_ = this->create_wall_timer(

Check warning on line 137 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L134-L137

Added lines #L134 - L137 were not covered by tests
std::chrono::duration<double>(message_timeout_sec_),
std::bind(&ObjectAssociationMergerNode::timeoutCallback, this));

Check warning on line 139 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L139

Added line #L139 was not covered by tests
diagnostics_interface_ptr_ =
std::make_unique<autoware_utils::DiagnosticsInterface>(this, "object_association_merger");

Check warning on line 141 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L141

Added line #L141 was not covered by tests
}

void ObjectAssociationMergerNode::objectsCallback(
Expand All @@ -142,6 +151,18 @@
}
stop_watch_ptr_->toc("processing_time", true);

// If messages normally synced
diagnostics_interface_ptr_->clear();
diagnostics_interface_ptr_->add_key_value("timeout_occurred", false);
diagnostics_interface_ptr_->add_key_value(
"messages_interval", (this->now() - last_sync_time_).seconds());
diagnostics_interface_ptr_->update_level_and_message(

Check warning on line 159 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L155-L159

Added lines #L155 - L159 were not covered by tests
diagnostic_msgs::msg::DiagnosticStatus::OK,
"ObjectAssociationMergerNode OK: Messages merged successfully");
diagnostics_interface_ptr_->publish(input_objects0_msg->header.stamp);
last_sync_time_ = this->now();
timeout_sent_ = false;

Check warning on line 164 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L162-L164

Added lines #L162 - L164 were not covered by tests

Check warning on line 165 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

ObjectAssociationMergerNode::objectsCallback already has high cyclomatic complexity, and now it increases in Lines of Code from 93 to 103. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
/* transform to base_link coordinate */
autoware_perception_msgs::msg::DetectedObjects transformed_objects0, transformed_objects1;
if (
Expand Down Expand Up @@ -238,6 +259,25 @@
processing_time_publisher_->publish<autoware_internal_debug_msgs::msg::Float64Stamped>(
"debug/processing_time_ms", stop_watch_ptr_->toc("processing_time", true));
}

void ObjectAssociationMergerNode::timeoutCallback()

Check warning on line 263 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L263

Added line #L263 was not covered by tests
{
rclcpp::Time now = this->now();

Check warning on line 265 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L265

Added line #L265 was not covered by tests
if ((now - last_sync_time_).seconds() >= message_timeout_sec_ && !timeout_sent_) {
diagnostics_interface_ptr_->clear();
diagnostics_interface_ptr_->add_key_value("timeout_occurred", true);
diagnostics_interface_ptr_->add_key_value(
"messages_interval", (now - last_sync_time_).seconds());
std::stringstream message;
message << "Timeout occurred: No synchronized messages received within " << message_timeout_sec_
<< "s.";
diagnostics_interface_ptr_->update_level_and_message(
diagnostic_msgs::msg::DiagnosticStatus::WARN, message.str());
diagnostics_interface_ptr_->publish(now);
timeout_sent_ = true;
}
}

Check warning on line 279 in perception/autoware_object_merger/src/object_association_merger_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_object_merger/src/object_association_merger_node.cpp#L267-L279

Added lines #L267 - L279 were not covered by tests

} // namespace autoware::object_merger

#include <rclcpp_components/register_node_macro.hpp>
Expand Down
Loading