5858#include < nav_msgs/msg/occupancy_grid.hpp>
5959#include < sensor_msgs/msg/laser_scan.hpp>
6060#include < sensor_msgs/msg/point_field.hpp>
61+ #include < std_msgs/msg/float64.hpp>
6162#include < std_srvs/srv/empty.hpp>
6263
6364#include < beluga/motion/differential_drive_model.hpp>
@@ -201,6 +202,28 @@ AmclNode::AmclNode(const rclcpp::NodeOptions& options) : BaseAMCLNode{"amcl", ""
201202 " increase resource usage and potentially degrade performance." ;
202203 declare_parameter (" debug" , false , descriptor);
203204 }
205+
206+ {
207+ const auto defaults = beluga_ros::AmclParams{};
208+ auto descriptor = rcl_interfaces::msg::ParameterDescriptor ();
209+ descriptor.floating_point_range .resize (1 );
210+ descriptor.floating_point_range [0 ].from_value = 0.0 ;
211+ descriptor.floating_point_range [0 ].to_value = 1.0 ;
212+ descriptor.floating_point_range [0 ].step = 0.0 ;
213+
214+ descriptor.description =
215+ " Expected standard deviation of x in a healthy particle distribution, used for quality estimation [m]." ;
216+ declare_parameter (" expected_pose_x_stddev" , rclcpp::ParameterValue (defaults.expected_pose_x_stddev ), descriptor);
217+
218+ descriptor.description =
219+ " Expected standard deviation of y in a healthy particle distribution, used for quality estimation [m]." ;
220+ declare_parameter (" expected_pose_y_stddev" , rclcpp::ParameterValue (defaults.expected_pose_y_stddev ), descriptor);
221+
222+ descriptor.description =
223+ " Expected standard deviation of yaw in a healthy particle distribution, used for quality estimation [rad]." ;
224+ declare_parameter (
225+ " expected_pose_yaw_stddev" , rclcpp::ParameterValue (defaults.expected_pose_yaw_stddev ), descriptor);
226+ }
204227}
205228
206229AmclNode::~AmclNode () {
@@ -215,6 +238,9 @@ void AmclNode::do_activate(const rclcpp_lifecycle::State&) {
215238 likelihood_field_pub_->on_activate ();
216239 }
217240
241+ quality_pub_ = create_publisher<std_msgs::msg::Float64>(" localization_quality" , rclcpp::SystemDefaultsQoS ());
242+ quality_pub_->on_activate ();
243+
218244 {
219245 map_sub_ = create_subscription<nav_msgs::msg::OccupancyGrid>(
220246 get_parameter (" map_topic" ).as_string (), rclcpp::QoS (rclcpp::KeepLast (1 )).transient_local ().reliable (),
@@ -311,13 +337,17 @@ void AmclNode::do_deactivate(const rclcpp_lifecycle::State&) {
311337 if (likelihood_field_pub_) {
312338 likelihood_field_pub_->on_deactivate ();
313339 }
340+ if (quality_pub_) {
341+ quality_pub_->on_deactivate ();
342+ }
314343}
315344
316345void AmclNode::do_cleanup (const rclcpp_lifecycle::State&) {
317346 // Release all resources.
318347 particle_filter_.reset ();
319348 enable_tf_broadcast_ = false ;
320349 likelihood_field_pub_.reset ();
350+ quality_pub_.reset ();
321351}
322352
323353auto AmclNode::get_initial_estimate () const -> std::optional<std::pair<Sophus::SE2d, Eigen::Matrix3d>> {
@@ -423,6 +453,9 @@ auto AmclNode::make_particle_filter(nav_msgs::msg::OccupancyGrid::SharedPtr map)
423453 params.spatial_resolution_x = get_parameter (" spatial_resolution_x" ).as_double ();
424454 params.spatial_resolution_y = get_parameter (" spatial_resolution_y" ).as_double ();
425455 params.spatial_resolution_theta = get_parameter (" spatial_resolution_theta" ).as_double ();
456+ params.expected_pose_x_stddev = get_parameter (" expected_pose_x_stddev" ).as_double ();
457+ params.expected_pose_y_stddev = get_parameter (" expected_pose_y_stddev" ).as_double ();
458+ params.expected_pose_yaw_stddev = get_parameter (" expected_pose_yaw_stddev" ).as_double ();
426459
427460 return std::make_unique<beluga_ros::Amcl>(
428461 beluga_ros::OccupancyGrid{map}, //
@@ -644,6 +677,10 @@ void AmclNode::sensor_callback(const std::shared_ptr<const MessageT>& sensor_msg
644677 tf2::toMsg (base_pose_in_map, message.pose .pose );
645678 tf2::covarianceEigenToRowMajor (base_pose_covariance, message.pose .covariance );
646679 pose_pub_->publish (message);
680+
681+ auto quality_msg = std_msgs::msg::Float64{};
682+ quality_msg.data = particle_filter_->quality ();
683+ quality_pub_->publish (quality_msg);
647684 }
648685}
649686
0 commit comments