Main MRPT website > C++ reference for MRPT 1.9.9
CNavigatorManualSequence.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
11 
17 
18 using namespace mrpt::nav;
19 
21  CRobot2NavInterface& robot_interface)
22  : CAbstractNavigator(robot_interface)
23 {
24 }
25 
26 // Dtor:
30 {
31 }
32 
35 {
36  const std::string s = "CNavigatorManualSequence";
37 
38  programmed_orders.clear();
39  mrpt::vector_string lstKeys;
40  c.getAllKeys(s, lstKeys);
41 
42  for (size_t i = 0; i < lstKeys.size(); i++)
43  {
44  std::string s = c.read_string(s, lstKeys[i], "", true);
45  std::vector<std::string> toks;
46  mrpt::system::tokenize(s, " \t\r\n", toks);
47  ASSERTMSG_(
48  toks.size() > 2,
50  "Wrong format while parsing CNavigatorManualSequence "
51  "cfg file in entry: ") +
52  lstKeys[i]);
53 
54  const double t = atof(toks[0].c_str());
55  TVelCmd krc;
56 
57  const size_t nComps = toks.size() - 1;
58  switch (nComps)
59  {
60  case 2:
63  break;
64  case 4:
67  break;
68  default:
69  THROW_EXCEPTION("Expected 2 or 4 velocity components!");
70  };
71 
72  for (size_t i = 0; i < nComps; i++)
73  krc.cmd_vel->setVelCmdElement(i, atof(toks[i + 1].c_str()));
74 
75  // insert:
76  programmed_orders[t] = krc;
77  }
78 }
79 
81 {
82  ASSERT_(!programmed_orders.empty())
84 }
85 
86 /** Overriden in this class to ignore the cancel/pause/... commands */
88 {
89  if (programmed_orders.empty()) return;
90 
91  const double t = m_robot.getNavigationTime();
92 
93  if (t >= programmed_orders.begin()->first)
94  {
95  const TVelCmd& krc = programmed_orders.begin()->second;
96  // Send cmd:
97  logFmt(
98  mrpt::utils::LVL_DEBUG,
99  "[CNavigatorManualSequence] Sending cmd: t=%f\n",
100  programmed_orders.begin()->first);
101 
102  if (!this->changeSpeeds(*krc.cmd_vel))
103  {
104  this->stop(true /*not emergency*/);
105  logFmt(
106  mrpt::utils::LVL_ERROR,
107  "[CNavigatorManualSequence] **ERROR** sending cmd to robot.");
108  return;
109  }
110  // remove:
111  programmed_orders.erase(programmed_orders.begin());
112  }
113 }
virtual void saveConfigFile(mrpt::utils::CConfigFileBase &c) const override
Saves all current options to a config file.
GLdouble GLdouble t
Definition: glext.h:3689
virtual void resetNavigationTimer()
see getNavigationTime()
mrpt::kinematics::CVehicleVelCmd::Ptr cmd_vel
all with the same meaning than in CRobot2NavInterface::changeSpeeds()
#define THROW_EXCEPTION(msg)
virtual double getNavigationTime()
Returns the number of seconds ellapsed since the constructor of this class was invoked, or since the last call of resetNavigationTimer().
GLdouble s
Definition: glext.h:3676
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)
Default: forward call to m_robot.changeSpeed().
This class allows loading and storing values and vectors of different types from a configuration text...
void navigationStep() override
Overriden in this class to ignore the cancel/pause/...
const GLubyte * c
Definition: glext.h:6313
virtual void loadConfigFile(const mrpt::utils::CConfigFileBase &c) override
Loads all params from a file.
GLsizei const GLchar ** string
Definition: glext.h:4101
void tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
CRobot2NavInterface & m_robot
The navigator-robot interface.
void initialize() override
Must be called for loading collision grids, etc.
#define ASSERT_(f)
std::shared_ptr< T > make_aligned_shared(Args &&... args)
Creates a shared_ptr with 16-byte aligned memory.
CNavigatorManualSequence(CRobot2NavInterface &react_iterf_impl)
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...
std::vector< std::string > vector_string
A type for passing a vector of strings.
#define ASSERTMSG_(f, __ERROR_MSG)
This is the base class for any reactive/planned navigation system.
Kinematic model for Ackermann-like or differential-driven vehicles.
virtual bool stop(bool isEmergencyStop)
Default: forward call to m_robot.stop().
std::map< double, TVelCmd > programmed_orders
map [time_in_secs_since_beginning] -> orders.



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