g2o
sensor_pointxy_offset.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_pointxy_offset.h"
28 #include "g2o/core/factory.h"
29 
30 namespace g2o {
31  using namespace std;
32  using namespace Eigen;
33 
34  // SensorPointXYOffset
36  _offsetParam = 0;
37  _information.setIdentity();
38  _information*=1000.;
40  }
41 
43  if (! _robotPoseObject)
44  return false;
45  assert(to && to->vertex());
46  VertexType* v=to->vertex();
47  VertexType::EstimateType pose=v->estimate();
48  VertexType::EstimateType delta = _sensorPose.inverse()*pose;
49  Vector2d translation=delta;
50  double range2=translation.squaredNorm();
51  if (range2>_maxRange2)
52  return false;
53  if (range2<_minRange2)
54  return false;
55  translation.normalize();
56  // the cameras have the z in front
57  double bearing=atan2(translation.y(), translation.x());
58  if (fabs(bearing)>_fov)
59  return false;
60  //cerr <<"a";
61  return true;
62  }
63 
65  if (!_offsetParam)
67  assert(world());
69  }
70 
73  e->setMeasurement(e->measurement()+n);
75  }
76 
78  if (! _offsetParam){
79  return;
80  }
82  RobotType* r= dynamic_cast<RobotType*>(robot());
83  std::list<PoseObject*>::reverse_iterator it=r->trajectory().rbegin();
84  int count = 0;
85  while (it!=r->trajectory().rend() && count < 1){
86  if (!_robotPoseObject)
87  _robotPoseObject = *it;
88  it++;
89  count++;
90  }
91  if (!_robotPoseObject)
92  return;
93  _sensorPose = _robotPoseObject->vertex()->estimate()*_offsetParam->offset();
94  for (std::set<BaseWorldObject*>::iterator it=world()->objects().begin();
95  it!=world()->objects().end(); it++){
96  WorldObjectType* o=dynamic_cast<WorldObjectType*>(*it);
97  if (o && isVisible(o)){
98  EdgeType* e=mkEdge(o);
100  if (e && graph()) {
101  graph()->addEdge(e);
103  addNoise(e);
104  }
105  }
106  }
107  }
108 
109 }
bool addParameter(Parameter *p)
Definition: simulator.cpp:102
bool isVisible(WorldObjectType *to)
GaussianSampler< typename EdgeType::ErrorVector, InformationType > _sampler
Definition: simulator.h:271
SampleType generateSample()
Definition: sampler.h:67
virtual void addNoise(EdgeType *e)
ParameterSE2Offset * _offsetParam
bool setParameterId(int argNum, int paramId)
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
const SE2 & offset() const
int id() const
Definition: parameter.h:45
OptimizableGraph * graph()
Definition: simulator.cpp:75
BaseRobot * robot()
Definition: simulator.h:129
virtual void setMeasurement(const Vector2D &m)
std::set< BaseWorldObject * > & objects()
Definition: simulator.h:284
virtual bool addEdge(HyperGraph::Edge *e)
VertexType * vertex()
Definition: simulator.h:72
void setInformation(const InformationType &information_)
Definition: simulator.h:221
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
SensorPointXYOffset(const std::string &name_)