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 }
Kinematic model for Ackermann-like or differential-driven vehicles.
This is the base class for any reactive/planned navigation system.
CRobot2NavInterface & m_robot
The navigator-robot interface.
virtual bool stop(bool isEmergencyStop)
Default: forward call to m_robot.stop().
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)
Default: forward call to m_robot.changeSpeed().
void initialize() override
Must be called for loading collision grids, etc.
virtual void loadConfigFile(const mrpt::utils::CConfigFileBase &c) override
Loads all params from a file.
std::map< double, TVelCmd > programmed_orders
map [time_in_secs_since_beginning] -> orders.
virtual void saveConfigFile(mrpt::utils::CConfigFileBase &c) const override
Saves all current options to a config file.
void navigationStep() override
Overriden in this class to ignore the cancel/pause/...
CNavigatorManualSequence(CRobot2NavInterface &react_iterf_impl)
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...
virtual void resetNavigationTimer()
see getNavigationTime()
virtual double getNavigationTime()
Returns the number of seconds ellapsed since the constructor of this class was invoked,...
This class allows loading and storing values and vectors of different types from a configuration text...
GLdouble GLdouble t
Definition: glext.h:3689
const GLubyte * c
Definition: glext.h:6313
GLdouble s
Definition: glext.h:3676
GLsizei const GLchar ** string
Definition: glext.h:4101
std::shared_ptr< T > make_aligned_shared(Args &&... args)
Creates a shared_ptr with 16-byte aligned memory.
std::vector< std::string > vector_string
A type for passing a vector of strings.
Definition: types_simple.h:33
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.
#define ASSERT_(f)
Definition: mrpt_macros.h:309
#define THROW_EXCEPTION(msg)
Definition: mrpt_macros.h:111
#define ASSERTMSG_(f, __ERROR_MSG)
Definition: mrpt_macros.h:306
mrpt::kinematics::CVehicleVelCmd::Ptr cmd_vel
all with the same meaning than in CRobot2NavInterface::changeSpeeds()



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST