Program Listing for File turning_base.h

Return to documentation for file (include/fields2cover/path_planning/turning_base.h)

//=============================================================================
//    Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
//                     Author: Gonzalo Mier
//                        BSD-3 License
//=============================================================================

#pragma once
#ifndef FIELDS2COVER_PATH_PLANNING_TURNING_BASE_H_
#define FIELDS2COVER_PATH_PLANNING_TURNING_BASE_H_

#include <memory>
#include <map>
#include <vector>
#include <limits>
#include <functional>
#include "fields2cover/types.h"
#include "fields2cover/utils/random.h"

namespace f2c::pp {

class TurningBase {
 public:
  F2CPath createTurn(const F2CRobot& robot,
      const F2CPoint& start_pos, double start_angle,
      const F2CPoint& end_pos, double end_angle);

  F2CPath createTurnIfNotCached(const F2CRobot& robot, double dist_start_pos,
      double start_angle, double end_angle);

  virtual F2CPath createSimpleTurn(const F2CRobot& robot, double dist_start_pos,
      double start_angle, double end_angle) = 0;

  static std::vector<double> transformToNormalTurn(const F2CPoint& start_pos,
      double start_angle, const F2CPoint& end_pos, double end_angle);

  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);


  double getDiscretization() const;
  void setDiscretization(double d);

  bool getUsingCache() const;
  void setUsingCache(bool c);


 private:
  static void correctPath(F2CPath& path,
      const F2CPoint& start_pos,
      const F2CPoint& end_pos,
      float max_error_dist = 0.05);

 protected:
  // To prevent memory consumption and comparative errors because of doubles
  // ints are used multiplied by 1000.
  std::map<std::vector<int>, F2CPath> path_cache_;
  double discretization {0.01};
  bool using_cache {true};
};

}  // namespace f2c::pp

#endif  // FIELDS2COVER_PATH_PLANNING_TURNING_BASE_H_