33#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ROBOT_MODEL_H_
34#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ROBOT_MODEL_H_
65 Point2 global_start_position_, global_current_position_;
66 Point2 local_start_position_, local_current_position_;
67 double normalization_factor_ = 0;
76 local_exploration_map_;
78 double time_step_dist_ = 0;
79 double sensor_area_ = 0;
81 std::shared_ptr<const WorldIDF>
87 void UpdateSensorView() {
94 world_idf_->GetSubWorldMap(global_current_position_, params_.
pSensorSize,
98 void UpdateRobotMap() {
109 void UpdateExplorationMap() {
119 exploration_map_.block(
125 normalization_factor_ = world_idf_->GetNormalizationFactor();
126 global_current_position_ = global_start_position_;
132 local_start_position_ =
Point2{0, 0};
133 local_current_position_ = local_start_position_;
140 local_exploration_map_ =
142 UpdateExplorationMap();
146 local_exploration_map_ =
165 std::shared_ptr<const WorldIDF>
const &world_idf)
167 global_start_position_{global_start_position},
168 world_idf_{world_idf} {
175 global_start_position_{global_start_position},
176 world_idf_{std::make_shared<const
WorldIDF>(world_idf)} {
201 auto dir = direction;
203 Point2 new_pos = local_current_position_;
207 bool invalid_dir = dir.norm() <
kEps and sp >=
kEps;
208 if (sp < 0 or invalid_dir) {
209 std::cout << sp <<
" " << dir.norm() << std::endl;
210 std::cerr <<
"Speed needs to be non-negative\n";
211 std::cerr <<
"Zero-vector direction cannot be given in control\n";
212 std::throw_with_nested(
213 std::runtime_error(
"Speed needs to be non-negative"));
222 new_pos = local_current_position_ + dir * sp * params_.
pTimeStep;
230 Point2 new_global_pos = pos + global_start_position_;
231 if (new_global_pos.x() <= 0) {
234 if (new_global_pos.y() <= 0) {
238 if (new_global_pos.x() >= max_xy) {
241 if (new_global_pos.y() >= max_xy) {
245 local_current_position_ = new_global_pos - global_start_position_;
246 global_current_position_ = new_global_pos;
254 UpdateExplorationMap();
259 Point2 new_global_pos = pos;
260 if (new_global_pos.x() <= 0) {
263 if (new_global_pos.y() <= 0) {
267 if (new_global_pos.x() >= max_xy) {
270 if (new_global_pos.y() >= max_xy) {
274 local_current_position_ = new_global_pos - global_start_position_;
275 global_current_position_ = new_global_pos;
283 UpdateExplorationMap();
296 system_map_ = local_map_ - local_exploration_map_;
324 local_exploration_map_ =
333 return local_exploration_map_;
339 ComputeOffsets(params_.
pResolution, global_current_position_,
344 return obstacle_map_;
349 Point2 const &pos = global_current_position_;
352 double pos_x_lim = std::min(pos[0] + factor * time_step_dist_,
354 double pos_y_lim = std::min(pos[1] + factor * time_step_dist_,
356 for (
double pos_x = std::max(pos[0] - factor * time_step_dist_,
kLargeEps);
357 pos_x < pos_x_lim; pos_x += 1 * params_.
pResolution) {
359 std::max(pos[1] - factor * time_step_dist_,
kLargeEps);
360 pos_y < pos_y_lim; pos_y += 1 * params_.
pResolution) {
361 Point2 qpos{pos_x, pos_y};
362 double dist = (qpos - pos).norm();
363 dist = std::max(dist, time_step_dist_);
372 double benefit = unexplored;
373 if (unexplored > 0.1 * sensor_area_) {
379 benefit += 2 * idf_value;
381 double bcr = benefit / dist;
384 frontiers.push(
Frontier(qpos, bcr));
386 auto worst_frontier = frontiers.top();
387 if (worst_frontier.value < bcr) {
389 frontiers.push(
Frontier(qpos, bcr));
394 std::vector<double> frontier_features(params_.
pNumFrontiers * 2);
396 while (!frontiers.empty()) {
397 auto point = frontiers.top();
398 frontier_features[count++] = point.pt[0] - pos[0];
399 frontier_features[count++] = point.pt[1] - pos[1];
402 return frontier_features;
409 auto const &pos = global_current_position_;
413 auto trimmed_local_map =
423 robot_positions[0] = pos - map_translation;
424 Voronoi voronoi(robot_positions, trimmed_local_map, map_size,
429 return vcell.GetFeatureVector();
Class to store parameters.
int pRobotMapSize
Robot map saves what the robot has seen.
double pTimeStep
Each time step corresponds to pTimeStep seconds.
double pUnknownImportance
bool pUpdateExplorationMap
bool pRobotMapUseUnknownImportance
Class for handling the robot model.
const MapType & GetObstacleMap()
void SetGlobalRobotPosition(Point2 const &pos)
auto GetExplorationFeatures()
Point2 GetGlobalCurrentPosition() const
const MapType & GetSensorView() const
const MapType & GetExplorationMap()
void SetRobotPosition(Point2 const &pos)
Set robot position relative to the current position.
const MapType & GetRobotMap() const
RobotModel(Parameters const ¶ms, Point2 const &global_start_position, std::shared_ptr< const WorldIDF > const &world_idf)
Constructor for the robot model.
const MapType & GetRobotSystemMap()
auto GetVoronoiFeatures()
MapType & GetRobotMapMutable()
int StepControl(Point2 const &direction, double const &speed)
const MapType & GetRobotLocalMap()
Point2 GetGlobalStartPosition() const
RobotModel(Parameters const ¶ms, Point2 const &global_start_position, WorldIDF const &world_idf)
Class for computing Voronoi cells.
Class for Importance Density Function (IDF) for the world.
Constants for the CoverageControl library.
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MapType
std::vector< Point2 > PointVector
std::priority_queue< Frontier, std::vector< Frontier >, FrontierCompare > queue_t
Utility functions for transforming maps.
int IsPointOutsideBoundary(double const resolution, Point2 const &pos, int const sensor_size, int const boundary)
void GetSubMap(double const resolution, Point2 const &pos, int const map_size, T const &map, int const submap_size, T &submap)
void ComputeOffsets(double const resolution, Point2 const &pos, int const submap_size, int const map_size, MapBounds &index, MapBounds &offset)
Namespace for the CoverageControl library.
A struct to store a frontier points and a value.
Contains typedefs for the library.
Class for computing Voronoi cells.
Contains the class for Importance Density Function (IDF) for the world.