|
| 1 | +#ifndef ED_LASER_LASER_UPDATER_H_ |
| 2 | +#define ED_LASER_LASER_UPDATER_H_ |
| 3 | + |
| 4 | +#include "ed/laser/entity_update.h" |
| 5 | + |
| 6 | +#include <ed/convex_hull.h> |
| 7 | +#include <ed/init_data.h> |
| 8 | +#include <ed/world_model.h> |
| 9 | + |
| 10 | +#include <geolib/sensors/LaserRangeFinder.h> |
| 11 | + |
| 12 | +#include <map> |
| 13 | +#include <string> |
| 14 | + |
| 15 | +typedef std::vector<unsigned int> ScanSegment; |
| 16 | + |
| 17 | +class LaserUpdater |
| 18 | +{ |
| 19 | + |
| 20 | +public: |
| 21 | + /** |
| 22 | + * @brief Configure updater |
| 23 | + * |
| 24 | + * @param[in] config Configuration which may contain the following fields: |
| 25 | + * world_association_distance |
| 26 | + * min_segment_size_pixels |
| 27 | + * segment_depth_threshold |
| 28 | + * min_cluster_size |
| 29 | + * max_cluster_size |
| 30 | + * max_gap_size |
| 31 | + * fit_entities Whether or not to fit an entity (0 or 1) |
| 32 | + */ |
| 33 | + void configure(tue::Configuration& config); |
| 34 | + |
| 35 | + /** |
| 36 | + * @brief update update the worldmodel based on a novel laserscan message. |
| 37 | + * |
| 38 | + * @param[in] world worldmodel to be updated |
| 39 | + * @param[in] sensor_ranges distances measured by the lrf |
| 40 | + * @param[in] sensor_pose pose of the lrf sensor at the time of the measurement |
| 41 | + * @param[in] timestamp timestamp of the lrf measurment |
| 42 | + * @param[out] req update request |
| 43 | + */ |
| 44 | + void update(const ed::WorldModel& world, std::vector<double>& sensor_ranges, |
| 45 | + const geo::Pose3D& sensor_pose, const double timestamp, ed::UpdateRequest& req); |
| 46 | + |
| 47 | + /** |
| 48 | + * @brief configure the LRF model based on a laserscan message |
| 49 | + * |
| 50 | + * @param num_beams number of beams in the lrf model |
| 51 | + * @param angle_min angle corresponding to the first beam in radians |
| 52 | + * @param angle_max angle corresponding to the final beam in radians |
| 53 | + * @param range_min minimum distance that can be detected with the lrf in meters |
| 54 | + * @param range_max maximum distance that can be detected with the lrf in meters |
| 55 | + */ |
| 56 | + void configureLaserModel(uint num_beams, double angle_min, double angle_max, double range_min, double range_max) |
| 57 | + { |
| 58 | + lrf_model_.setNumBeams(num_beams); |
| 59 | + lrf_model_.setAngleLimits(angle_min, angle_max); |
| 60 | + lrf_model_.setRangeLimits(range_min, range_max); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @brief set the frame of the laser model |
| 65 | + * |
| 66 | + * @param frame_id frame id of the laser |
| 67 | + */ |
| 68 | + inline void setLaserFrame(const std::string& frame_id) { lrf_frame_ = frame_id; } |
| 69 | + |
| 70 | + /** |
| 71 | + * @brief get the number of beams of the model |
| 72 | + */ |
| 73 | + unsigned int getNumBeams() { return lrf_model_.getNumBeams(); } |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief render the worldmodel as would be seen by the lrf. |
| 77 | + * |
| 78 | + * @param[in] sensor_pose pose of the lrf to be modeled in the world frame. |
| 79 | + * @param[in] world worldmodel |
| 80 | + * @param[out] model_ranges ranges of distances as would be seen by an lrf |
| 81 | + */ |
| 82 | + void renderWorld(const geo::Pose3D& sensor_pose, const ed::WorldModel& world, std::vector<double>& model_ranges); |
| 83 | + |
| 84 | + // parameters |
| 85 | + int min_segment_size_pixels_; // in nr of laser points |
| 86 | + double world_association_distance_; // in m |
| 87 | + double segment_depth_threshold_; |
| 88 | + double min_cluster_size_; |
| 89 | + double max_cluster_size_; |
| 90 | + bool fit_entities_; |
| 91 | + int max_gap_size_; |
| 92 | + |
| 93 | +private: |
| 94 | + /** |
| 95 | + * @brief associate: filter sensor information and remove ranges that can be associated with the worldmodel. Leaving only novel data. |
| 96 | + * |
| 97 | + * @param[in] sensor_ranges distances measured by the lrf |
| 98 | + * @param[in,out] model_ranges distances as predicted by the worldmodel. Will be filtered. (associated ranges have value 0.0) |
| 99 | + */ |
| 100 | + void associate(std::vector<double>& sensor_ranges, const std::vector<double>& model_ranges); |
| 101 | + |
| 102 | + /** |
| 103 | + * @brief divide the sensor ranges into segments |
| 104 | + */ |
| 105 | + std::vector<ScanSegment> segment(const std::vector<double>& sensor_ranges); |
| 106 | + |
| 107 | + /** |
| 108 | + * @brief convert a segment of ranges to a convex hull |
| 109 | + */ |
| 110 | + EntityUpdate segmentToConvexHull(const ScanSegment& segment, const geo::Pose3D& sensor_pose, const std::vector<double>& sensor_ranges); |
| 111 | + |
| 112 | + // PARAMETERS |
| 113 | + geo::LaserRangeFinder lrf_model_; |
| 114 | + std::string lrf_frame_; |
| 115 | + |
| 116 | + std::map<ed::UUID, geo::Pose3D> pose_cache; |
| 117 | + |
| 118 | +}; |
| 119 | + |
| 120 | +#endif |
0 commit comments