Main MRPT website > C++ reference for MRPT 1.9.9
CVehicleVelCmd_Holo.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 
18 
20  : vel(.0), dir_local(.0), ramp_time(.0), rot_speed(.0)
21 {
22 }
23 
25  double vel, double dir_local, double ramp_time, double rot_speed)
26  : vel(vel), dir_local(dir_local), ramp_time(ramp_time), rot_speed(rot_speed)
27 {
28 }
29 
31 size_t CVehicleVelCmd_Holo::getVelCmdLength() const { return 4; }
33 {
34  switch (index)
35  {
36  case 0:
37  return "vel";
38  break;
39  case 1:
40  return "dir_local";
41  break;
42  case 2:
43  return "ramp_time";
44  break;
45  case 3:
46  return "rot_speed";
47  break;
48  default:
49  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
50  };
51 }
52 
54 {
55  switch (index)
56  {
57  case 0:
58  return vel;
59  break;
60  case 1:
61  return dir_local;
62  break;
63  case 2:
64  return ramp_time;
65  break;
66  case 3:
67  return rot_speed;
68  break;
69  default:
70  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
71  };
72 }
73 
74 void CVehicleVelCmd_Holo::setVelCmdElement(const int index, const double val)
75 {
76  switch (index)
77  {
78  case 0:
79  vel = val;
80  break;
81  case 1:
82  dir_local = val;
83  break;
84  case 2:
85  ramp_time = val;
86  break;
87  case 3:
88  rot_speed = val;
89  break;
90  default:
91  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
92  };
93 }
94 
96 {
97  return vel == 0 && rot_speed == 0;
98 }
99 
101 {
102  vel = dir_local = ramp_time = rot_speed = .0;
103 }
105 {
106  switch (version)
107  {
108  case 0:
109  in >> vel >> dir_local >> ramp_time >> rot_speed;
110  break;
111  default:
113  };
114 }
115 
117  mrpt::utils::CStream& out, int* version) const
118 {
119  if (version)
120  {
121  *version = 0;
122  return;
123  }
124  out << vel << dir_local << ramp_time << rot_speed;
125 }
126 
127 void CVehicleVelCmd_Holo::cmdVel_scale(double vel_scale)
128 {
129  vel *= vel_scale; // |(vx,vy)|
130  // rot_speed *= vel_scale; // rot_speed
131  // Note: No need to scale "rot_speed" since a holonomic robot's path will be
132  // invariant
133  // ramp_time: leave unchanged
134 }
135 
137  const mrpt::kinematics::CVehicleVelCmd& prev_vel_cmd, const double beta,
138  const TVelCmdParams& params)
139 {
140  ASSERTMSG_(
141  params.robotMax_V_mps >= .0,
142  "[CVehicleVelCmd_Holo] `robotMax_V_mps` must be set to valid values: "
143  "either assign values programmatically or call loadConfigFile()");
144 
145  double f = 1.0;
146  if (vel > params.robotMax_V_mps) f = params.robotMax_V_mps / vel;
147 
148  vel *= f; // |(vx,vy)|
149  rot_speed *= f; // rot_speed
150  // ramp_time: leave unchanged
151  // Blending with "beta" not required, since the ramp_time already blends
152  // cmds for holo robots.
153 
154  return f;
155 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::string getVelCmdDescription(const int index) const override
Get textual, human-readable description of each velocity command component.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
void cmdVel_scale(double vel_scale) override
Scale the velocity command encoded in this object.
size_t getVelCmdLength() const override
Get number of components in each velocity command.
void setToStop() override
Set to a command that means "do not move" / "stop".
Virtual base for velocity commands of different kinematic models of planar mobile robot...
double ramp_time
: Blending time between current and target time.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
void setVelCmdElement(const int index, const double val) override
Set each velocity command component.
double dir_local
: direction, relative to the current robot heading (radians).
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 index
Definition: glext.h:4054
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
int val
Definition: mrpt_jpeglib.h:955
double getVelCmdElement(const int index) const override
Get each velocity command component.
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
double cmdVel_limits(const mrpt::kinematics::CVehicleVelCmd &prev_vel_cmd, const double beta, const TVelCmdParams &params) override
Updates this command, computing a blended version of beta (within [0,1]) of vel_cmd and 1-beta of pre...
GLuint in
Definition: glext.h:7274
bool isStopCmd() const override
Returns true if the command means "do not move" / "stop".
Parameters that may be used by cmdVel_limits() in any derived classes.
#define ASSERTMSG_(f, __ERROR_MSG)
GLenum const GLfloat * params
Definition: glext.h:3534
double rot_speed
: (rad/s) rotational speed for rotating such as the robot slowly faces forward.



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