Main MRPT website > C++ reference for MRPT 1.9.9
CVehicleVelCmd_DiffDriven.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 "kinematics-precomp.h" // Precompiled header
12 #include <mrpt/utils/CStream.h>
13 
14 using namespace mrpt::kinematics;
15 using namespace mrpt::utils;
16 
19 
21  : lin_vel(.0), ang_vel(.0)
22 {
23 }
24 CVehicleVelCmd_DiffDriven::~CVehicleVelCmd_DiffDriven() {}
25 size_t CVehicleVelCmd_DiffDriven::getVelCmdLength() const { return 2; }
27  const int index) const
28 {
29  switch (index)
30  {
31  case 0:
32  return "lin_vel";
33  break;
34  case 1:
35  return "ang_vel";
36  break;
37  default:
38  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
39  };
40 }
41 
43 {
44  switch (index)
45  {
46  case 0:
47  return lin_vel;
48  break;
49  case 1:
50  return ang_vel;
51  break;
52  default:
53  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
54  };
55 }
56 
58  const int index, const double val)
59 {
60  switch (index)
61  {
62  case 0:
63  lin_vel = val;
64  break;
65  case 1:
66  ang_vel = val;
67  break;
68  default:
69  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
70  };
71 }
72 
74 {
75  return lin_vel == .0 && ang_vel == .0;
76 }
77 
80  mrpt::utils::CStream& in, int version)
81 {
82  switch (version)
83  {
84  case 0:
85  in >> lin_vel >> ang_vel;
86  break;
87  default:
89  };
90 }
91 
93  mrpt::utils::CStream& out, int* version) const
94 {
95  if (version)
96  {
97  *version = 0;
98  return;
99  }
100  out << lin_vel << ang_vel;
101 }
102 
104 {
105  lin_vel *= vel_scale;
106  ang_vel *= vel_scale;
107 }
108 
110  const mrpt::kinematics::CVehicleVelCmd& prev_vel_cmd, const double beta,
111  const TVelCmdParams& params)
112 {
113  ASSERT_(params.robotMax_V_mps > 0);
114  ASSERT_(params.robotMax_W_radps > 0);
116  dynamic_cast<const mrpt::kinematics::CVehicleVelCmd_DiffDriven*>(
117  &prev_vel_cmd);
118  ASSERTMSG_(prevcmd, "Expected prevcmd of type `CVehicleVelCmd_DiffDriven`");
119 
120  double speed_scale = filter_max_vw(lin_vel, ang_vel, params);
121 
122  if (std::abs(lin_vel) <
123  0.01) // i.e. new behavior is nearly a pure rotation
124  { // thus, it's OK to blend the rotational component
125  ang_vel = beta * ang_vel + (1 - beta) * prevcmd->ang_vel;
126  }
127  else // there is a non-zero translational component
128  {
129  // must maintain the ratio of w to v (while filtering v)
130  float ratio = ang_vel / lin_vel;
131  lin_vel = beta * lin_vel +
132  (1 - beta) * prevcmd->lin_vel; // blend new v value
133  ang_vel =
134  ratio * lin_vel; // ensure new w implements expected path curvature
135 
136  speed_scale *= filter_max_vw(lin_vel, ang_vel, params);
137  }
138 
139  return speed_scale;
140 }
141 
143  double& v, double& w, const TVelCmdParams& p)
144 {
145  double speed_scale = 1.0;
146  // Ensure maximum speeds:
147  if (std::abs(v) > p.robotMax_V_mps)
148  {
149  // Scale:
150  const double F = std::abs(p.robotMax_V_mps / v);
151  v *= F;
152  w *= F;
153  speed_scale *= F;
154  }
155 
156  if (std::abs(w) > p.robotMax_W_radps)
157  {
158  // Scale:
159  const double F = std::abs(p.robotMax_W_radps / w);
160  v *= F;
161  w *= F;
162  speed_scale *= F;
163  }
164  return speed_scale;
165 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
double filter_max_vw(double &v, double &w, const TVelCmdParams &p)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
Virtual base for velocity commands of different kinematic models of planar mobile robot...
double cmdVel_limits(const mrpt::kinematics::CVehicleVelCmd &prev_vel_cmd, const double beta, const TVelCmdParams &params) override
See base class docs.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
GLuint index
Definition: glext.h:4054
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void setToStop() override
Set to a command that means "do not move" / "stop".
int val
Definition: mrpt_jpeglib.h:955
void setVelCmdElement(const int index, const double val) override
Set each velocity command component.
GLsizei const GLchar ** string
Definition: glext.h:4101
const GLdouble * v
Definition: glext.h:3678
IMPLEMENTS_SERIALIZABLE(CVehicleVelCmd_DiffDriven, CVehicleVelCmd, mrpt::kinematics) CVehicleVelCmd_DiffDriven
size_t getVelCmdLength() const override
Get number of components in each velocity command.
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...
GLuint in
Definition: glext.h:7274
#define ASSERT_(f)
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
bool isStopCmd() const override
Returns true if the command means "do not move" / "stop".
double getVelCmdElement(const int index) const override
Get each velocity command component.
std::string getVelCmdDescription(const int index) const override
Get textual, human-readable description of each velocity command component.
Parameters that may be used by cmdVel_limits() in any derived classes.
#define ASSERTMSG_(f, __ERROR_MSG)
GLfloat GLfloat p
Definition: glext.h:6305
GLenum const GLfloat * params
Definition: glext.h:3534
void cmdVel_scale(double vel_scale) override
See docs of method in base class.
Kinematic model for Ackermann-like or differential-driven vehicles.



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