|
| 1 | +# autoware_localization_util |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +`autoware_localization_util` is a collection of localization utility packages. It contains 5 individual library that used by autoware localization nodes. |
| 6 | + |
| 7 | +- `covariance_ellipse` 2d covariance visualization wrapper. |
| 8 | +- `smart_pose_buffer` pose buffer management library which contains interpolate and data validation. |
| 9 | +- `tree_structured_parzen_estimator` A Tree Structured Parzen Estimator library. |
| 10 | +- `util_func` A tool library which contains several function for localization nodes. |
| 11 | + |
| 12 | +## Design |
| 13 | + |
| 14 | +- `covariance_ellipse` Translate `geometry_msgs::msg::PoseWithCovariance` message into ellipse visual marker to demonstrate covariance distribution. |
| 15 | +- `smart_pose_buffer` A buffer library which implements pose message buffering, pose interpolate and pose validation. |
| 16 | +- `tree_structured_parzen_estimator` A Probability Estimator library that includes estimator and log likelihood ratio calculation. |
| 17 | +- `util_func` Tool function collection. |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### covariance_ellipse |
| 22 | + |
| 23 | +Include header file to use: |
| 24 | + |
| 25 | +```cpp |
| 26 | +#include "autoware/localization_util/covariance_ellipse.hpp" |
| 27 | +``` |
| 28 | + |
| 29 | +calculate ellipse and visualize |
| 30 | + |
| 31 | +```cpp |
| 32 | +autoware::localization_util::Ellipse ellipse_ = autoware::localization_util::calculate_xy_ellipse(input_msg->pose, scale_); |
| 33 | + |
| 34 | + const auto ellipse_marker = autoware::localization_util::create_ellipse_marker( |
| 35 | + ellipse_, input_msg->header, input_msg->pose); |
| 36 | +``` |
| 37 | + |
| 38 | +### smart_pose_buffer |
| 39 | + |
| 40 | +buffer init |
| 41 | + |
| 42 | +```cpp |
| 43 | +#include "autoware/localization_util/smart_pose_buffer.hpp" |
| 44 | + |
| 45 | +using autoware::localization_util::SmartPoseBuffer; |
| 46 | + |
| 47 | +std::unique_ptr<autoware::localization_util::SmartPoseBuffer> initial_pose_buffer_; |
| 48 | +initial_pose_buffer_ = std::make_unique<SmartPoseBuffer>( |
| 49 | + this->get_logger(), param_.validation.initial_pose_timeout_sec, |
| 50 | + param_.validation.initial_pose_distance_tolerance_m); |
| 51 | +``` |
| 52 | + |
| 53 | +interpolate and pop out old pose message |
| 54 | + |
| 55 | +```cpp |
| 56 | +std::optional<SmartPoseBuffer::InterpolateResult> interpolation_result_opt = |
| 57 | +initial_pose_buffer_->interpolate(sensor_ros_time); |
| 58 | + |
| 59 | +... |
| 60 | + |
| 61 | +initial_pose_buffer_->pop_old(sensor_ros_time); |
| 62 | +const SmartPoseBuffer::InterpolateResult & interpolation_result = |
| 63 | +interpolation_result_opt.value(); |
| 64 | +``` |
| 65 | +
|
| 66 | +clear buffer |
| 67 | +
|
| 68 | +```cpp |
| 69 | +initial_pose_buffer_->clear(); |
| 70 | +``` |
| 71 | + |
| 72 | +### tree_structured_parzen_estimator |
| 73 | + |
| 74 | +init the estimator. |
| 75 | +n_startup_trials -- The number of initial random trials in the TPE (Tree-Structured Parzen Estimator). This value should be equal to or less than 'initial_estimate_particles_num' and more than 0. If it is equal to 'initial_estimate_particles_num', the search will be the same as a full random search. |
| 76 | + |
| 77 | +```cpp |
| 78 | +#include "autoware/localization_util/tree_structured_parzen_estimator.hpp" |
| 79 | + |
| 80 | +using autoware::localization_util::TreeStructuredParzenEstimator; |
| 81 | + |
| 82 | +TreeStructuredParzenEstimator tpe( |
| 83 | +TreeStructuredParzenEstimator::Direction::MAXIMIZE, |
| 84 | +param_.initial_pose_estimation.n_startup_trials, sample_mean, sample_stddev); |
| 85 | +``` |
| 86 | +
|
| 87 | +get estimation result |
| 88 | +
|
| 89 | +```cpp |
| 90 | +const TreeStructuredParzenEstimator::Input input = tpe.get_next_input(); |
| 91 | +``` |
| 92 | + |
| 93 | +add new data to the estimator |
| 94 | + |
| 95 | +```cpp |
| 96 | +TreeStructuredParzenEstimator::Input result(6); |
| 97 | + result[0] = pose.position.x; |
| 98 | + result[1] = pose.position.y; |
| 99 | + result[2] = pose.position.z; |
| 100 | + result[3] = rpy.x; |
| 101 | + result[4] = rpy.y; |
| 102 | + result[5] = rpy.z; |
| 103 | +tpe.add_trial(TreeStructuredParzenEstimator::Trial{result, ndt_result.transform_probability}); |
| 104 | +``` |
| 105 | +
|
| 106 | +### util_func |
| 107 | +
|
| 108 | +include header file to use |
| 109 | +
|
| 110 | +```cpp |
| 111 | +#include "autoware/localization_util/util_func.hpp" |
| 112 | +
|
| 113 | +using autoware::localization_util::exchange_color_crc; |
| 114 | +using autoware::localization_util::matrix4f_to_pose; |
| 115 | +using autoware::localization_util::point_to_vector3d; |
| 116 | +using autoware::localization_util::pose_to_matrix4f; |
| 117 | +``` |
| 118 | + |
| 119 | +list of useful function |
| 120 | + |
| 121 | +```cpp |
| 122 | +std_msgs::msg::ColorRGBA exchange_color_crc(double x); |
| 123 | +double calc_diff_for_radian(const double lhs_rad, const double rhs_rad); |
| 124 | +geometry_msgs::msg::Vector3 get_rpy(const geometry_msgs::msg::Pose & pose); |
| 125 | +geometry_msgs::msg::Vector3 get_rpy(const geometry_msgs::msg::PoseStamped & pose); |
| 126 | +geometry_msgs::msg::Vector3 get_rpy(const geometry_msgs::msg::PoseWithCovarianceStamped & pose); |
| 127 | +geometry_msgs::msg::Quaternion rpy_rad_to_quaternion( |
| 128 | + const double r_rad, const double p_rad, const double y_rad); |
| 129 | +geometry_msgs::msg::Quaternion rpy_deg_to_quaternion( |
| 130 | + const double r_deg, const double p_deg, const double y_deg); |
| 131 | +geometry_msgs::msg::Twist calc_twist( |
| 132 | + const geometry_msgs::msg::PoseStamped & pose_a, const geometry_msgs::msg::PoseStamped & pose_b); |
| 133 | +geometry_msgs::msg::PoseStamped interpolate_pose( |
| 134 | + const geometry_msgs::msg::PoseStamped & pose_a, const geometry_msgs::msg::PoseStamped & pose_b, |
| 135 | + const rclcpp::Time & time_stamp); |
| 136 | +geometry_msgs::msg::PoseStamped interpolate_pose( |
| 137 | + const geometry_msgs::msg::PoseWithCovarianceStamped & pose_a, |
| 138 | + const geometry_msgs::msg::PoseWithCovarianceStamped & pose_b, const rclcpp::Time & time_stamp); |
| 139 | +Eigen::Affine3d pose_to_affine3d(const geometry_msgs::msg::Pose & ros_pose); |
| 140 | +Eigen::Matrix4f pose_to_matrix4f(const geometry_msgs::msg::Pose & ros_pose); |
| 141 | +geometry_msgs::msg::Pose matrix4f_to_pose(const Eigen::Matrix4f & eigen_pose_matrix); |
| 142 | +Eigen::Vector3d point_to_vector3d(const geometry_msgs::msg::Point & ros_pos); |
| 143 | +template <class T> |
| 144 | +T transform(const T & input, const geometry_msgs::msg::TransformStamped & transform);double norm(const geometry_msgs::msg::Point & p1, const geometry_msgs::msg::Point & p2); |
| 145 | + |
| 146 | +void output_pose_with_cov_to_log( |
| 147 | + const rclcpp::Logger & logger, const std::string & prefix, |
| 148 | + const geometry_msgs::msg::PoseWithCovarianceStamped & pose_with_cov); |
| 149 | +``` |
0 commit comments