g2o
sensor_pose2d.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 G. Grisetti, R. Kuemmerle, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #include "sensor_pose2d.h"
28 
29 using namespace Eigen;
30 
31 namespace g2o{
32  SensorPose2D::SensorPose2D(const std::string& name_):
34  {
35  _stepsToIgnore = 10;
36  }
37 
39  if (! _robotPoseObject)
40  return false;
41  if (_posesToIgnore.find(to)!=_posesToIgnore.end())
42  return false;
43 
44  assert(to && to->vertex());
45  VertexType* v=to->vertex();
46  VertexType::EstimateType pose=v->estimate();
47  VertexType::EstimateType delta = _robotPoseObject->vertex()->estimate().inverse()*pose;
48  Vector2d translation=delta.translation();
49  double range2=translation.squaredNorm();
50  if (range2>_maxRange2)
51  return false;
52  if (range2<_minRange2)
53  return false;
54  translation.normalize();
55  double bearing=acos(translation.x());
56  if (fabs(bearing)>_fov)
57  return false;
58  if (fabs(delta.rotation().angle())>_maxAngularDifference)
59  return false;
60  return true;
61  }
62 
63 
67  n.fromVector(noise);
68  e->setMeasurement(e->measurement()*n);
70  }
71 
74  RobotType* r= dynamic_cast<RobotType*>(robot());
75  std::list<PoseObject*>::reverse_iterator it=r->trajectory().rbegin();
76  _posesToIgnore.clear();
77  int count = 0;
78  while (it!=r->trajectory().rend() && count < _stepsToIgnore){
79  if (!_robotPoseObject)
80  _robotPoseObject = *it;
81  _posesToIgnore.insert(*it);
82  it++;
83  count++;
84  }
85  for (std::set<BaseWorldObject*>::iterator it=world()->objects().begin();
86  it!=world()->objects().end(); it++){
87  WorldObjectType* o=dynamic_cast<WorldObjectType*>(*it);
88  if (o && isVisible(o)){
89  EdgeType* e=mkEdge(o);
90  if (e && graph()) {
92  addNoise(e);
93  graph()->addEdge(e);
94  }
95  }
96  }
97  }
98 
99 } // end namespace
virtual void setMeasurement(const SE2 &m)
Definition: edge_se2.h:56
virtual void sense()
2D edge between two Vertex2
Definition: edge_se2.h:40
bool isVisible(WorldObjectType *to)
GaussianSampler< typename EdgeType::ErrorVector, InformationType > _sampler
Definition: simulator.h:271
SampleType generateSample()
Definition: sampler.h:67
World * world()
Definition: simulator.cpp:69
EIGEN_STRONG_INLINE void setInformation(const InformationType &information)
Definition: base_edge.h:69
TrajectoryType & trajectory()
Definition: simulator.h:119
std::set< PoseObject * > _posesToIgnore
Definition: sensor_pose2d.h:49
virtual bool setMeasurementFromState()
Definition: edge_se2.h:77
OptimizableGraph * graph()
Definition: simulator.cpp:75
BaseRobot * robot()
Definition: simulator.h:129
std::set< BaseWorldObject * > & objects()
Definition: simulator.h:284
virtual bool addEdge(HyperGraph::Edge *e)
VertexType * vertex()
Definition: simulator.h:72
virtual void addNoise(EdgeType *e)
EdgeType * mkEdge(WorldObjectType *object)
Definition: simulator.h:263
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75