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-2018, 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
13 
14 using namespace mrpt::kinematics;
15 
17 
19  : vel(.0), dir_local(.0), ramp_time(.0), rot_speed(.0)
20 {
21 }
22 
24  double vel_, double dir_local_, double ramp_time_, double rot_speed_)
25  : vel(vel_),
26  dir_local(dir_local_),
27  ramp_time(ramp_time_),
28  rot_speed(rot_speed_)
29 {
30 }
31 
33 size_t CVehicleVelCmd_Holo::getVelCmdLength() const { return 4; }
35 {
36  switch (index)
37  {
38  case 0:
39  return "vel";
40  break;
41  case 1:
42  return "dir_local";
43  break;
44  case 2:
45  return "ramp_time";
46  break;
47  case 3:
48  return "rot_speed";
49  break;
50  default:
51  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
52  };
53 }
54 
56 {
57  switch (index)
58  {
59  case 0:
60  return vel;
61  break;
62  case 1:
63  return dir_local;
64  break;
65  case 2:
66  return ramp_time;
67  break;
68  case 3:
69  return rot_speed;
70  break;
71  default:
72  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
73  };
74 }
75 
76 void CVehicleVelCmd_Holo::setVelCmdElement(const int index, const double val)
77 {
78  switch (index)
79  {
80  case 0:
81  vel = val;
82  break;
83  case 1:
84  dir_local = val;
85  break;
86  case 2:
87  ramp_time = val;
88  break;
89  case 3:
90  rot_speed = val;
91  break;
92  default:
93  THROW_EXCEPTION_FMT("index out of bounds: %i", index);
94  };
95 }
96 
98 {
99  return vel == 0 && rot_speed == 0;
100 }
101 
103 {
104  vel = dir_local = ramp_time = rot_speed = .0;
105 }
108 {
109  switch (version)
110  {
111  case 0:
112  in >> vel >> dir_local >> ramp_time >> rot_speed;
113  break;
114  default:
116  };
117 }
118 
121 {
122  out << vel << dir_local << ramp_time << rot_speed;
123 }
124 
125 void CVehicleVelCmd_Holo::cmdVel_scale(double vel_scale)
126 {
127  vel *= vel_scale; // |(vx,vy)|
128  // rot_speed *= vel_scale; // rot_speed
129  // Note: No need to scale "rot_speed" since a holonomic robot's path will be
130  // invariant
131  // ramp_time: leave unchanged
132 }
133 
135  const mrpt::kinematics::CVehicleVelCmd& prev_vel_cmd, const double beta,
136  const TVelCmdParams& params)
137 {
138  ASSERTMSG_(
139  params.robotMax_V_mps >= .0,
140  "[CVehicleVelCmd_Holo] `robotMax_V_mps` must be set to valid values: "
141  "either assign values programmatically or call loadConfigFile()");
142 
143  double f = 1.0;
144  if (vel > params.robotMax_V_mps) f = params.robotMax_V_mps / vel;
145 
146  vel *= f; // |(vx,vy)|
147  rot_speed *= f; // rot_speed
148  // ramp_time: leave unchanged
149  // Blending with "beta" not required, since the ramp_time already blends
150  // cmds for holo robots.
151 
152  return f;
153 }
CVehicleVelCmd_Holo.h
mrpt::kinematics::CVehicleVelCmd_Holo::~CVehicleVelCmd_Holo
virtual ~CVehicleVelCmd_Holo()
Definition: CVehicleVelCmd_Holo.cpp:32
mrpt::kinematics::CVehicleVelCmd_Holo::getVelCmdDescription
std::string getVelCmdDescription(const int index) const override
Get textual, human-readable description of each velocity command component.
Definition: CVehicleVelCmd_Holo.cpp:34
mrpt::kinematics::CVehicleVelCmd_Holo::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CVehicleVelCmd_Holo.cpp:120
mrpt::kinematics::CVehicleVelCmd_Holo::setToStop
void setToStop() override
Set to a command that means "do not move" / "stop".
Definition: CVehicleVelCmd_Holo.cpp:102
mrpt::kinematics::CVehicleVelCmd_Holo::cmdVel_scale
void cmdVel_scale(double vel_scale) override
Scale the velocity command encoded in this object.
Definition: CVehicleVelCmd_Holo.cpp:125
mrpt::kinematics::CVehicleVelCmd::TVelCmdParams
Parameters that may be used by cmdVel_limits() in any derived classes.
Definition: CVehicleVelCmd.h:50
mrpt::kinematics::CVehicleVelCmd_Holo::vel
double vel
speed(m / s)
Definition: CVehicleVelCmd_Holo.h:26
mrpt::kinematics::CVehicleVelCmd_Holo::getVelCmdLength
size_t getVelCmdLength() const override
Get number of components in each velocity command.
Definition: CVehicleVelCmd_Holo.cpp:33
mrpt::kinematics::CVehicleVelCmd_Holo::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CVehicleVelCmd_Holo.cpp:119
THROW_EXCEPTION_FMT
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:43
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::kinematics::CVehicleVelCmd_Holo::setVelCmdElement
void setVelCmdElement(const int index, const double val) override
Set each velocity command component.
Definition: CVehicleVelCmd_Holo.cpp:76
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::kinematics::CVehicleVelCmd_Holo::ramp_time
double ramp_time
: Blending time between current and target time.
Definition: CVehicleVelCmd_Holo.h:31
val
int val
Definition: mrpt_jpeglib.h:955
mrpt::kinematics::CVehicleVelCmd_Holo::getVelCmdElement
double getVelCmdElement(const int index) const override
Get each velocity command component.
Definition: CVehicleVelCmd_Holo.cpp:55
mrpt::kinematics::CVehicleVelCmd_Holo::dir_local
double dir_local
: direction, relative to the current robot heading (radians).
Definition: CVehicleVelCmd_Holo.h:29
kinematics-precomp.h
index
GLuint index
Definition: glext.h:4054
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
mrpt::kinematics::CVehicleVelCmd_Holo::isStopCmd
bool isStopCmd() const override
Returns true if the command means "do not move" / "stop".
Definition: CVehicleVelCmd_Holo.cpp:97
mrpt::kinematics::CVehicleVelCmd_Holo::cmdVel_limits
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...
Definition: CVehicleVelCmd_Holo.cpp:134
mrpt::kinematics::CVehicleVelCmd_Holo::CVehicleVelCmd_Holo
CVehicleVelCmd_Holo()
Definition: CVehicleVelCmd_Holo.cpp:18
mrpt::kinematics::CVehicleVelCmd_Holo
Kinematic model for.
Definition: CVehicleVelCmd_Holo.h:21
in
GLuint in
Definition: glext.h:7274
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::kinematics::CVehicleVelCmd_Holo::rot_speed
double rot_speed
: (rad/s) rotational speed for rotating such as the robot slowly faces forward.
Definition: CVehicleVelCmd_Holo.h:34
mrpt::kinematics
Definition: CKinematicChain.h:19
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::kinematics::CVehicleVelCmd
Virtual base for velocity commands of different kinematic models of planar mobile robot.
Definition: CVehicleVelCmd.h:22
mrpt::kinematics::CVehicleVelCmd_Holo::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CVehicleVelCmd_Holo.cpp:106
params
GLenum const GLfloat * params
Definition: glext.h:3534



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST