send one time

This commit is contained in:
acki
2025-05-29 08:26:05 -04:00
parent baf86150bd
commit 3b8b3a2d62
2 changed files with 20 additions and 7 deletions

View File

@@ -38,6 +38,8 @@ namespace Modelec
bool enemy_initialized_ = false; bool enemy_initialized_ = false;
rclcpp::Time last_publish_time_; rclcpp::Time last_publish_time_;
bool is_enemy_close_ = false;
float min_move_threshold_mm_ = 0.0f; float min_move_threshold_mm_ = 0.0f;
float refresh_rate_s_ = 0.0f; float refresh_rate_s_ = 0.0f;

View File

@@ -138,16 +138,27 @@ namespace Modelec
// Check if in bounds // Check if in bounds
if (x_global >= 0 && x_global <= (map_width_ - margin_detection_table_) && y_global >= 0 && y_global <= (map_height_ - margin_detection_table_)) if (x_global >= 0 && x_global <= (map_width_ - margin_detection_table_) && y_global >= 0 && y_global <= (map_height_ - margin_detection_table_))
{ {
modelec_interfaces::msg::OdometryPos emergency_msg; if (!is_enemy_close_)
emergency_msg.x = x_global; {
emergency_msg.y = y_global; modelec_interfaces::msg::OdometryPos emergency_msg;
emergency_msg.theta = 0.0; emergency_msg.x = x_global;
emergency_msg.y = y_global;
emergency_msg.theta = 0.0;
close_enemy_pos_pub_->publish(emergency_msg); close_enemy_pos_pub_->publish(emergency_msg);
RCLCPP_WARN(this->get_logger(), "EMERGENCY CLOSE OBJECT DETECTED at x=%.2f y=%.2f (%.1f mm)", x_global, y_global, range_mm); RCLCPP_WARN(this->get_logger(), "EMERGENCY CLOSE OBJECT DETECTED at x=%.2f y=%.2f (%.1f mm)", x_global, y_global, range_mm);
is_enemy_close_ = true;
}
break;
} }
break;; is_enemy_close_ = false;
}
else
{
is_enemy_close_ = false;
} }
// Convert to local robot frame // Convert to local robot frame