-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoccupancy_map.h
102 lines (79 loc) · 2.76 KB
/
occupancy_map.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef OCCUPANCY_MAP_H_
#define OCCUPANCY_MAP_H_
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <Eigen/Eigen>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud.h>
#include "parameters.h"
struct QueueElement
{
Eigen::Vector3i point_;
double distance_;
bool operator<(const QueueElement& element) const
{
return distance_ > element.distance_;
}
};
class OccupancyMap
{
private:
// member attributes for occupancy update
double logit_hit_;
double logit_miss_;
double min_logit_;
double max_logit_;
double occupancy_threshold_logit_;
// map sizes
Eigen::Vector3d map_size_;
Eigen::Vector3d min_range_;
Eigen::Vector3d max_range_;
Eigen::Vector3i grid_size_;
int grid_size_yz_;
std::vector<double> occupancy_buffer_; // 0 is free, 1 is occupied
std::vector<double> distance_buffer_;
std::vector<int> num_hit_;
std::vector<int> num_miss_;
std::queue<QueueElement> occupancy_queue_;
// map properties
Eigen::Vector3d origin_;
std::string frame_id_;
int infinity_;
int undefined_;
double resolution_;
Eigen::Vector3i max_vec_, min_vec_, last_max_vec_, last_min_vec_;
// boundary for visualizing/publishing map point cloud
Eigen::Vector3i vis_lower_bound_, vis_upper_bound_;
public:
int grid_total_size_;
OccupancyMap(Eigen::Vector3d origin, double resolution, Eigen::Vector3d map_size);
~OccupancyMap(){};
// log odds function for occupancy update
double Logit(const double& prob) const;
bool Exist(const int& indx);
// member methods for conversion between voxel, position and index
void Vox2Pos(Eigen::Vector3i& voxel, Eigen::Vector3d& pos);
void Pos2Vox(Eigen::Vector3d& pos, Eigen::Vector3i& voxel);
int Vox2Indx(Eigen::Vector3i& voxel);
Eigen::Vector3i Indx2Vox(int& indx);
void SetParameters(const double& prob_hit, const double& prob_miss,
const double& prob_min, const double& prob_max, const double& prob_occupancy);
bool CheckUpdate();
void UpdateOccupancy(bool global_map);
// occupancy management
int SetOccupancy(Eigen::Vector3d pos, int occ);
int SetOccupancy(Eigen::Vector3i voxel, int occ);
int GetOccupancy(Eigen::Vector3i voxel);
int GetOccupancy(Eigen::Vector3d pos);
void SetOriginalRange();
void SetVisualizationMargin(const Eigen::Vector3d& vis_min_margin,
const Eigen::Vector3d& vis_max_margin);
void GetPointCloud(sensor_msgs::PointCloud& point_cloud, const std::string& map_frame_id);
void GetVisualizePointCloud(sensor_msgs::PointCloud& point_cloud,
const std::string& map_frame_id);
};
#endif