Main MRPT website > C++ reference for MRPT 1.5.7
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  CAbstractNavigator( robot_interface )
22 {
23 }
24 
25 // Dtor:
27 {
28 }
29 
31 {
32 }
33 
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_(toks.size()>2,std::string("Wrong format while parsing CNavigatorManualSequence cfg file in entry: ")+lstKeys[i]);
48 
49  const double t = atof(toks[0].c_str());
50  TVelCmd krc;
51 
52  const size_t nComps = toks.size() - 1;
53  switch (nComps)
54  {
57  default:
58  THROW_EXCEPTION("Expected 2 or 4 velocity components!");
59  };
60 
61  for (size_t i=0;i<nComps;i++)
62  krc.cmd_vel->setVelCmdElement(i, atof(toks[i+1].c_str() ));
63 
64  // insert:
65  programmed_orders[t] = krc;
66  }
67 }
68 
70 {
71  ASSERT_(!programmed_orders.empty())
73 }
74 
75 /** Overriden in this class to ignore the cancel/pause/... commands */
77 {
78  if (programmed_orders.empty())
79  return;
80 
81  const double t = m_robot.getNavigationTime();
82 
83  if (t>=programmed_orders.begin()->first)
84  {
85  const TVelCmd &krc = programmed_orders.begin()->second;
86  // Send cmd:
87  logFmt( mrpt::utils::LVL_DEBUG, "[CNavigatorManualSequence] Sending cmd: t=%f\n",programmed_orders.begin()->first);
88 
89  if (!this->changeSpeeds(*krc.cmd_vel) )
90  {
91  this->stop(true /*not emergency*/);
92  logFmt( mrpt::utils::LVL_ERROR, "[CNavigatorManualSequence] **ERROR** sending cmd to robot.");
93  return;
94  }
95  // remove:
96  programmed_orders.erase( programmed_orders.begin() );
97  }
98 }
99 
100 
static CVehicleVelCmd_DiffDrivenPtr Create()
static CVehicleVelCmd_HoloPtr Create()
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(). Can be overriden.
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)
Default: forward call to m_robot.changeSpeed(). Can be overriden.
std::map< double, TVelCmd > programmed_orders
map [time_in_secs_since_beginning] -> orders.
void navigationStep() MRPT_OVERRIDE
Overriden in this class to ignore the cancel/pause/...
void initialize() MRPT_OVERRIDE
Must be called for loading collision grids, etc. before invoking any navigation command.
virtual void loadConfigFile(const mrpt::utils::CConfigFileBase &c) MRPT_OVERRIDE
Loads all params from a file.
virtual void saveConfigFile(mrpt::utils::CConfigFileBase &c) const MRPT_OVERRIDE
Saves all current options to a config file.
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:3610
const GLubyte * c
Definition: glext.h:5590
GLdouble s
Definition: glext.h:3602
GLsizei const GLchar ** string
Definition: glext.h:3919
std::vector< std::string > vector_string
A type for passing a vector of strings.
Definition: types_simple.h:30
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
Tokenizes a string according to a set of delimiting characters.
#define ASSERT_(f)
Definition: mrpt_macros.h:278
#define THROW_EXCEPTION(msg)
Definition: mrpt_macros.h:154
#define ASSERTMSG_(f, __ERROR_MSG)
Definition: mrpt_macros.h:277
mrpt::kinematics::CVehicleVelCmdPtr cmd_vel
all with the same meaning than in CRobot2NavInterface::changeSpeeds()



Page generated by Doxygen 1.9.1 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at mar 26 may 2026 13:12:03 CEST