Main MRPT website > C++ reference for MRPT 1.5.7
CGenericSensor.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 "hwdrivers-precomp.h" // Precompiled headers
11 
13 #include <mrpt/obs/CAction.h>
14 #include <mrpt/obs/CObservation.h>
15 
16 using namespace mrpt::utils;
17 using namespace mrpt::obs;
18 using namespace mrpt::system;
19 using namespace mrpt::hwdrivers;
20 using namespace std;
21 
22 /*-------------------------------------------------------------
23  Constructor
24 -------------------------------------------------------------*/
26  m_process_rate(0),
27  m_max_queue_len(200),
28  m_grab_decimation(0),
29  m_sensorLabel("UNNAMED_SENSOR"),
30  m_grab_decimation_counter(0),
31  m_state( ssInitializing ),
32  m_verbose(false),
33  m_path_for_external_images (),
34  m_external_images_format ("png"),
35  m_external_images_jpeg_quality (95)
36 {
37  const char * sVerbose = getenv("MRPT_HWDRIVERS_VERBOSE");
38  m_verbose = (sVerbose!=NULL) && atoi(sVerbose)!=0;
39 }
40 
41 /*-------------------------------------------------------------
42  Destructor
43 -------------------------------------------------------------*/
45 {
46  // Free objects in list, if any:
47  m_objList.clear();
48 }
49 
50 /*-------------------------------------------------------------
51  appendObservations
52 -------------------------------------------------------------*/
53 void CGenericSensor::appendObservations( const std::vector<mrpt::utils::CSerializablePtr> &objs)
54 {
56  {
58 
60 
61  for (size_t i=0;i<objs.size();i++)
62  {
63  const CSerializablePtr &obj = objs[i];
64  if (!obj) continue;
65 
66  // It must be a CObservation or a CAction!
67  TTimeStamp timestamp;
68 
69  if ( obj->GetRuntimeClass()->derivedFrom( CLASS_ID(CAction) ) )
70  {
71  timestamp = CActionPtr(obj)->timestamp;
72  }
73  else
74  if ( obj->GetRuntimeClass()->derivedFrom( CLASS_ID(CObservation) ) )
75  {
76  timestamp = CObservationPtr(obj)->timestamp;
77  }
78  else THROW_EXCEPTION("Passed object must be CObservation.");
79 
80  // Add it:
81  m_objList.insert( TListObsPair(timestamp, obj) );
82  }
83  }
84 }
85 
86 
87 /*-------------------------------------------------------------
88  getObservations
89 -------------------------------------------------------------*/
91 {
93  lstObjects = m_objList;
94  m_objList.clear(); // Memory of objects will be freed by invoker.
95 }
96 
97 
98 /*-------------------------------------------------------------
99 
100  createSensor
101 
102 -------------------------------------------------------------*/
104 {
106  const registered_sensor_classes_t::iterator it=regs.find(className);
107  return it==regs.end() ? NULL : it->second->ptrCreateObject();
108 }
109 
110 // Singleton
112 {
113  static registered_sensor_classes_t reg;
114  return reg;
115 }
116 
117 /*-------------------------------------------------------------
118  registerClass
119 -------------------------------------------------------------*/
121 {
123  regs[ pNewClass->className ] = pNewClass;
124 }
125 
126 
127 
128 /** Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensorSpecific"
129  * \exception This method throws an exception with a descriptive message if some critical parameter is missing or has an invalid value.
130  */
132  const mrpt::utils::CConfigFileBase &cfg,
133  const std::string &sect )
134 {
135  MRPT_START
136 
137  m_process_rate = cfg.read_double(sect,"process_rate",0 ); // Leave it to 0 so rawlog-grabber can detect if it's not set by the user.
138  m_max_queue_len = static_cast<size_t>(cfg.read_int(sect,"max_queue_len",int(m_max_queue_len)));
139  m_grab_decimation = static_cast<size_t>(cfg.read_int(sect,"grab_decimation",int(m_grab_decimation)));
140 
141  m_sensorLabel = cfg.read_string( sect, "sensorLabel", m_sensorLabel );
142 
144 
145  loadConfig_sensorSpecific(cfg,sect);
146 
147  MRPT_END
148 }
TListObservations m_objList
The queue of objects to be returned by getObservations.
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
void appendObservations(const std::vector< mrpt::utils::CSerializablePtr > &obj)
This method must be called by derived classes to enqueue a new observation in the list to be returned...
size_t m_grab_decimation_counter
Used when "m_grab_decimation" is enabled.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
double m_process_rate
See CGenericSensor.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
synch::CCriticalSection m_csObjList
The critical section for m_objList.
std::multimap< mrpt::system::TTimeStamp, mrpt::utils::CSerializablePtr > TListObservations
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:29
std::string m_sensorLabel
See CGenericSensor.
#define THROW_EXCEPTION(msg)
Scalar * iterator
Definition: eigen_plugins.h:23
Contains classes for various device interfaces.
void getObservations(TListObservations &lstObjects)
Returns a list of enqueued objects, emptying it (thread-safe).
static CGenericSensor * createSensor(const std::string &className)
Creates a sensor by a name of the class.
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
STL namespace.
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
void loadConfig(const mrpt::utils::CConfigFileBase &configSource, const std::string &section)
Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensor...
This class allows loading and storing values and vectors of different types from a configuration text...
int read_int(const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
virtual ~CGenericSensor()
Destructor.
const char * className
Class name.
#define MRPT_END
static void registerClass(const TSensorClassId *pNewClass)
Register a class into the internal list of "CGenericSensor" descendents.
static registered_sensor_classes_t & get_registered_sensor_classes()
Access to singleton.
This namespace contains representation of robot actions and observations.
std::map< std::string, const TSensorClassId * > registered_sensor_classes_t
Used in registerClass.
size_t m_max_queue_len
See CGenericSensor.
GLsizei const GLchar ** string
Definition: glext.h:3919
Declares a class for storing a robot action.
Definition: obs/CAction.h:33
#define CLASS_ID(class_name)
Access to runtime class ID for a defined class name.
Definition: CObject.h:82
#define MRPT_START
virtual void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &section)=0
Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes)
size_t m_grab_decimation
If set to N>=2, only 1 out of N observations will be saved to m_objList.
std::pair< mrpt::system::TTimeStamp, mrpt::utils::CSerializablePtr > TListObsPair
Declares a class that represents any robot&#39;s observation.
double read_double(const std::string &section, const std::string &name, double defaultValue, bool failIfNotFound=false) const
class HWDRIVERS_IMPEXP CGenericSensor
A structure for runtime ID class type information in the context of hwdrivers::CGenericSensor.



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019