Main MRPT website > C++ reference for MRPT 1.9.9
CPTG_DiffDrive_C.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "nav-precomp.h" // Precomp header
12 #include <mrpt/math/wrap2pi.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::nav;
16 using namespace mrpt::utils;
17 using namespace mrpt::system;
18 
21 
23  const mrpt::utils::CConfigFileBase& cfg, const std::string& sSection)
24 {
26 
27  MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(K, double, cfg, sSection);
28 }
30  mrpt::utils::CConfigFileBase& cfg, const std::string& sSection) const
31 {
33  const int WN = 25, WV = 30;
35 
36  cfg.write(
37  sSection, "K", K, WN, WV,
38  "K=+1 forward paths; K=-1 for backwards paths.");
39 
40  MRPT_END
41 }
42 
44 {
46 
47  switch (version)
48  {
49  case 0:
50  in >> K;
51  break;
52  default:
54  };
55 }
56 
58  mrpt::utils::CStream& out, int* version) const
59 {
60  if (version)
61  {
62  *version = 0;
63  return;
64  }
65 
67  out << K;
68 }
69 
71 {
72  return mrpt::format("CPTG_DiffDrive_C,K=%i", (int)K);
73 }
74 
76  float alpha, float t, float x, float y, float phi, float& v, float& w) const
77 {
81  MRPT_UNUSED_PARAM(phi);
82  // (v,w)
83  v = V_MAX * sign(K);
84  // Use a linear mapping: (Old was: w = tan( alpha/2 ) * W_MAX * sign(K))
85  w = (alpha / M_PI) * W_MAX * sign(K);
86 }
87 
88 bool CPTG_DiffDrive_C::PTG_IsIntoDomain(double x, double y) const
89 {
92  return true;
93 }
94 
96  double x, double y, int& k_out, double& d_out, double tolerance_dist) const
97 {
98  MRPT_UNUSED_PARAM(tolerance_dist);
99  bool is_exact = true;
100  if (y != 0)
101  {
102  double R = (x * x + y * y) / (2 * y);
103  const double Rmin = std::abs(V_MAX / W_MAX);
104 
105  double theta;
106 
107  if (K > 0)
108  {
109  if (y > 0)
110  theta = atan2((double)x, fabs(R) - y);
111  else
112  theta = atan2((double)x, y + fabs(R));
113  }
114  else
115  {
116  if (y > 0)
117  theta = atan2(-(double)x, fabs(R) - y);
118  else
119  theta = atan2(-(double)x, y + fabs(R));
120  }
121 
122  // Arc length must be possitive [0,2*pi]
124 
125  // Distance thru arc:
126  d_out = (float)(theta * (fabs(R) + turningRadiusReference));
127 
128  if (std::abs(R) < Rmin)
129  {
130  is_exact = false;
131  R = Rmin * mrpt::utils::sign(R);
132  }
133 
134  // Was: a = 2*atan( V_MAX / (W_MAX*R) );
135  const double a = M_PI * V_MAX / (W_MAX * R);
136  k_out = alpha2index((float)a);
137  }
138  else
139  {
140  if (sign(x) == sign(K))
141  {
142  k_out = alpha2index(0);
143  d_out = x;
144  is_exact = true;
145  }
146  else
147  {
148  k_out = m_alphaValuesCount - 1;
149  d_out = 1e+3;
150  is_exact = false;
151  }
152  }
153 
154  // Normalize:
155  d_out = d_out / refDistance;
156 
157  ASSERT_ABOVEEQ_(k_out, 0)
158  ASSERT_BELOW_(k_out, m_alphaValuesCount)
159 
160  return is_exact;
161 }
162 
164 {
166  K = +1.0;
167 }
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3525
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble t
Definition: glext.h:3689
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool PTG_IsIntoDomain(double x, double y) const override
Returns the same than inverseMap_WS2TP() but without any additional cost.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:30
void loadDefaultParams() override
Loads a set of default parameters; provided exclusively for the PTG-configurator tool.
#define ASSERT_BELOW_(__A, __B)
void internal_readFromStream(mrpt::utils::CStream &in) override
int sign(T x)
Returns the sign of X as "1" or "-1".
#define M_PI
Definition: bits.h:92
void ptgDiffDriveSteeringFunction(float alpha, float t, float x, float y, float phi, float &v, float &w) const override
The main method to be implemented in derived classes: it defines the differential-driven differential...
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
std::string getDescription() const override
Gets a short textual description of the PTG and its parameters.
This class allows loading and storing values and vectors of different types from a configuration text...
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This is the base class for any user-defined PTG.
virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) override
Possible values in "params" (those in CParameterizedTrajectoryGenerator, which is called internally...
#define MRPT_END
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
GLsizei const GLchar ** string
Definition: glext.h:4101
int sign(T x)
Returns the sign of X as "1" or "-1".
Definition: bits.h:121
void wrapTo2PiInPlace(T &a)
Modifies the given angle to translate it into the [0,2pi[ range.
Definition: wrap2pi.h:28
#define MRPT_START
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool inverseMap_WS2TP(double x, double y, int &out_k, double &out_d, double tolerance_dist=0.10) const override
The default implementation in this class relies on a look-up-table.
void write(const std::string &section, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
#define ASSERT_ABOVEEQ_(__A, __B)
const float R
IMPLEMENTS_SERIALIZABLE(CPTG_DiffDrive_C, CParameterizedTrajectoryGenerator, mrpt::nav) void CPTG_DiffDrive_C
GLuint in
Definition: glext.h:7274
void internal_writeToStream(mrpt::utils::CStream &out) const override
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
#define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT( variableName, variableType, configFileObject, sectionNameStr)
GLenum GLint GLint y
Definition: glext.h:3538
virtual void loadDefaultParams() override
Loads a set of default parameters; provided exclusively for the PTG-configurator tool.
GLenum GLint x
Definition: glext.h:3538
A PTG for circular paths ("C" type PTG in papers).
virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) override
Possible values in "params" (those in CParameterizedTrajectoryGenerator, which is called internally...
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019