Main MRPT website > C++ reference for MRPT 1.9.9
CDetectorDoorCrossing.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 "detectors-precomp.h" // Precompiled headers
11 
14 #include <mrpt/poses/CPosePDF.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::obs;
18 using namespace mrpt::maps;
19 using namespace mrpt::detectors;
20 using namespace mrpt::utils;
21 using namespace mrpt::poses;
22 
23 /*---------------------------------------------------------------
24  Constructor
25  ---------------------------------------------------------------*/
26 CDetectorDoorCrossing::CDetectorDoorCrossing()
27  : COutputLogger("CDetectorDoorCrossing"),
28  options(),
29  lastObs(),
30  entropy(),
31  lastEntropy(),
32  lastEntropyValid(false)
33 {
34  clear();
35 }
36 
37 /*---------------------------------------------------------------
38  clear
39  ---------------------------------------------------------------*/
41 {
42  lastObs.clear();
43  lastEntropyValid = false;
44 }
45 
46 /*---------------------------------------------------------------
47  process
48  ---------------------------------------------------------------*/
50  CActionRobotMovement2D& in_poseChange, CSensoryFrame& in_sf,
51  TDoorCrossingOutParams& out_estimation)
52 {
53  // Variables for generic use:
54  size_t i;
55 
56  out_estimation.cumulativeTurning = 0;
57 
59 
60  // 1) Add new pair to the list:
61  // -----------------------------------------
62  lastObs.addAction(in_poseChange);
63  lastObs.addObservations(in_sf);
64 
65  // 2) Remove oldest pair:
66  // -----------------------------------------
68  ASSERT_((lastObs.size() % 2) == 0); // Assure even size
69 
70  while (lastObs.size() > options.windowSize * 2)
71  {
72  lastObs.remove(0);
73  lastObs.remove(0);
74  }
75 
76  if (lastObs.size() < options.windowSize * 2)
77  {
78  // Not enought old data yet:
79  out_estimation.enoughtInformation = false;
80  return;
81  }
82 
83  // 3) Build an occupancy grid map with observations
84  // -------------------------------------------------
85  CPose2D p, pos;
86 
87  TSetOfMetricMapInitializers mapInitializer;
88 
89  {
91  mapInitializer.push_back(def);
92  }
93  {
96  mapInitializer.push_back(def);
97  }
98 
99  CMultiMetricMap auxMap(&mapInitializer);
100 
101  for (i = 0; i < options.windowSize; i++)
102  {
103  CActionCollection::Ptr acts = lastObs.getAsAction(i * 2 + 0);
104  CAction::Ptr act = acts->get(0);
105 
106  ASSERT_(
107  act->GetRuntimeClass()->derivedFrom(
110  std::dynamic_pointer_cast<CActionRobotMovement2D>(act);
111 
112  action->poseChange->getMean(pos);
113 
114  out_estimation.cumulativeTurning += fabs(pos.phi());
115 
116  // Get the cumulative pose for the current observation:
117  p = p + pos;
118 
119  // Add SF to the grid map:
121  CPose3D pose3D(p);
122  sf->insertObservationsInto(&auxMap, &pose3D);
123  }
124 
125  // 4) Compute the information differece between this
126  // "map patch" and the previous one:
127  // -------------------------------------------------------
128  auxMap.m_gridMaps[0]->computeEntropy(entropy);
129 
130  if (!lastEntropyValid)
131  {
132  out_estimation.enoughtInformation = false;
133  }
134  else
135  {
136  // 5) Fill output data
137  // ---------------------------------
138  out_estimation.enoughtInformation = true;
139 
140  out_estimation.informationGain = entropy.I - lastEntropy.I;
141  out_estimation.pointsMap.copyFrom(*auxMap.m_pointsMaps[0]);
142  }
143 
144  // For next iterations:
146  lastEntropyValid = true;
147 
148  MRPT_END
149 }
unsigned int windowSize
The window size, in (action,observations) pairs;min.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
ProxyFilterContainerByClass< mrpt::maps::CSimplePointsMap::Ptr, TListMaps > m_pointsMaps
STL-like proxy to access this kind of maps in maps.
mrpt::maps::COccupancyGridMap2D::TEntropyInfo entropy
Entropy of current, and last "map patchs".
bool enoughtInformation
If this is false, all other output fields must not be taken into account since there is not yet enoug...
void addObservations(CSensoryFrame &observations)
Add a set of observations to the sequence; the object is duplicated, so the original one can be free ...
Definition: CRawlog.cpp:38
A set of TMetricMapInitializer structures, passed to the constructor CMultiMetricMap::CMultiMetricMap...
CActionCollection::Ptr getAsAction(size_t index) const
Returns the i&#39;th element in the sequence, as being actions, where index=0 is the first object...
Definition: CRawlog.cpp:89
Represents a probabilistic 2D movement of the robot mobile base.
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85
#define MRPT_END
std::shared_ptr< CActionRobotMovement2D > Ptr
std::shared_ptr< CAction > Ptr
Definition: CAction.h:30
double I
The target variable for absolute "information", defining I(x) = 1 - H(x)
struct mrpt::detectors::CDetectorDoorCrossing::TOptions options
This namespace contains representation of robot actions and observations.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:56
ProxyFilterContainerByClass< mrpt::maps::COccupancyGridMap2D::Ptr, TListMaps > m_gridMaps
STL-like proxy to access this kind of maps in maps.
void process(mrpt::obs::CActionRobotMovement2D &in_poseChange, mrpt::obs::CSensoryFrame &in_sf, TDoorCrossingOutParams &out_estimation)
The main method, where a new action/observation pair is added to the list.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
CSensoryFrame::Ptr getAsObservations(size_t index) const
Returns the i&#39;th element in the sequence, as being an action, where index=0 is the first object...
Definition: CRawlog.cpp:149
void remove(size_t index)
Delete the action or observation stored in the given index.
Definition: CRawlog.cpp:285
virtual void copyFrom(const CPointsMap &obj) override
Virtual assignment operator, to be implemented in derived classes.
void push_back(const MAP_DEFINITION &o)
#define MRPT_START
float informationGain
The gain in information produced by the last observation, in "bits".
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::shared_ptr< CActionCollection > Ptr
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
void clear()
Reset the detector, i.e.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
const double & phi() const
Get the phi angle of the 2D pose (in radians)
Definition: CPose2D.h:91
#define ASSERT_(f)
void clear()
Clear the sequence of actions/observations.
Definition: CRawlog.cpp:32
float cumulativeTurning
The cumulative turning of the robot in radians for the movements in the "window". ...
mrpt::obs::CRawlog lastObs
The last observations and consecutive actions are stored here: Indexes (0,1) is the earlier (act...
void addAction(CAction &action)
Add an action to the sequence: a collection of just one element is created.
Definition: CRawlog.cpp:80
This class stores any customizable set of metric maps.
size_t size() const
Returns the number of actions / observations object in the sequence.
Definition: CRawlog.cpp:88
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::maps::COccupancyGridMap2D::TEntropyInfo lastEntropy



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