Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
ground_grid.cpp
Go to the documentation of this file.
2
3GroundGrid::GroundGrid(const double range, const double angle, const double radius,
4 const double start_augmentation, const double radius_augmentation,
5 const double fov)
6 : range_(range), grid_geometry_(angle, radius, start_augmentation, radius_augmentation, fov) {
7 int num_slices_ = grid_geometry_.get_num_slices();
8 int num_bins_ = grid_geometry_.get_num_bins(range_);
9 grid_.resize(num_slices_, std::vector<float>(num_bins_, std::numeric_limits<float>::quiet_NaN()));
10}
11
12float GroundGrid::get_ground_height(const float x, const float y) const {
13 int slice = grid_geometry_.get_slice_index(x, y);
14 int bin_idx = grid_geometry_.get_bin_index(x, y);
15 int num_slices_ = grid_geometry_.get_num_slices();
16 int num_bins_ = grid_geometry_.get_num_bins(range_);
17
18 if (slice < 0 || slice >= num_slices_ || bin_idx < 0 || bin_idx >= num_bins_) {
19 return std::numeric_limits<float>::quiet_NaN();
20 }
21
22 return grid_[slice][bin_idx];
23}
24
25void GroundGrid::set_ground_height(const float x, const float y, const float height) {
26 int slice = grid_geometry_.get_slice_index(x, y);
27 int bin_idx = grid_geometry_.get_bin_index(x, y);
28 int num_slices_ = grid_geometry_.get_num_slices();
29 int num_bins_ = grid_geometry_.get_num_bins(range_);
30
31 if (slice < 0 || slice >= num_slices_ || bin_idx < 0 || bin_idx >= num_bins_) {
32 return; // out of bounds, ignore
33 }
34
35 if (std::isnan(grid_[slice][bin_idx])) {
36 grid_[slice][bin_idx] = height;
37 } else {
38 // Update only if new height is lower
39 grid_[slice][bin_idx] = std::min(grid_[slice][bin_idx], height);
40 }
41}
42
44 for (auto& row : grid_) {
45 std::fill(row.begin(), row.end(), std::numeric_limits<float>::quiet_NaN());
46 }
47}
std::vector< std::vector< float > > grid_
double range_
void set_ground_height(const float x, const float y, const float height)
Set the ground height at a specific (x, y) location.
float get_ground_height(const float x, const float y) const
Get the ground height at a specific (x, y) location.
GroundGrid()=default
void reset_grid()
Reset the ground grid to initial state.
GridGeometry grid_geometry_
int get_bin_index(double x, double y) const
Compute bin index for a given (x, y)
int get_slice_index(double x, double y) const
Compute slice index for a given (x, y)
int get_num_slices() const
Get the number of slices in the grid.
int get_num_bins(double range) const
Get the number of bins for a given range.