turning_base.h
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef FIELDS2COVER_PATH_PLANNING_TURNING_BASE_H_
9 #define FIELDS2COVER_PATH_PLANNING_TURNING_BASE_H_
10 
11 #include <memory>
12 #include <map>
13 #include <vector>
14 #include <limits>
15 #include <functional>
16 #include "fields2cover/types.h"
18 
19 namespace f2c::pp {
20 
22 class TurningBase {
23  public:
34  const F2CPoint& start_pos, double start_angle,
35  const F2CPoint& end_pos, double end_angle);
36 
42  F2CPath createTurnIfNotCached(const F2CRobot& robot, double dist_start_pos,
43  double start_angle, double end_angle);
44 
50  virtual F2CPath createSimpleTurn(const F2CRobot& robot, double dist_start_pos,
51  double start_angle, double end_angle) = 0;
52 
60  static std::vector<double> transformToNormalTurn(const F2CPoint& start_pos,
61  double start_angle, const F2CPoint& end_pos, double end_angle);
62 
64  static bool isTurnValid(const F2CPath& path, double dist_start_end,
65  double end_angle, double max_dist_error = 0.05,
66  double max_rot_error = 0.1);
67 
68 
70  double getDiscretization() const;
72  void setDiscretization(double d);
73 
75  bool getUsingCache() const;
77  void setUsingCache(bool c);
78 
79  virtual ~TurningBase() = default;
80 
81 
82  private:
83  static void correctPath(F2CPath& path,
84  const F2CPoint& start_pos,
85  const F2CPoint& end_pos,
86  float max_error_dist = 0.05);
87 
88  protected:
89  // To prevent memory consumption and comparative errors because of doubles
90  // ints are used multiplied by 1000.
91  std::map<std::vector<int>, F2CPath> path_cache_;
92  double discretization {0.01};
93  bool using_cache {true};
94 };
95 
96 } // namespace f2c::pp
97 
98 #endif // FIELDS2COVER_PATH_PLANNING_TURNING_BASE_H_
f2c::pp
Path planning algorithms' namespace.
Definition: dubins_curves.h:14
types.h
2_objective_functions.path
path
Definition: 2_objective_functions.py:88
f2c::pp::TurningBase::~TurningBase
virtual ~TurningBase()=default
f2c::pp::TurningBase::getUsingCache
bool getUsingCache() const
Get if turns are being cached or not.
Definition: turning_base.cpp:122
f2c::pp::TurningBase::createSimpleTurn
virtual F2CPath createSimpleTurn(const F2CRobot &robot, double dist_start_pos, double start_angle, double end_angle)=0
Create a turn.
f2c::pp::TurningBase::using_cache
bool using_cache
Definition: turning_base.h:93
2_objective_functions.robot
robot
Definition: 2_objective_functions.py:76
random.h
f2c::types::Path
Definition: Path.h:23
f2c::pp::TurningBase::path_cache_
std::map< std::vector< int >, F2CPath > path_cache_
Definition: turning_base.h:91
f2c::pp::TurningBase::discretization
double discretization
Definition: turning_base.h:92
f2c::pp::TurningBase::transformToNormalTurn
static std::vector< double > transformToNormalTurn(const F2CPoint &start_pos, double start_angle, const F2CPoint &end_pos, double end_angle)
Transform the turn parameters representation from two points with two angles to one distance and two ...
Definition: turning_base.cpp:11
f2c::pp::TurningBase
Base class for turn planners.
Definition: turning_base.h:22
f2c::types::Point
Definition: Point.h:21
f2c::types::Robot
Definition: Robot.h:25
f2c::pp::TurningBase::setUsingCache
void setUsingCache(bool c)
Set if cache should be used when planning same turn as before.
Definition: turning_base.cpp:126
f2c::pp::TurningBase::createTurnIfNotCached
F2CPath createTurnIfNotCached(const F2CRobot &robot, double dist_start_pos, double start_angle, double end_angle)
Generate a turn if it has not been computed before.
Definition: turning_base.cpp:81
f2c::pp::TurningBase::isTurnValid
static bool isTurnValid(const F2CPath &path, double dist_start_end, double end_angle, double max_dist_error=0.05, double max_rot_error=0.1)
Check if turn is valid.
Definition: turning_base.cpp:100
f2c::pp::TurningBase::createTurn
F2CPath createTurn(const F2CRobot &robot, const F2CPoint &start_pos, double start_angle, const F2CPoint &end_pos, double end_angle)
Create a turn that goes from one point with a certain angle to another point.
Definition: turning_base.cpp:30
f2c::pp::TurningBase::getDiscretization
double getDiscretization() const
Get discretization distance from points in the turn.
Definition: turning_base.cpp:114
f2c::pp::TurningBase::correctPath
static void correctPath(F2CPath &path, const F2CPoint &start_pos, const F2CPoint &end_pos, float max_error_dist=0.05)
Definition: turning_base.cpp:65
f2c::pp::TurningBase::setDiscretization
void setDiscretization(double d)
Set discretization distance from points in the turn.
Definition: turning_base.cpp:118


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31