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 std::shared_ptr<const WorldIDF>
80 double time_step_dist_ = 0;
81 double sensor_area_ = 0;
85 void UpdateSensorView() {
86 sensor_view_ = MapType::Zero(params_.pSensorSize, params_.pSensorSize);
87 if (MapUtils::IsPointOutsideBoundary(
88 params_.
pResolution, global_current_position_, params_.pSensorSize,
92 world_idf_->GetSubWorldMap(global_current_position_, params_.pSensorSize,
96 void UpdateRobotMap() {
101 robot_map_.block(index.left + offset.left, index.bottom + offset.bottom,
102 offset.width, offset.height) =
103 sensor_view_.block(offset.left, offset.bottom, offset.width,
107 void UpdateExplorationMap() {
108 if (MapUtils::IsPointOutsideBoundary(
109 params_.
pResolution, global_current_position_, params_.pSensorSize,
117 exploration_map_.block(
118 index.left + offset.left, index.bottom + offset.bottom, offset.width,
119 offset.height) = MapType::Zero(offset.width, offset.height);
132 : params_{params}, global_start_position_{global_start_position} {
133 world_idf_ = std::make_shared<const WorldIDF>(world_idf);
134 normalization_factor_ = world_idf_->GetNormalizationFactor();
135 global_current_position_ = global_start_position_;
137 sensor_view_ = MapType::Zero(params_.pSensorSize, params_.pSensorSize);
141 local_start_position_ =
Point2{0, 0};
142 local_current_position_ = local_start_position_;
146 if (params_.pUpdateExplorationMap ==
true) {
149 local_exploration_map_ =
151 UpdateExplorationMap();
155 local_exploration_map_ =
161 sensor_area_ = params_.pSensorSize * params_.pSensorSize;
164 void ClearRobotMap() {
165 if (params_.pRobotMapUseUnknownImportance ==
true) {
168 params_.pUnknownImportance * params_.pNorm);
173 if (params_.pUpdateSensorView ==
true) {
176 if (params_.pUpdateRobotMap ==
false) {
177 robot_map_ = world_idf_->GetWorldMap();
187 auto dir = direction;
189 Point2 new_pos = local_current_position_;
190 if (sp > params_.pMaxRobotSpeed) {
191 sp = params_.pMaxRobotSpeed;
193 bool invalid_dir = dir.norm() <
kEps and sp >=
kEps;
194 if (sp < 0 or invalid_dir) {
195 std::cout << sp <<
" " << dir.norm() << std::endl;
196 std::cerr <<
"Speed needs to be non-negative\n";
197 std::cerr <<
"Zero-vector direction cannot be given in control\n";
198 std::throw_with_nested(
199 std::runtime_error(
"Speed needs to be non-negative"));
208 new_pos = local_current_position_ + dir * sp * params_.
pTimeStep;
216 Point2 new_global_pos = pos + global_start_position_;
217 if (new_global_pos.x() <= 0) {
220 if (new_global_pos.y() <= 0) {
224 if (new_global_pos.x() >= max_xy) {
227 if (new_global_pos.y() >= max_xy) {
231 local_current_position_ = new_global_pos - global_start_position_;
232 global_current_position_ = new_global_pos;
233 if (params_.pUpdateSensorView ==
true) {
236 if (params_.pUpdateRobotMap ==
true) {
239 if (params_.pUpdateExplorationMap ==
true) {
240 UpdateExplorationMap();
244 void SetGlobalRobotPosition(
Point2 const &pos) {
245 Point2 new_global_pos = pos;
246 if (new_global_pos.x() <= 0) {
249 if (new_global_pos.y() <= 0) {
253 if (new_global_pos.x() >= max_xy) {
256 if (new_global_pos.y() >= max_xy) {
260 local_current_position_ = new_global_pos - global_start_position_;
261 global_current_position_ = new_global_pos;
262 if (params_.pUpdateSensorView ==
true) {
265 if (params_.pUpdateRobotMap ==
true) {
268 if (params_.pUpdateExplorationMap ==
true) {
269 UpdateExplorationMap();
273 Point2 GetGlobalStartPosition()
const {
return global_start_position_; }
274 Point2 GetGlobalCurrentPosition()
const {
return global_current_position_; }
276 const MapType &GetRobotMap()
const {
return robot_map_; }
277 const MapType &GetSensorView()
const {
return sensor_view_; }
279 const MapType &GetRobotSystemMap() {
282 system_map_ = local_map_ - local_exploration_map_;
286 const MapType &GetRobotLocalMap() {
291 if (not MapUtils::IsPointOutsideBoundary(
294 MapUtils::GetSubMap(params_.
pResolution, global_current_position_,
301 const MapType &GetExplorationMap() {
304 local_exploration_map_ =
306 if (not MapUtils::IsPointOutsideBoundary(
309 MapUtils::GetSubMap(params_.
pResolution, global_current_position_,
313 return local_exploration_map_;
316 const MapType &GetObstacleMap() {
318 MapUtils::MapBounds index, offset;
321 obstacle_map_.block(offset.left, offset.bottom, offset.width,
323 MapType::Zero(offset.width, offset.height);
324 return obstacle_map_;
327 auto GetExplorationFeatures() {
329 Point2
const &pos = global_current_position_;
332 double pos_x_lim = std::min(pos[0] + factor * time_step_dist_,
334 double pos_y_lim = std::min(pos[1] + factor * time_step_dist_,
336 for (
double pos_x = std::max(pos[0] - factor * time_step_dist_,
kLargeEps);
337 pos_x < pos_x_lim; pos_x += 1 * params_.
pResolution) {
339 std::max(pos[1] - factor * time_step_dist_,
kLargeEps);
340 pos_y < pos_y_lim; pos_y += 1 * params_.
pResolution) {
341 Point2 qpos{pos_x, pos_y};
342 double dist = (qpos - pos).norm();
343 dist = std::max(dist, time_step_dist_);
344 MapUtils::MapBounds index, offset;
349 .block(index.left + offset.left, index.bottom + offset.bottom,
350 offset.width, offset.height)
352 double benefit = unexplored;
353 if (unexplored > 0.1 * sensor_area_) {
356 .block(index.left + offset.left, index.bottom + offset.bottom,
357 offset.width, offset.height)
359 benefit += 2 * idf_value;
361 double bcr = benefit / dist;
363 if (frontiers.size() <
size_t(params_.pNumFrontiers)) {
364 frontiers.push(Frontier(qpos, bcr));
366 auto worst_frontier = frontiers.top();
367 if (worst_frontier.value < bcr) {
369 frontiers.push(Frontier(qpos, bcr));
374 std::vector<double> frontier_features(params_.pNumFrontiers * 2);
376 while (!frontiers.empty()) {
377 auto point = frontiers.top();
378 frontier_features[count++] = point.pt[0] - pos[0];
379 frontier_features[count++] = point.pt[1] - pos[1];
382 return frontier_features;
388 auto GetVoronoiFeatures() {
389 auto const &pos = global_current_position_;
390 MapUtils::MapBounds index, offset;
393 auto trimmed_local_map =
394 robot_map_.block(index.left + offset.left, index.bottom + offset.bottom,
395 offset.width, offset.height);
397 Point2 map_size(offset.width, offset.height);
398 Point2 map_translation(
400 (index.bottom + offset.bottom) * params_.
pResolution);
402 PointVector robot_positions(1);
403 robot_positions[0] = pos - map_translation;
404 Voronoi voronoi(robot_positions, trimmed_local_map, map_size,
406 auto vcell = voronoi.GetVoronoiCell();
409 return vcell.GetFeatureVector();