selfdriving
HolonomicBlend.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * SelfDriving C++ library based on PTGs and mrpt-nav
3  * Copyright (C) 2019-2022 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
6 
7 /* +------------------------------------------------------------------------+
8  | Mobile Robot Programming Toolkit (MRPT) |
9  | https://www.mrpt.org/ |
10  | |
11  | Copyright (c) 2005-2022, Individual contributors, see AUTHORS file |
12  | See: https://www.mrpt.org/Authors - All rights reserved. |
13  | Released under BSD License. See: https://www.mrpt.org/License |
14  +------------------------------------------------------------------------+ */
15 #pragma once
16 
18 #include <mrpt/expr/CRuntimeCompiledExpression.h>
19 #include <mrpt/nav/tpspace/CParameterizedTrajectoryGenerator.h>
20 
21 #include <mutex>
22 
23 namespace mpp::ptg
24 {
25 /** A PTG for circular-shaped robots with holonomic kinematics.
26  * - **Compatible kinematics**: Holonomic robot capable of velocity commands
27  * with a linear interpolation ("ramp "or "blending") time. See
28  * mrpt::kinematics::CVehicleSimul_Holo
29  * - **Compatible robot shape**: Circular robots
30  * - **PTG parameters**: Use the app `ptg-configurator`
31  *
32  * \note This class is an enhanced version of mrpt::nav::HolonomicBlend
33  */
35  public mrpt::nav::CPTG_RobotShape_Circular
36 {
37  DEFINE_SERIALIZABLE(HolonomicBlend, mpp::ptg)
38  public:
41  const mrpt::config::CConfigFileBase& cfg, const std::string& sSection);
42 
43  ~HolonomicBlend() override;
44 
45  void loadFromConfigFile(
46  const mrpt::config::CConfigFileBase& cfg,
47  const std::string& sSection) override;
48  void saveToConfigFile(
49  mrpt::config::CConfigFileBase& cfg,
50  const std::string& sSection) const override;
51  void loadDefaultParams() override;
52  bool supportVelCmdNOP() const override;
53  double maxTimeInVelCmdNOP(int path_k) const override;
54 
55  std::string getDescription() const override;
56  bool inverseMap_WS2TP(
57  double x, double y, int& out_k, double& out_d,
58  double tolerance_dist = 0.10) const override;
59  bool PTG_IsIntoDomain(double x, double y) const override;
60  void onNewNavDynamicState() override;
61 
62  bool supportSpeedAtTarget() const override { return true; }
63 
65  double x, double y, int& out_k, double& out_d, double& T_ramp) const;
66 
67  /** Converts a discretized "alpha" value into a feasible motion command or
68  * action. See derived classes for the meaning of these actions */
69  mrpt::kinematics::CVehicleVelCmd::Ptr directionToMotionCommand(
70  uint16_t k) const override;
71  mrpt::kinematics::CVehicleVelCmd::Ptr getSupportedKinematicVelocityCommand()
72  const override;
73 
74  size_t getPathStepCount(uint16_t k) const override;
75  mrpt::math::TPose2D getPathPose(uint16_t k, uint32_t step) const override;
76  double getPathDist(uint16_t k, uint32_t step) const override;
77  bool getPathStepForDist(
78  uint16_t k, double dist, uint32_t& out_step) const override;
79  double getPathStepDuration() const override;
80  double getMaxLinVel() const override { return V_MAX; }
81  double getMaxAngVel() const override { return W_MAX; }
82  void updateTPObstacle(
83  double ox, double oy, std::vector<double>& tp_obstacles) const override;
85  double ox, double oy, uint16_t k, double& tp_obstacle_k) const override;
86 
87  double internal_getPathDist(
88  uint32_t step, double T_ramp, double vxf, double vyf) const;
89 
90  /** Duration of each PTG "step" (default: 10e-3=10 ms) */
91  static double PATH_TIME_STEP;
92 
93  /** Mathematical "epsilon", to detect ill-conditioned situations (e.g. 1/0)
94  * (Default: 1e-4) */
95  static double eps;
96 
97  protected:
98  double T_ramp_max = -1.0;
99  double V_MAX = -1.0, W_MAX = -1.0;
100  double turningRadiusReference = 0.30;
101 
102  std::string expr_V, expr_W, expr_T_ramp;
103  mutable std::vector<int> m_pathStepCountCache;
104 
105  // Compilation of user-given expressions
106  mrpt::expr::CRuntimeCompiledExpression m_expr_v, m_expr_w;
107  double m_expr_dir = 0; // Used as symbol "dir" in m_expr_v and m_expr_w
108  double m_expr_target_dir = 0; // symbol "target_dir" in expressions
109  double m_expr_target_dist = 0; // symbol "target_dist" in expressions
110  std::mutex m_expr_mtx;
111 
113  {
114  double vxi = 0, vyi = 0;
115  double vxf = 0, vyf = 0;
116  double vf = 0, wf = 0;
117  double T_ramp = 1;
118  };
119 
121  const double dir) const;
122 
124 
125  void internal_processNewRobotShape() override;
126  void internal_initialize(
127  const std::string& cacheFilename = std::string(),
128  const bool verbose = true) override;
129  void internal_deinitialize() override;
130 
131  public:
132  /** Axiliary function for computing the line-integral distance along the
133  * trajectory, handling special cases of 1/0: */
134  static double calc_trans_distance_t_below_Tramp(
135  double k2, double k4, double vxi, double vyi, double t);
136  /** Axiliary function for calc_trans_distance_t_below_Tramp() and others */
138  double t, double a, double b, double c);
139 };
140 } // namespace mpp::ptg
double vf
Definition: HolonomicBlend.h:116
std::mutex m_expr_mtx
Definition: HolonomicBlend.h:110
double turningRadiusReference
Definition: HolonomicBlend.h:100
Definition: HolonomicBlend.h:112
Definition: SpeedTrimmablePTG.h:17
InternalParams internal_params_from_dir_and_dynstate(const double dir) const
void updateTPObstacle(double ox, double oy, std::vector< double > &tp_obstacles) const override
bool getPathStepForDist(uint16_t k, double dist, uint32_t &out_step) const override
size_t getPathStepCount(uint16_t k) const override
static double calc_trans_distance_t_below_Tramp(double k2, double k4, double vxi, double vyi, double t)
double internal_getPathDist(uint32_t step, double T_ramp, double vxf, double vyf) const
double vyi
Definition: HolonomicBlend.h:114
std::string expr_V
Definition: HolonomicBlend.h:102
void internal_processNewRobotShape() override
mrpt::kinematics::CVehicleVelCmd::Ptr getSupportedKinematicVelocityCommand() const override
double getPathDist(uint16_t k, uint32_t step) const override
Definition: DiffDrive_C.h:14
double m_expr_target_dist
Definition: HolonomicBlend.h:109
std::string expr_W
Definition: HolonomicBlend.h:102
void loadDefaultParams() override
void internal_deinitialize() override
double T_ramp_max
Definition: HolonomicBlend.h:98
static double PATH_TIME_STEP
Definition: HolonomicBlend.h:91
double m_expr_dir
Definition: HolonomicBlend.h:107
mrpt::math::TPose2D getPathPose(uint16_t k, uint32_t step) const override
Definition: HolonomicBlend.h:34
mrpt::expr::CRuntimeCompiledExpression m_expr_v
Definition: HolonomicBlend.h:106
void internal_initialize(const std::string &cacheFilename=std::string(), const bool verbose=true) override
std::string expr_T_ramp
Definition: HolonomicBlend.h:102
void saveToConfigFile(mrpt::config::CConfigFileBase &cfg, const std::string &sSection) const override
static double eps
Definition: HolonomicBlend.h:95
double vxi
Definition: HolonomicBlend.h:114
void loadFromConfigFile(const mrpt::config::CConfigFileBase &cfg, const std::string &sSection) override
double wf
Definition: HolonomicBlend.h:116
bool PTG_IsIntoDomain(double x, double y) const override
std::string getDescription() const override
void updateTPObstacleSingle(double ox, double oy, uint16_t k, double &tp_obstacle_k) const override
double getMaxLinVel() const override
Definition: HolonomicBlend.h:80
bool inverseMap_WS2TP(double x, double y, int &out_k, double &out_d, double tolerance_dist=0.10) const override
double getMaxAngVel() const override
Definition: HolonomicBlend.h:81
static double calc_trans_distance_t_below_Tramp_abc(double t, double a, double b, double c)
void onNewNavDynamicState() override
std::vector< int > m_pathStepCountCache
Definition: HolonomicBlend.h:103
double maxTimeInVelCmdNOP(int path_k) const override
bool inverseMap_WS2TP_with_Tramp(double x, double y, int &out_k, double &out_d, double &T_ramp) const
mrpt::kinematics::CVehicleVelCmd::Ptr directionToMotionCommand(uint16_t k) const override
bool supportSpeedAtTarget() const override
Definition: HolonomicBlend.h:62
mrpt::expr::CRuntimeCompiledExpression m_expr_w
Definition: HolonomicBlend.h:106
bool supportVelCmdNOP() const override
double V_MAX
Definition: HolonomicBlend.h:99
double W_MAX
Definition: HolonomicBlend.h:99
double getPathStepDuration() const override
double m_expr_target_dir
Definition: HolonomicBlend.h:108